コード例 #1
0
ファイル: server.py プロジェクト: Night-Stalkers/piqueserver
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 test_apply_scripts(self):
        script_objects = self.get_test_scripts()
        protocol_class = FeatureProtocol
        connection_class = FeatureConnection

        # TODO: figure out what this was supposed to do
        # self.assertNotEqual(protocol_class.game_mode, "testing")
        # self.assertTrue(connection_class.killing)

        (protocol_class, connection_class) = extensions.apply_scripts(
            script_objects, config, protocol_class, connection_class)
コード例 #3
0
    def test_apply_scripts(self):
        script_objects = self.get_test_scripts()
        protocol_class = FeatureProtocol
        connection_class = FeatureConnection

        self.assertNotEqual(protocol_class.game_mode, "testing")
        self.assertTrue(connection_class.killing)

        (protocol_class, connection_class) = extensions.apply_scripts(
            script_objects, config, protocol_class, connection_class)

        self.assertEqual(protocol_class.game_mode, "testing")
        self.assertFalse(connection_class.killing)