예제 #1
0
def run() -> None:
    """
    runs the server
    """

    # load and apply regular scripts
    script_names = scripts_option.get()
    script_dir = os.path.join(config.config_dir, 'scripts/')
    if script_dir not in sys.path:
        sys.path.append(script_dir)
    script_objects = extensions.load_scripts_regular_extension(
        script_names, script_dir)
    (protocol_class,
     connection_class) = extensions.apply_scripts(script_objects, config,
                                                  FeatureProtocol,
                                                  FeatureConnection)

    # load and apply the game_mode script
    game_mode_name = game_mode.get()
    game_mode_dir = os.path.join(config.config_dir, 'game_modes/')
    game_mode_object = extensions.load_script_game_mode(
        game_mode_name, game_mode_dir)
    (protocol_class,
     connection_class) = extensions.apply_scripts(game_mode_object, config,
                                                  protocol_class,
                                                  connection_class)

    protocol_class.connection_class = connection_class

    interface = network_interface.get().encode('utf-8')

    # instantiate the protocol class once. It will set timers and hooks to keep
    # itself running once we start the reactor
    protocol_class(interface, config.get_dict())

    log.debug('Checking for unregistered config items...')
    unused = config.check_unused()
    if unused:
        log.warn('The following config items are not used:')
        pprint(unused)

    log.info('Started server...')

    profile = logging_profile_option.get()
    if profile:
        import cProfile
        cProfile.runctx('reactor.run()', None, globals())
    else:
        reactor.run()
예제 #2
0
def run() -> None:
    """
    runs the server
    """

    # apply scripts

    protocol_class = FeatureProtocol
    connection_class = FeatureConnection

    script_objects = []
    script_names = scripts_option.get()
    script_dir = os.path.join(config.config_dir, 'scripts/')

    for script in script_names[:]:
        try:
            # this finds and loads scripts directly from the script dir
            # no need for messing with sys.path
            f, filename, desc = imp.find_module(script, [script_dir])
            module = imp.load_module(
                'piqueserver_script_namespace_' + script, f, filename, desc)
            script_objects.append(module)
        except ImportError as e:
            # warning: this also catches import errors from inside the script
            # module it tried to load
            try:
                module = importlib.import_module(script)
                script_objects.append(module)
            except ImportError as e:
                log.error("(script '{}' not found: {!r})".format(script, e))
                script_names.remove(script)

    for script in script_objects:
        protocol_class, connection_class = script.apply_script(
            protocol_class, connection_class, config.get_dict())

    # apply the game_mode script
    if game_mode.get() not in ('ctf', 'tc'):
        # must be a script with this game mode
        module = None
        try:
            game_mode_dir = os.path.join(config.config_dir, 'game_modes/')
            f, filename, desc = imp.find_module(
                game_mode.get(), [game_mode_dir])
            module = imp.load_module(
                'piqueserver_gamemode_namespace_' + game_mode.get(), f, filename, desc)
        except ImportError as e:
            try:
                module = importlib.import_module(game_mode.get())
            except ImportError as e:
                log.error("(game_mode '%s' not found: %r)" %
                          (game_mode.get(), e))

        if module:
            protocol_class, connection_class = module.apply_script(
                protocol_class, connection_class, config.get_dict())

    protocol_class.connection_class = connection_class

    interface = network_interface.get().encode('utf-8')

    # instantiate the protocol class once. It will set timers and hooks to keep
    # itself running once we start the reactor
    protocol_class(interface, config.get_dict())

    log.debug('Checking for unregistered config items...')
    unused = config.check_unused()
    if unused:
        log.warn('The following config items are not used:')
        pprint(unused)

    log.info('Started server...')

    profile = logging_profile_option.get()
    if profile:
        import cProfile
        cProfile.runctx('reactor.run()', None, globals())
    else:
        reactor.run()