Example #1
0
def _initialize_players():
    for i in range(1, global_vars.max_clients + 1):
        try:
            edict = edict_from_index(i)
        except ValueError:
            pass
        else:
            baseplayer = BasePlayer(i)
            baseplayer._edict = edict
            baseplayer._userid = userid_from_edict(edict)
            baseplayer._name = playerinfo_from_edict(edict).name
            baseplayer._connected = True
            baseplayer._fake_client = playerinfo_from_edict(
                edict).is_fake_client()

            if baseplayer._fake_client:
                baseplayer._accountid = baseplayer._name
                baseplayer._steamid2 = 'BOT'
                baseplayer._uniqueid = f'BOT_{baseplayer.name}'
                baseplayer._authorized = True

                OnClientAuthorized.manager.notify(baseplayer)
            else:
                if engine_server.is_client_fully_authenticated(
                        baseplayer.edict):
                    _initialize(baseplayer)
                else:
                    _authenticate.add(baseplayer)
Example #2
0
 def update(self):
     for index in self:
         CvarQuery(
             edict_from_index(index),
             self.store,
             self.cvar_name,
             self.cvar_value,
         )
     self.clear()
Example #3
0
 def update_index(self, index):
     if index in self:
         CvarQuery(
             edict_from_index(index),
             self.store,
             self.cvar_name,
             self.cvar_value,
         )
         self.remove(index)
    def weapon_indexes(
            self, classname=None, is_filters=None, not_filters=None):
        """Iterate over the player's weapon indexes for the given arguments.

        :return:
            A generator of indexes.
        :rtype: generator
        """
        # Is the weapon array supported for the current game?
        if _weapon_prop_length is None:
            return

        # Loop through the length of the weapon array
        for offset in range(_weapon_prop_length):

            # Get the player's current weapon at this offset
            handle = self.get_property_int(
                '{base}{offset:03d}'.format(
                    base=weapon_manager.myweapons,
                    offset=offset,
                )
            )

            # Try to get the index of the handle
            try:
                index = index_from_inthandle(handle)
            except (ValueError, OverflowError):
                continue

            # Get the weapon's classname
            weapon_class = edict_from_index(index).classname

            # Was a classname given and the current
            # weapon is not of that classname?
            if classname is not None and weapon_class != classname:

                # Do not yield this index
                continue

            # Import WeaponClassIter to use its functionality
            from filters.weapons import WeaponClassIter

            # Was a weapon type given and the
            # current weapon is not of that type?
            if not (is_filters is None and not_filters is None):
                if weapon_class not in map(
                        lambda value: value.name,
                        WeaponClassIter(is_filters, not_filters)):

                    # Do not yield this index
                    continue

            # Yield the index
            yield index
Example #5
0
    def weapon_indexes(self,
                       classname=None,
                       is_filters=None,
                       not_filters=None):
        """Iterate over the player's weapon indexes for the given arguments.

        :return:
            A generator of indexes.
        :rtype: generator
        """
        # Is the weapon array supported for the current game?
        if _weapon_prop_length is None:
            return

        # Loop through the length of the weapon array
        for offset in range(_weapon_prop_length):

            # Get the player's current weapon at this offset
            handle = self.get_property_int('{base}{offset:03d}'.format(
                base=weapon_manager.myweapons,
                offset=offset,
            ))

            # Try to get the index of the handle
            try:
                index = index_from_inthandle(handle)
            except (ValueError, OverflowError):
                continue

            # Get the weapon's classname
            weapon_class = edict_from_index(index).classname

            # Was a classname given and the current
            # weapon is not of that classname?
            if classname is not None and weapon_class != classname:

                # Do not yield this index
                continue

            # Import WeaponClassIter to use its functionality
            from filters.weapons import WeaponClassIter

            # Was a weapon type given and the
            # current weapon is not of that type?
            if not (is_filters is None and not_filters is None):
                if weapon_class not in map(
                        lambda value: value.name,
                        WeaponClassIter(is_filters, not_filters)):

                    # Do not yield this index
                    continue

            # Yield the index
            yield index
