コード例 #1
0
    def __init__(self, path, preload=False, download=False):
        """Add the file to downloadables if download is True.

        :param str path:
            Path to file to use.
        :param bool preload:
            If ``True`` the file will be pre-loaded.
        :param bool download:
            If ``True`` the file will be added to the ``downloadables`` string
            table.
        """
        # Save the path that should be precached
        self._path = path

        # Save whether the the file should be preloaded
        self._preload = preload

        # Is the map loaded?
        if global_vars.map_name:

            # Precache the instance
            self._precache()

        # Register the server_spawn event to precache every map change
        event_manager.register_for_event('server_spawn', self._server_spawn)

        # Should the path be added to the downloadables?
        if download:

            # Add the path to the downloadables
            self._downloads = Downloadables()
            self._downloads.add(self._path)
コード例 #2
0
ファイル: pypug.py プロジェクト: TheRealLime/pypug
    def __init__(self, listeners, event_names):
        self._handlers = {}

        for name in event_names:
            eh = generate_handler(name, listeners)
            self._handlers[name] = eh
            event_manager.register_for_event(name, eh)
コード例 #3
0
ファイル: precache.py プロジェクト: Doldol/Source.Python
    def __init__(self, path, preload=False, download=False):
        """Add the file to downloadables if download is True."""
        # Save the path that should be precached
        self._path = path

        # Save whether the the file should be preloaded
        self._preload = preload

        # Get the calling module
        caller = getmodule(stack()[1][0])

        # Set the _calling_module attribute for the instance
        self._calling_module = caller.__name__

        # Is the map loaded?
        if global_vars.map_name:
            # Precache the instance
            self._precache()

        # Register the server_spawn event to precache every map change
        event_manager.register_for_event('server_spawn', self._server_spawn)

        # Should the path be added to the downloadables?
        if download:

            # Add the path to the downloadables
            self._downloads = Downloadables()
            self._downloads.add(self._path)
コード例 #4
0
    def __init__(self, path, preload=False, download=False):
        """Add the file to downloadables if download is True.

        :param str path:
            Path to file to use.
        :param bool preload:
            If ``True`` the file will be pre-loaded.
        :param bool download:
            If ``True`` the file will be added to the ``downloadables`` string
            table.
        """
        # Save the path that should be precached
        self._path = path

        # Save whether the the file should be preloaded
        self._preload = preload

        # Is the map loaded?
        if global_vars.map_name:

            # Precache the instance
            self._precache()

        # Register the server_spawn event to precache every map change
        event_manager.register_for_event('server_spawn', self._server_spawn)

        # Should the path be added to the downloadables?
        if download:

            # Add the path to the downloadables
            self._downloads = Downloadables()
            self._downloads.add(self._path)
コード例 #5
0
    def __init__(self, callback):
        """Store the callback and register the event."""
        # Store the callback
        self.callback = callback

        # Register the event
        event_manager.register_for_event(
            self.callback.__name__, self.callback)
コード例 #6
0
ファイル: base_game.py プロジェクト: Hackmastr/ArcJail
    def stage_register_event_handlers(self):
        for game_event_handler_ in self._events.values():
            event_manager.register_for_event(game_event_handler_.event,
                                             game_event_handler_)

        for game_internal_event_handler_ in self._internal_events.values():
            internal_event_manager.register_event_handler(
                game_internal_event_handler_.event,
                game_internal_event_handler_)
コード例 #7
0
    def stage_prepare_register_event_handlers(self):
        event_manager.register_for_event(
            'player_death', self._prepare_event_handler_player_death)

        event_manager.register_for_event(
            'player_hurt', self._prepare_event_handler_player_hurt)

        internal_event_manager.register_event_handler(
            'player_deleted', self._prepare_event_handler_player_deleted)
コード例 #8
0
ファイル: cvar_warning.py プロジェクト: CookStar/SmallLib
    def enable(self):
        if id(self) not in self._warnings:
            unregistered_events = set(self.events)
            for cvar_warning in self._warnings.values():
                unregistered_events -= cvar_warning.events
            for event_name in unregistered_events:
                event_manager.register_for_event(event_name, self.game_event)

            self.restore()
            self._warnings[id(self)] = self
コード例 #9
0
ファイル: prepare_time.py プロジェクト: KirillMysnik/ArcJail
    def stage_prepare_register_event_handlers(self):
        event_manager.register_for_event(
            'player_death', self._prepare_event_handler_player_death)

        event_manager.register_for_event(
            'player_hurt', self._prepare_event_handler_player_hurt)

        internal_event_manager.register_event_handler(
            'player_deleted',
            self._prepare_event_handler_player_deleted
        )
コード例 #10
0
ファイル: sp_irc.py プロジェクト: necavi/sp_irc
 def __init__(self, ins):
     super().__init__(ins)
     self.config_path = CFG_PATH.joinpath("sp_irc.ini")
     if not os.path.exists(self.config_path):
         shutil.copyfile(join_script_path("sp_irc.ini"), self.config_path)
     self.config = ConfigObj(self.config_path, configspec=join_script_path("sp_irc_spec.ini"))
     self.config.validate(Validator(), copy=True)
     self.events = self.config["events"]
     for event in self.events:
         event_manager.register_for_event(event, self.parse_event)
     self.bot.events.ChanMsg += self.irc_message
     self.bot.events.Connected += self.connected
