Exemple #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)
 def bots(self):
     game_history = GameHistory.Instance()
     history = {}
     for team in Team.all():
         history[team.name] = game_history.get_bot_history_by_name(
             team.name, -30
         )
     self.render('scoreboard/history/bots.html', history=history)
Exemple #3
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)
 def initialize(self):
     ''' Setup sessions '''
     self.manager = EventManager.Instance()
     self.game_history = GameHistory.Instance()