Example #1
0
    def start():
        WorldLoader.load_data()

        server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
        # Use SO_REUSEADDR if SO_REUSEPORT doesn't exist.
        except AttributeError:
            server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_socket.bind((config.Server.Connection.WorldServer.host, config.Server.Connection.WorldServer.port))
        server_socket.listen()

        WorldServerSessionHandler.schedule_background_tasks()

        real_binding = server_socket.getsockname()
        Logger.success(f'World server started, listening on {real_binding[0]}:{real_binding[1]}\a')
        while WORLD_ON:  # sck.accept() is a blocking call, we can't exit this loop gracefully.
            # noinspection PyBroadException
            try:
                (client_socket, client_address) = server_socket.accept()
                server_handler = WorldServerSessionHandler(client_socket, client_address)
                world_session_thread = threading.Thread(target=server_handler.handle)
                world_session_thread.daemon = True
                world_session_thread.start()
            except:
                break
Example #2
0
    def start():
        WorldLoader.load_data()
        Logger.success('World server started.')

        WorldServerSessionHandler.schedule_updates()

        ThreadedWorldServer.allow_reuse_address = True
        ThreadedWorldServer.timeout = 10
        with ThreadedWorldServer((config.Server.Connection.RealmServer.host,
                                  config.Server.Connection.WorldServer.port),
                                 WorldServerSessionHandler) as world_instance:
            try:
                world_session_thread = threading.Thread(
                    target=world_instance.serve_forever())
                world_session_thread.daemon = True
                world_session_thread.start()
            except KeyboardInterrupt:
                Logger.info("World server turned off.")