Example #6
0
    def _close(self, player_index):
        """See :meth:`menus.base._BaseMenu._close`."""
        queue = self.get_user_queue(player_index)
        queue.priority -= 1

        # Unfortunately, this doesn't hide the menu :(
        data = KeyValues('menu')
        data.set_string('title', '')
        data.set_int('level', queue.priority)
        data.set_int('time', 10)
        data.set_string('msg', '')
        create_message(edict_from_index(player_index), DialogType.MENU, data)
Example #7
0
    def max_ammo(self, weapon_classnames):
        for index in self.player.weapon_indexes():
            weapon_classname = edict_from_index(index).classname
            if weapon_classname not in weapon_classnames:
                continue

            if weapon_classname in PROJECTILE_CLASSNAMES:
                continue

            weapon_class = weapon_manager[weapon_classname]
            if weapon_class.maxammo > 0:
                Weapon(index).ammo = weapon_class.maxammo
Example #8
0
    def _close(self, player_index):
        """Close a menu by overriding it with an empty menu.

        @param <player_index>:
        A player index.
        """
        queue = self.get_user_queue(player_index)
        queue.priority -= 1

        # Unfortunately, this doesn't hide the menu :(
        data = KeyValues('menu')
        data.set_string('title', '')
        data.set_int('level', queue.priority)
        data.set_int('time', 10)
        data.set_string('msg', '')
        create_message(edict_from_index(player_index), DialogType.MENU, data)
Example #9
0
    def weapon_indexes(self,
                       classname=None,
                       is_filters=None,
                       not_filters=None):
        """Iterate over all currently held weapons by thier index."""
        # Is the weapon array supported for the current game?
        if _weapon_prop_length is None:
            return

        # Loop through the length of the weapon array
        for offset in range(_weapon_prop_length):

            # Get the player's current weapon at this offset
            handle = self.get_property_int(weapon_manager.myweapons +
                                           '%03i' % offset)

            try:
                index = index_from_inthandle(handle)
            except (ValueError, OverflowError):
                continue

            # Get the weapon's classname
            weapon_class = edict_from_index(index).classname

            # Was a classname given and the current
            # weapon is not of that classname?
            if classname is not None and weapon_class != classname:

                # Do not yield this index
                continue

            # Import WeaponClassIter to use its functionality
            from filters.weapons import WeaponClassIter

            # Was a weapon type given and the
            # current weapon is not of that type?
            if not (is_filters is None and not_filters is None):
                if weapon_class not in map(
                        lambda value: value.name,
                        WeaponClassIter(is_filters, not_filters)):

                    # Do not yield this index
                    continue

            # Yield the index
            yield index
Example #10
0
    def _send(self, player_index):
        """Build and send the menu to the given player via create_message().

        :param int player_index: See :meth:`menus.base._BaseMenu._send`.
        """
        queue = self.get_user_queue(player_index)
        queue.priority -= 1

        # Build the menu
        data = self._build(player_index)

        # Set priority and display time
        data.set_int('level', queue.priority)
        data.set_int('time', 10)

        # Send the menu
        create_message(edict_from_index(player_index), DialogType.MENU, data)
Example #11
0
    def weapon_indexes(
            self, classname=None, is_filters=None, not_filters=None):
        """Iterate over all currently held weapons by thier index."""
        # Is the weapon array supported for the current game?
        if _weapon_prop_length is None:
            return

        # Loop through the length of the weapon array
        for offset in range(_weapon_prop_length):

            # Get the player's current weapon at this offset
            handle = self.get_property_int(
                weapon_manager.myweapons + '%03i' % offset)

            try:
                index = index_from_inthandle(handle)
            except (ValueError, OverflowError):
                continue

            # Get the weapon's classname
            weapon_class = edict_from_index(index).classname

            # Was a classname given and the current
            # weapon is not of that classname?
            if classname is not None and weapon_class != classname:

                # Do not yield this index
                continue

            # Import WeaponClassIter to use its functionality
            from filters.weapons import WeaponClassIter

            # Was a weapon type given and the
            # current weapon is not of that type?
            if not (is_filters is None and not_filters is None):
                if weapon_class not in map(
                        lambda value: value.name,
                        WeaponClassIter(is_filters, not_filters)):

                    # Do not yield this index
                    continue

            # Yield the index
            yield index
