Beispiel #1
0
def start_server():
    ''' Main entry point for the application '''
    sockets = netutil.bind_sockets(config.listen_port)
    server = HTTPServer(app)
    server.add_sockets(sockets)
    io_loop = IOLoop.instance()
    scoring = PeriodicCallback(
        scoring_round, int(5 * 60 * 1000), io_loop=io_loop
    )
    scoring.start()
    try:
        sys.stdout.write("\r" + INFO + "The game has begun, good hunting!\n")
        if config.debug:
            sys.stdout.write(WARN + "WARNING: Debug mode is enabled.\n")
        sys.stdout.flush()
        game_history = GameHistory.Instance()
        history_callback = PeriodicCallback(
            game_history.take_snapshot, int(60 * 1000), io_loop=io_loop
        )
        history_callback.start()
        io_loop.start()
    except KeyboardInterrupt:
        print('\r' + WARN + 'Shutdown Everything!')
    except:
      logging.exception("Main i/o loop threw exception")
    finally:
        io_loop.stop()
        if config.debug and \
                raw_input(PROMPT + "Flush Memcache? [Y/n]: ").lower() == 'y':
            print(INFO + 'Flushing cache ...'),
            FileCache.flush()
            print('OK')
        _exit(0)
Beispiel #2
0
def start_server():
    ''' Main entry point for the application '''
    sockets = netutil.bind_sockets(config.listen_port)
    server = HTTPServer(app)
    server.add_sockets(sockets)
    io_loop = IOLoop.instance()
    scoring = PeriodicCallback(scoring_round,
                               int(5 * 60 * 1000),
                               io_loop=io_loop)
    scoring.start()
    try:
        sys.stdout.write("\r" + INFO + "The game has begun, good hunting!\n")
        if config.debug:
            sys.stdout.write(WARN + "WARNING: Debug mode is enabled.\n")
        sys.stdout.flush()
        game_history = GameHistory.Instance()
        history_callback = PeriodicCallback(game_history.take_snapshot,
                                            int(60 * 1000),
                                            io_loop=io_loop)
        history_callback.start()
        io_loop.start()
    except KeyboardInterrupt:
        print('\r' + WARN + 'Shutdown Everything!')
    except:
        logging.exception("Main i/o loop threw exception")
    finally:
        io_loop.stop()
        if config.debug and \
                raw_input(PROMPT + "Flush Memcache? [Y/n]: ").lower() == 'y':
            print(INFO + 'Flushing cache ...'),
            FileCache.flush()
            print('OK')
        _exit(0)
Beispiel #3
0
def start_game():
    try:
        print("\r" + INFO + "Starting web server; binding to port %d" % config.listen_port)
        application.listen(config.listen_port)
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        FileCache.flush()
        print("\r" + WARN + "Shutting everything!")
Beispiel #4
0
def start_server():
    ''' Main entry point for the application '''
    
    if config.debug:
        sys.stdout.write(WARN+"WARNING: Debug mode is enabled in "+config.filename)
        sys.stdout.flush()
        logging.warn("Debug mode is enabled; some security measures will be ignored")
    
    # Setup server object
    if config.use_ssl:
        server = HTTPServer(app, 
            ssl_options={
                "certfile": config.certfile,
                "keyfile": config.keyfile,
            }, 
            xheaders=config.x_headers
        )
    else:
        server = HTTPServer(app, xheaders=config.x_headers)

    # Bind to a socket
    sockets = netutil.bind_sockets(config.listen_port)
    server.add_sockets(sockets)
    
    # Start the i/o loop, and callbacks
    try:
        io_loop = IOLoop.instance()
        game_history = GameHistory.Instance()
        history_callback = PeriodicCallback(
            game_history.take_snapshot, 
            config.history_snapshot_interval, 
            io_loop=io_loop
        )
        if config.use_bots:
            scoring_callback = PeriodicCallback(
                score_bots, 
                config.bot_reward_interval, 
                io_loop=io_loop
            )
            bot_ping_callback = PeriodicCallback(
                ping_bots, 30000, io_loop=io_loop
            )
            bot_ping_callback.start()
            scoring_callback.start()
        history_callback.start()
        io_loop.start()
    except KeyboardInterrupt:
        sys.stdout.write('\r'+WARN+'Shutdown Everything!\n')
    except:
        logging.exception("Main i/o loop threw exception")
    finally:
        io_loop.stop()
        if config.debug and raw_input(PROMPT+"Flush Memcache? [Y/n]: ").lower() == 'y':
            sys.stdout.write(INFO+'Flushing cache ... '),
            FileCache.flush()
            sys.stdout.write('okay\n')
        _exit(0)
Beispiel #5
0
def start_server():
    ''' Main entry point for the application '''
    server = HTTPServer(app)
    sockets = netutil.bind_sockets(config.listen_port)
    server.add_sockets(sockets)
    io_loop = IOLoop.instance()
    try:
        if config.debug:
            # Print a nice verbose warning
            sys.stdout.write(WARN + "WARNING: Debug mode is enabled in " +
                             config.filename)
            sys.stdout.write(
                bold +
                "\n\n\t>>> Debug Mode Disables Some Security Measures <<<" +
                W + "\n\n")
        sys.stdout.flush()
        game_history = GameHistory.Instance()
        history_callback = PeriodicCallback(game_history.take_snapshot,
                                            config.history_snapshot_interval,
                                            io_loop=io_loop)
        scoring_callback = PeriodicCallback(score_bots,
                                            config.bot_reward_interval,
                                            io_loop=io_loop)
        bot_ping_callback = PeriodicCallback(ping_bots, 30000, io_loop=io_loop)
        # Start ALL THE THINGS!
        bot_ping_callback.start()
        history_callback.start()
        scoring_callback.start()
        io_loop.start()
    except KeyboardInterrupt:
        sys.stdout.write('\r' + WARN + 'Shutdown Everything!\n')
    except:
        logging.exception("Main i/o loop threw exception")
    finally:
        io_loop.stop()
        if config.debug and raw_input(
                PROMPT + "Flush Memcache? [Y/n]: ").lower() == 'y':
            sys.stdout.write(INFO + 'Flushing cache ... '),
            FileCache.flush()
            sys.stdout.write('okay\n')
        _exit(0)