コード例 #11
0
    def __call__(self, callback):
        """Store the callback and register the events."""
        # Store the callback
        self.callback = callback

        # Loop through all event names
        for event_name in self._event_names:

            # Register the event
            event_manager.register_for_event(event_name, self.callback)

        # Return the callback
        return self.callback
コード例 #12
0
ファイル: __init__.py プロジェクト: Doldol/Source.Python
    def __call__(self, callback):
        """Store the callback and register the events."""
        # Store the callback
        self._callback = callback

        # Loop through all event names
        for event_name in self._event_names:

            # Register the event
            event_manager.register_for_event(event_name, self._callback)

        # Return the instance so that it unloads properly
        return self
コード例 #13
0
    def __call__(self, callback):
        """Store the callback and register the events."""
        # Store the callback
        self.callback = callback

        # Loop through all event names
        for event_name in self._event_names:

            # Register the event
            event_manager.register_for_event(event_name, self.callback)

        # Return the callback
        return self.callback
コード例 #14
0
def load():
    """Register all warmup listeners."""
    event_manager.register_for_event('player_death', _player_death)
    event_manager.register_for_event('weapon_fire', _weapon_fire)
    event_manager.register_for_event('player_spawn', _player_spawn)
    client_command_manager.register_commands('joinclass', _join_class)
    for player in PlayerIter('alive'):
        _give_warmup_weapon(player)
コード例 #15
0
ファイル: cvar_warning.py プロジェクト: CookStar/SmallLib
    def __init__(self, cvar_name, cvar_value, *events, kick=0):
        for cvar_warning in self._warnings.values():
            if (cvar_warning.cvar_name == cvar_name
                    and cvar_warning.cvar_value != cvar_value):
                raise ValueError("Warning already exists.")

        super().__init__(cvar_name, cvar_value)

        if events:
            self.events = set(events)
        else:
            self.events = {"player_death"}

        self.kick = kick
        self.warned = defaultdict(int)

        unregistered_events = set(self.events)
        for cvar_warning in self._warnings.values():
            unregistered_events -= cvar_warning.events
        for event_name in unregistered_events:
            event_manager.register_for_event(event_name, self.game_event)

        self._warnings[id(self)] = self
コード例 #16
0
ファイル: storage.py プロジェクト: Doldol/Source.Python
    @property
    def connection(self):
        """Return the connection to the database."""
        return self._connection

    @property
    def cursor(self):
        """Return the cursor instance."""
        return self._cursor

    def server_spawn(self, game_event):
        """Store the dictionary to the database on map change."""
        self.connection.commit()

# Set a variable to make sure _UniqueSettings doesn't
#   call _player_settings_storage while it is being initialized.
_IN_INITIALIZATION = True

# Get the _PlayerSettingsDictionary instance
_player_settings_storage = _PlayerSettingsDictionary()

# Now that the initialization is done, allow
#   _UniqueSettings to call _player_settings_storage.
_IN_INITIALIZATION = False

# Register for the event server_spawn in order
# to store the database to file on map change
event_manager.register_for_event(
    'server_spawn', _player_settings_storage.server_spawn)
コード例 #17
0
ファイル: downloads.py プロジェクト: Doldol/Source.Python
    def _add_to_download_table(self, item):
        """Add the given file to the downloadables table."""
        # Is the server still in launching process?
        if self.download_table is None:

            # If so, no need to go further...
            return

        # Add the given file to the downloadables table.
        self.download_table.add_string(item, item)

    def server_spawn(self, game_event):
        """Add all items stored as downloadables to the stringtable."""
        # Refresh the downloadables table instance
        self._refresh_table_instance()

        # Loop through all items in the list
        for item in self:

            # Set all items in the current item as downloadables
            item._set_all_downloads()


# Get the _DownloadablesList instance
_downloadables_list = _DownloadablesList()

# Register for the event server_spawn in
# order to reset all downloads on map change
event_manager.register_for_event("server_spawn", _downloadables_list.server_spawn)
コード例 #18
0
ファイル: downloads.py プロジェクト: dsezen/Source.Python
    def _add_to_download_table(self, item):
        """Add the given file to the downloadables table."""
        # Is the server still in launching process?
        if self.download_table is None:

            # If so, no need to go further...
            return

        # Add the given file to the downloadables table.
        self.download_table.add_string(item, item)

    def server_spawn(self, game_event):
        """Add all items stored as downloadables to the stringtable."""
        # Refresh the downloadables table instance
        self._refresh_table_instance()

        # Loop through all items in the list
        for item in self:

            # Set all items in the current item as downloadables
            item._set_all_downloads()


# Get the _DownloadablesList instance
_downloadables_list = _DownloadablesList()

# Register for the event server_spawn in
# order to reset all downloads on map change
event_manager.register_for_event('server_spawn',
                                 _downloadables_list.server_spawn)
コード例 #19
0
 def register(self):
     for event_name in self._event_names:
         event_manager.register_for_event(event_name, self.callback)