Example #12
0
    def __new__(cls, index):
        """Verify the given index is valid and store base attributes."""
        # Get the given indexes edict
        edict = edict_from_index(index, False)

        # Is the edict valid?
        if edict is None or edict.get_unknown() is None:

            # If not raise an error
            raise ValueError(
                'Index "{0}" is not a proper entity index.'.format(index))

        # Create the object
        self = BaseEntity.__new__(cls)

        # Set the entity's base attributes
        self._index = index
        self._edict = edict
        self._pointer = pointer_from_edict(edict)

        # Return the instance
        return self
Example #13
0
    def _send(self, player_index):
        """Build and send the menu to the given player via create_message().

        @param <player_index>:
        A player index.
        """
        queue = self.get_user_queue(player_index)
        queue.priority -= 1

        # Build the menu
        data = self._build(player_index)

        # Set priority and display time
        data.set_int('level', queue.priority)
        data.set_int('time', 10)

        # Send the menu
        create_message(
            edict_from_index(player_index),
            DialogType.MENU,
            data
        )
Example #14
0
    def game_event(game_event):
        try:
            player = Player.from_userid(game_event["userid"])
            CvarWarning._events[game_event.name][player.index] = 0
        except KeyError:
            player = None
            CvarWarning._events.pop(game_event.name, None)

        for cvar_warning in CvarWarning._warnings.values():
            if game_event.name not in cvar_warning.events:
                continue

            if player is not None:
                if player.index in cvar_warning:
                    CvarQuery(
                        player.edict,
                        cvar_warning.warn,
                        cvar_warning.cvar_name,
                        cvar_warning.cvar_value,
                        event_name=game_event.name,
                    )
                    CvarWarning._events[game_event.name][player.index] += 1
                    cvar_warning.discard(player.index)
                    continue

            else:
                for index in cvar_warning:
                    CvarQuery(
                        edict_from_index(index),
                        cvar_warning.warn,
                        cvar_warning.cvar_name,
                        cvar_warning.cvar_value,
                        event_name=game_event.name,
                    )
                    CvarWarning._events[game_event.name][index] += 1
                cvar_warning.clear()
Example #15
0
    def _weapon_pickup_filter(self, player, weapon_index):
        if player not in self._players:
            return True

        weapon_classname = edict_from_index(weapon_index).classname
        return weapon_classname in self.map_data['ARENA_EQUIPMENT']
Example #16
0
    def _weapon_pickup_filter(self, player, weapon_index):
        if player not in self._players:
            return True

        weapon_classname = edict_from_index(weapon_index).classname
        return weapon_classname in self._settings.get('weapons', ())
Example #17
0
    def edict(self):
        """Return the entity's edict instance."""
        if self._edict is None:
            self._edict = edict_from_index(self.index)

        return self._edict
Example #18
0
 def client_fully_connect(index):
     """Query the player's language when they are fully connected."""
     from entities.helpers import edict_from_index
     engine_server.start_query_cvar_value(
         edict_from_index(index), 'cl_language')
Example #19
0
 def edict(self):
     """Return the entity's :class:`entities.Edict` instance."""
     if self._edict is None:
         edict = edict_from_index(self.index)
         object.__setattr__(self, '_edict', edict)
     return self._edict
    def _weapon_pickup_filter(self, player, weapon_index):
        if player not in self._players:
            return True

        weapon_classname = edict_from_index(weapon_index).classname
        return weapon_classname == FLASHBANG_CLASSNAME
Example #21
0
    def _weapon_pickup_filter(self, player, weapon_index):
        if player not in self._players:
            return True

        weapon_classname = edict_from_index(weapon_index).classname
        return weapon_classname in self.map_data['ARENA_EQUIPMENT']
    def _weapon_pickup_filter(self, player, weapon_index):
        if player not in self._players:
            return True

        weapon_classname = edict_from_index(weapon_index).classname
        return weapon_classname == FLASHBANG_CLASSNAME