Beispiel #1
0
 def __init__(self, ports):
     set_up_logging('taserver_firewall.log')
     self.logger = logging.getLogger('firewall')
     self.ports = ports
     self.utils = FirewallUtils(self.logger)
     self.blacklist = Blacklist(self.utils, self.logger, ports)
     self.whitelist = Whitelist(self.utils, self.logger, ports)
     self.name = 'TAserverfirewall-general'
     if self.ports.portOffset:
         self.name += f'_offset{self.ports.portOffset}'
Beispiel #2
0
def main():
    set_up_logging('authbot.log')
    logger = logging.getLogger(__name__)
    config = configparser.ConfigParser()
    with open(INI_PATH) as f:
        config.read_file(f)

    restart = True
    restart_delay = 10
    tasks = []
    try:
        while restart:
            incoming_queue = gevent.queue.Queue()

            tasks = [
                gevent_spawn("authbot's handle_authbot", handle_authbot,
                             config['authbot'], incoming_queue),
                gevent_spawn("authbot's handle_hirez_login_server",
                             handle_hirez_login_server, config['authbot'],
                             incoming_queue),
            ]

            # Wait for any of the tasks to terminate
            finished_greenlets = gevent.joinall(tasks, count=1)

            logger.warning('The following greenlets terminated: %s' %
                           ','.join([g.name for g in finished_greenlets]))

            fatal_errors = [
                '  %s' % g.exception for g in finished_greenlets
                if isinstance(g.exception, FatalError)
            ]
            if fatal_errors:
                logger.critical(
                    '\n' + '\n-------------------------------------------\n' +
                    'The following fatal errors occurred:\n' +
                    '\n'.join(fatal_errors) +
                    '\n-------------------------------------------\n')
                restart = False

            logger.info('Killing all tasks...')
            gevent.killall(tasks)
            logger.info('Waiting %s seconds before %s...' %
                        (restart_delay,
                         ('restarting' if restart else 'exiting')))
            gevent.sleep(restart_delay)

    except KeyboardInterrupt:
        logger.info('Keyboard interrupt received. Exiting...')
        gevent.killall(tasks)
    except Exception:
        logger.exception('Main authbot thread exited with an exception')
Beispiel #3
0
def main():
    set_up_logging('login_server.log')
    logger = logging.getLogger(__name__)
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--dump', action='store_true',
                        help='Dump all traffic to %s in a format suitable '
                             'for parsing with the parse.py utility.' %
                             dumpfilename)
    args = parser.parse_args()

    # Perform data migrations on startup
    try:
        run_migrations('data')
    except ValueError as e:
        # If a migration failed, it will raise a ValueError
        logger.fatal('Failed to run data migrations with format error: %s' % str(e))
        sys.exit(2)
    except OSError as e:
        # If a migration failed, it will raise a ValueError
        logger.fatal('Failed to run data migrations with OS error: %s' % str(e))
        sys.exit(2)
    
    client_queues = {}
    server_queue = gevent.queue.Queue()
    server_stats_queue = gevent.queue.Queue()
    dump_queue = gevent.queue.Queue() if args.dump else None

    accounts = Accounts('data/accountdatabase.json')
    config = configparser.ConfigParser()
    with open(INI_PATH) as f:
        config.read_file(f)
    with open(SHARED_INI_PATH) as f:
        config.read_file(f)

    ports = Ports(int(config['shared']['port_offset']))

    tasks = [
        gevent_spawn("login server's handle_server",
                     handle_server,
                     server_queue,
                     client_queues,
                     server_stats_queue,
                     ports,
                     accounts),
        gevent_spawn("login server's handle_authcodes",
                     handle_authcodes,
                     server_queue),
        gevent_spawn("login server's handle_webhook",
                     handle_webhook,
                     server_stats_queue,
                     config['loginserver']),
        gevent_spawn("login server's handle_http",
                     handle_http,
                     server_queue,
                     ports),
        gevent_spawn("login server's handle_game_client",
                     handle_game_client,
                     server_queue, dump_queue),
        gevent_spawn("login server's handle_game_server_launcher",
                     handle_game_server_launcher,
                     server_queue,
                     ports)
    ]
    # Give the greenlets enough time to start up, otherwise killall can block
    gevent.sleep(1)

    if dump_queue:
        tasks.append(gevent_spawn("login server's handle_dump", handle_dump, dump_queue))

    try:
        # Wait for any of the tasks to terminate
        finished_greenlets = gevent.joinall(tasks, count=1)

        logger.error('The following greenlets terminated: %s' % ','.join([g.name for g in finished_greenlets]))

        exceptions = ['  %s' % g.exception for g in finished_greenlets
                                if isinstance(g.exception, Exception)]
        if exceptions:
            logger.critical('\n' +
                            '\n-------------------------------------------\n' +
                            'The following exceptions occurred:\n' +
                            '\n'.join(exceptions) +
                            '\n-------------------------------------------\n'
                            )

        if dump_queue:
            logger.info('Giving the dump greenlet some time to finish writing to disk...')
            gevent.sleep(2)

        logger.info('Killing everything and waiting 10 seconds before exiting...')
        gevent.killall(tasks)
        gevent.sleep(5)

    except KeyboardInterrupt:
        logger.info('Keyboard interrupt received. Exiting...')
        gevent.killall(tasks)
        accounts.save()
    except Exception:
        logger.exception('Main login server thread exited with an exception')
