Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(description='Run a master server')
    parser.add_argument('filename', type=str)
    parser.add_argument('--port', type=int, default=DEFAULT_PORT)
    parser.add_argument('--blacklist', type=str,
                        default=BLACKLIST_FILE)
    args = parser.parse_args()

    port = args.port
    filename = args.filename
    blacklist_file = args.blacklist

    if sys.platform == 'win32':
        from cuwo.win32 import WindowsEventLoop
        loop = WindowsEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()

    loop.add_signal_handler(signal.SIGINT, loop.close)

    protocol = MasterServer(loop, filename, blacklist_file)

    print('Running cuwo (master) on port %s' % port)

    addr = ('0.0.0.0', port)
    asyncio.Task(loop.create_datagram_endpoint(lambda: protocol,
                                               local_addr=addr))
    loop.run_forever()
Beispiel #2
0
def main():
    # make sure we enable crash logging as early as possible
    faulthandler.enable()

    # for py2exe
    if hasattr(sys, 'frozen'):
        path = os.path.dirname(sys.executable)
        root = os.path.abspath(os.path.join(path, '..'))
        sys.path.append(root)

    config = ConfigObject('./config')

    if sys.platform == 'win32':
        from cuwo.win32 import WindowsEventLoop
        loop = WindowsEventLoop()
        loop.set_clock_resolution(1 * 1e-3)
        asyncio.set_event_loop(loop)
    else:
        try:
            import uvloop
            asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
            print('(using uvloop)')
        except ImportError:
            pass
        loop = asyncio.get_event_loop()

    if config.base.use_tgen:
        from cuwo.download import download_dependencies
        download_dependencies()

    server = CubeWorldServer(loop, config)

    loop.add_signal_handler(signal.SIGINT, server.stop)

    print('cuwo running on port %s' % config.base.port)

    if config.base.profile_file is None:
        loop.run_forever()
    else:
        import cProfile
        cProfile.run('loop.run_forever()', filename=config.base.profile_file)

    sys.exit(server.exit_code)
Beispiel #3
0
def main():
    # make sure we enable crash logging as early as possible
    faulthandler.enable()

    # for py2exe
    if hasattr(sys, 'frozen'):
        path = os.path.dirname(sys.executable)
        root = os.path.abspath(os.path.join(path, '..'))
        sys.path.append(root)

    config = ConfigObject('./config')

    if sys.platform == 'win32':
        from cuwo.win32 import WindowsEventLoop
        loop = WindowsEventLoop()
        loop.set_clock_resolution(1 * 1e-3)
        asyncio.set_event_loop(loop)
    else:
        try:
            import uvloop
            asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
            print('(using uvloop)')
        except ImportError:
            pass
        loop = asyncio.get_event_loop()

    if config.base.use_tgen:
        from cuwo.download import download_dependencies
        download_dependencies()

    server = CubeWorldServer(loop, config)

    loop.add_signal_handler(signal.SIGINT, server.stop)

    print('cuwo running on port %s' % config.base.port)

    if config.base.profile_file is None:
        loop.run_forever()
    else:
        import cProfile
        cProfile.run('loop.run_forever()', filename=config.base.profile_file)

    sys.exit(server.exit_code)
Beispiel #4
0
def main():
    if sys.platform == 'win32':
        from cuwo.win32 import WindowsEventLoop
        loop = WindowsEventLoop()
        asyncio.set_event_loop(loop)

        # asyncio has poor support for signals on win32.
        # use a busy loop to properly receive SIGINT
        def busy_loop():
            loop.call_later(0.1, busy_loop)
        busy_loop()
    else:
        loop = asyncio.get_event_loop()

    loop.add_signal_handler(signal.SIGINT, loop.stop)
    co = loop.create_server(lambda: FrontendProtocol(loop), '127.0.0.1', 12345)
    loop.create_task(co)
    print('cuwo (mitm) running on port 12345')

    loop.run_forever()