예제 #1
0
    def start(self):
        loop = asyncio.get_event_loop()

        bound_ip = '0.0.0.0'
        if self.config['local']:
            bound_ip = '127.0.0.1'

        ao_server_crt = loop.create_server(lambda: AOProtocol(self), bound_ip, self.config['port'])
        ao_server = loop.run_until_complete(ao_server_crt)

        if self.config['use_websockets']:
            ao_server_ws = websockets.serve(new_websocket_client(self), bound_ip, self.config['websocket_port'])
            asyncio.ensure_future(ao_server_ws)

        if self.config['use_district']:
            self.district_client = DistrictClient(self)
            asyncio.ensure_future(self.district_client.connect(), loop=loop)

        if self.config['use_masterserver']:
            self.ms_client = MasterServerClient(self)
            asyncio.ensure_future(self.ms_client.connect(), loop=loop)

        logger.log_debug('Server started.')
        print('Server started and is listening on port {}'.format(self.config['port']))

        try:
            loop.run_forever()
        except KeyboardInterrupt:
            pass

        logger.log_debug('Server shutting down.')

        ao_server.close()
        loop.run_until_complete(ao_server.wait_closed())
        loop.close()
예제 #2
0
    def start(self):
        """Start the server."""
        loop = asyncio.get_event_loop_policy().get_event_loop()

        bound_ip = "0.0.0.0"
        if self.config["local"]:
            bound_ip = "127.0.0.1"

        ao_server_crt = loop.create_server(lambda: AOProtocol(self), bound_ip,
                                           self.config["port"])
        ao_server = loop.run_until_complete(ao_server_crt)

        if self.config["use_websockets"]:
            ao_server_ws = websockets.serve(new_websocket_client(self),
                                            bound_ip,
                                            self.config["websocket_port"])
            asyncio.ensure_future(ao_server_ws)

        if self.config["use_masterserver"]:
            self.ms_client = MasterServerClient(self)
            asyncio.ensure_future(self.ms_client.connect(), loop=loop)

        if self.config["zalgo_tolerance"]:
            self.zalgo_tolerance = self.config["zalgo_tolerance"]

        if "bridgebot" in self.config and self.config["bridgebot"]["enabled"]:
            try:
                self.bridgebot = Bridgebot(
                    self,
                    self.config["bridgebot"]["channel"],
                    self.config["bridgebot"]["hub_id"],
                    self.config["bridgebot"]["area_id"],
                )
                asyncio.ensure_future(self.bridgebot.init(
                    self.config["bridgebot"]["token"]),
                                      loop=loop)
            except Exception as ex:
                # Don't end the whole server if bridgebot destroys itself
                print(ex)
        asyncio.ensure_future(self.schedule_unbans())

        database.log_misc("start")
        print("Server started and is listening on port {}".format(
            self.config["port"]))

        try:
            loop.run_forever()
        except KeyboardInterrupt:
            print("KEYBOARD INTERRUPT")
            loop.stop()

        database.log_misc("stop")

        ao_server.close()
        loop.run_until_complete(ao_server.wait_closed())
        loop.close()
예제 #3
0
    def start(self):
        """Start the server."""
        loop = asyncio.get_event_loop()

        bound_ip = '0.0.0.0'
        if self.config['local']:
            bound_ip = '127.0.0.1'

        ao_server_crt = loop.create_server(lambda: AOProtocol(self), bound_ip,
                                           self.config['port'])
        ao_server = loop.run_until_complete(ao_server_crt)

        if self.config['use_websockets']:
            ao_server_ws = websockets.serve(new_websocket_client(self),
                                            bound_ip,
                                            self.config['websocket_port'])
            asyncio.ensure_future(ao_server_ws)

        if self.config['use_masterserver']:
            self.ms_client = MasterServerClient(self)
            asyncio.ensure_future(self.ms_client.connect(), loop=loop)

        if self.config['zalgo_tolerance']:
            self.zalgo_tolerance = self.config['zalgo_tolerance']

        if 'bridgebot' in self.config and self.config['bridgebot']['enabled']:
            self.bridgebot = Bridgebot(self,
                                       self.config['bridgebot']['channel'],
                                       self.config['bridgebot']['hub_id'],
                                       self.config['bridgebot']['area_id'])
            asyncio.ensure_future(self.bridgebot.init(
                self.config['bridgebot']['token']),
                                  loop=loop)

        asyncio.ensure_future(self.schedule_unbans())

        database.log_misc('start')
        print('Server started and is listening on port {}'.format(
            self.config['port']))

        try:
            loop.run_forever()
        except KeyboardInterrupt:
            pass

        database.log_misc('stop')

        ao_server.close()
        loop.run_until_complete(ao_server.wait_closed())
        loop.close()