Beispiel #4
0
def main():
    set_up_logging('game_server_launcher.log')
    logger = logging.getLogger(__name__)
    config = configparser.ConfigParser()
    with open(LAUNCHER_INI_PATH) as f:
        config.read_file(f)
    with open(SHARED_INI_PATH) as f:
        config.read_file(f)

    ports = Ports(int(config['shared']['port_offset']))

    restart = True
    restart_delay = 10
    tasks = []
    try:
        while restart:
            incoming_queue = gevent.queue.Queue()
            server_handler_queue = gevent.queue.Queue()

            tasks = [
                gevent_spawn("game server launcher's handle_ping", handle_ping,
                             ports),
                gevent_spawn("game server launcher's handle_game_server",
                             handle_game_server, config['gameserver'], ports,
                             server_handler_queue, incoming_queue),
                gevent_spawn("game server launcher's handle_login_server",
                             handle_login_server, config['loginserver'],
                             incoming_queue),
                gevent_spawn("game server launcher's handle_game_controller",
                             handle_game_controller, ports, incoming_queue),
                gevent_spawn("game server launcher's handle_launcher",
                             handle_launcher, config['gameserver'], ports,
                             incoming_queue, server_handler_queue)
            ]
            # Give the greenlets enough time to start up, otherwise killall can block
            gevent.sleep(1)

            # Wait for any of the tasks to terminate
            finished_greenlets = gevent.joinall(tasks, count=1)

            logger.warning('The following greenlets terminated: %s' %
                           ','.join([g.name for g in finished_greenlets]))

            fatal_errors = [
                '  %s' % g.exception for g in finished_greenlets
                if isinstance(g.exception, FatalError)
            ]
            if fatal_errors:
                logger.critical(
                    '\n' + '\n-------------------------------------------\n' +
                    'The following fatal errors occurred:\n' +
                    '\n'.join(fatal_errors) +
                    '\n-------------------------------------------\n')
                restart = False

            logger.info('Killing all tasks...')
            gevent.killall(tasks)
            logger.info('Waiting %s seconds before %s...' %
                        (restart_delay,
                         ('restarting' if restart else 'exiting')))
            gevent.sleep(restart_delay)

    except KeyboardInterrupt:
        logger.info('Keyboard interrupt received. Exiting...')
        gevent.killall(tasks)
    except Exception:
        logger.exception(
            'Main game server launcher thread exited with an exception')
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--data-root',
        action='store',
        default='data',
        help='Location of the data dir containing all config files and logs.')
    args = parser.parse_args()
    data_root = args.data_root
    set_up_logging(data_root, 'authbot.log')
    logger = logging.getLogger(__name__)
    config = configparser.ConfigParser()
    with open(os.path.join(data_root, INI_FILE)) as f:
        config.read_file(f)

    # We're only gonna use fixed ports, so no need to read port offset from the config
    ports = Ports(0)

    restart = True
    tasks = []
    try:
        while restart:
            incoming_queue = gevent.queue.Queue()

            tasks = [
                gevent_spawn("authbot's handle_authbot", handle_authbot,
                             config['authbot'], incoming_queue),
                gevent_spawn("authbot's handle_hirez_login_server",
                             handle_hirez_login_server, config['authbot'],
                             ports, incoming_queue),
                gevent_spawn("authbot's handle_community_login_server",
                             handle_community_login_server, ports,
                             incoming_queue),
            ]

            # Wait for any of the tasks to terminate
            finished_greenlets = gevent.joinall(tasks, count=1)

            logger.warning('The following greenlets terminated: %s' %
                           ','.join([g.name for g in finished_greenlets]))

            restart_delay = 10

            fatal_errors = [
                '  %s' % g.exception for g in finished_greenlets
                if isinstance(g.exception, FatalError)
            ]
            if fatal_errors:
                logger.critical(
                    '\n' + '\n-------------------------------------------\n' +
                    'The following fatal errors occurred:\n' +
                    '\n'.join(fatal_errors) +
                    '\n-------------------------------------------\n')
                restart = False

            major_errors = [
                '  %s' % g.exception for g in finished_greenlets
                if isinstance(g.exception, MajorError)
            ]
            if major_errors:
                logger.critical(
                    '\n' + '\n-------------------------------------------\n' +
                    'The following major errors occurred:\n' +
                    '\n'.join(major_errors) +
                    '\n-------------------------------------------\n')
                restart_delay = 15 * 60

            logger.info('Killing all tasks...')
            gevent.killall(tasks)
            logger.info('Waiting %s seconds before %s...' %
                        (restart_delay,
                         ('restarting' if restart else 'exiting')))
            gevent.sleep(restart_delay)

    except KeyboardInterrupt:
        logger.info('Keyboard interrupt received. Exiting...')
        gevent.killall(tasks)
    except Exception:
        logger.exception('Main authbot thread exited with an exception')
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--data-root',
        action='store',
        default='data',
        help='Location of the data dir containing all config files and logs.')
    parser.add_argument('--port-offset',
                        action='store',
                        default=None,
                        help='Override port offset in the config')
    args = parser.parse_args()
    data_root = args.data_root
    set_up_logging(data_root, 'game_server_launcher.log')
    logger = logging.getLogger(__name__)
    config = configparser.ConfigParser()
    with open(os.path.join(data_root, 'gameserverlauncher.ini')) as f:
        config.read_file(f)
    with open(get_shared_ini_path(data_root)) as f:
        config.read_file(f)

    if args.port_offset is not None:
        print(f"Using port offset flag: {int(args.port_offset)}")
        ports = Ports(int(args.port_offset))
    else:
        ports = Ports(int(config['shared']['port_offset']))

    restart = True
    restart_delay = 10
    tasks = []
    try:
        while restart:
            incoming_queue = gevent.queue.Queue()
            server_handler_queue = gevent.queue.Queue()

            tasks = [
                gevent_spawn("game server launcher's handle_ping", handle_ping,
                             ports),
                gevent_spawn("game server launcher's handle_game_server",
                             handle_game_server, config['gameserver'], ports,
                             server_handler_queue, incoming_queue, data_root),
                gevent_spawn("game server launcher's handle_login_server",
                             handle_login_server, config['loginserver'],
                             incoming_queue),
                gevent_spawn("game server launcher's handle_game_controller",
                             handle_game_controller, ports, incoming_queue),
                gevent_spawn("game server launcher's handle_launcher",
                             handle_launcher, config['gameserver'], ports,
                             incoming_queue, server_handler_queue, data_root)
            ]
            # Give the greenlets enough time to start up, otherwise killall can block
            gevent.sleep(1)

            # Wait for any of the tasks to terminate
            finished_greenlets = gevent.joinall(tasks, count=1)

            logger.warning('The following greenlets terminated: %s' %
                           ','.join([g.name for g in finished_greenlets]))

            fatal_errors = [
                '  %s' % g.exception for g in finished_greenlets
                if isinstance(g.exception, FatalError)
            ]
            if fatal_errors:
                logger.critical(
                    '\n' + '\n-------------------------------------------\n' +
                    'The following fatal errors occurred:\n' +
                    '\n'.join(fatal_errors) +
                    '\n-------------------------------------------\n')
                restart = False

            logger.info('Killing all tasks...')
            gevent.killall(tasks)
            logger.info('Waiting %s seconds before %s...' %
                        (restart_delay,
                         ('restarting' if restart else 'exiting')))
            gevent.sleep(restart_delay)

    except KeyboardInterrupt:
        logger.info('Keyboard interrupt received. Exiting...')
        gevent.killall(tasks)
    except Exception:
        logger.exception(
            'Main game server launcher thread exited with an exception')
Beispiel #7
0
 def __init__(self):
     set_up_logging('taserver_firewall.log')
     self.logger = logging.getLogger('firewall')
     self.utils = FirewallUtils(self.logger)
     self.blacklist = Blacklist(self.utils, self.logger)
     self.whitelist = Whitelist(self.utils, self.logger)