def on_client_disconnect(index): # This can occur if the player leaves the server before OnClientActive was called try: uniqueid = uniqueid_from_playerinfo(playerinfo_from_index(index)) except ValueError: return wcsplayer = Player(uniqueid) # If we failed to get the correct uniqueid for some reason, do not proceed assert wcsplayer.uniqueid == uniqueid, (wcsplayer.uniqueid, uniqueid) OnPlayerDelete.manager.notify(wcsplayer) for delay in _delays.pop(wcsplayer.userid, []): delay.cancel() del Player._cache_userids[wcsplayer.userid] del Player._cache_indexes[wcsplayer.index] if wcsplayer.ready: wcsplayer._lastconnect = time() wcsplayer.save() database_manager.callback(wcsplayer._query_save)
def from_index(cls, index): wcsplayer = cls._cache_indexes.get(index) if wcsplayer is None: playerinfo = playerinfo_from_index(index) uniqueid = uniqueid_from_playerinfo(playerinfo) wcsplayer = cls._cache_indexes[index] = cls(uniqueid) return wcsplayer
def _chosen_value(self, menu, index, option): """Store the player's chosen value for the setting.""" # Get the client's uniqueid uniqueid = uniqueid_from_playerinfo(playerinfo_from_index(index)) # Set the player's setting _player_settings_storage[uniqueid][self.convar] = option.value # Send the player a message about their changed setting _message.send(index, convar=self.convar, value=option.value)
def from_userid(cls, userid): wcsplayer = cls._cache_userids.get(userid) if wcsplayer is None: index = index_from_userid(userid) playerinfo = playerinfo_from_index(index) uniqueid = uniqueid_from_playerinfo(playerinfo) wcsplayer = cls._cache_userids[userid] = cls(uniqueid) return wcsplayer
def __init__(self, index): self.index = index self.salt = None playerinfo = playerinfo_from_index(index) uniqueid = uniqueid_from_playerinfo(playerinfo) if uniqueid != playerinfo.steamid: raise ValueError( "Cannot initialize MOTDPlayer for bots or LAN players") self.steamid64 = str(SteamID.parse(playerinfo.steamid).to_uint64()) self._next_session_id = 1 self._sessions = {} self._loaded = False
def is_player_authorized( self, playerinfo, level=None, permission=None, flag=None): """Check to see if the player is authorized.""" # Get the player's uniqueid uniqueid = uniqueid_from_playerinfo(playerinfo) # Loop through all loaded auth providers for provider in self: # Is the player authorized? if self[provider].is_player_authorized( uniqueid, level, permission, flag): # If the player is authorized, return true return True # If the player is not found authorized for any provider, return false return False
def get_setting(self, index): """Return the setting value for the given player index.""" # Get the client's convar value value = engine_server.get_client_convar_value(index, self.convar) # Try to typecast the value, suppressing ValueErrors with suppress(ValueError): # Typecast the given value value = self._type(value) # Is the given value a proper one for the convar? if self._is_valid_setting(value): # If so, return the value return value # Get the client's uniqueid uniqueid = uniqueid_from_playerinfo(playerinfo_from_index(index)) # Is the uniqueid in the setting's storage dictionary? if uniqueid in _player_settings_storage: # Is the convar in the clients's dictionary? if self.convar in _player_settings_storage[uniqueid]: # Get the client's value for the convar value = _player_settings_storage[uniqueid][self.convar] # Try to typecast the value, suppressing ValueErrors with suppress(ValueError): # Typecast the given value value = self._type(value) # Is the given value a proper one for the convar? if self._is_valid_setting(value): # Return the value return value # Return the default value return self.default
def uniqueid(self): """Return the player's unique ID. :rtype: str """ return uniqueid_from_playerinfo(self.playerinfo)
def on_client_active(index): wcsplayer = Player(uniqueid_from_playerinfo(playerinfo_from_index(index))) wcsplayer._userid = userid_from_index(index) wcsplayer._index = index
def uniqueid(self): """Return the player's uniqueid.""" return uniqueid_from_playerinfo(self.playerinfo)
# ============================================================================= # >> RETURN TYPES # ============================================================================= # Register the return type functions _player_iter_manager.register_return_type('index', index_from_edict) _player_iter_manager.register_return_type('edict', lambda edict: edict) _player_iter_manager.register_return_type( 'basehandle', basehandle_from_edict) _player_iter_manager.register_return_type( 'inthandle', inthandle_from_edict) _player_iter_manager.register_return_type( 'pointer', pointer_from_edict) _player_iter_manager.register_return_type( 'userid', userid_from_edict) _player_iter_manager.register_return_type( 'uniqueid', lambda edict: uniqueid_from_playerinfo( playerinfo_from_edict(edict))) _player_iter_manager.register_return_type( 'address', lambda edict: address_from_playerinfo( playerinfo_from_edict(edict))) _player_iter_manager.register_return_type( 'playerinfo', playerinfo_from_edict) _player_iter_manager.register_return_type( 'player', lambda edict: PlayerEntity( index_from_edict(edict))) _player_iter_manager.register_return_type( 'name', lambda edict: playerinfo_from_edict(edict).get_name()) _player_iter_manager.register_return_type( 'steamid', lambda edict: playerinfo_from_edict( edict).get_networkid_string()) _player_iter_manager.register_return_type( 'location', lambda edict: playerinfo_from_edict(edict).get_abs_origin())
def uniqueid(self): '''Returns the player's uniqueid''' return uniqueid_from_playerinfo(self.info)
def get_setting(self, index): '''Returns the setting value for the given player index''' # Get the convar's value convar = self.prefix + self.name.lower().replace(' ', '_') # Get the client's convar value value = EngineServer.get_client_convar_value(index, convar) # Use try/except to typecast the value try: # Typecast the given value value = self._type(value) # Was an exception encountered? except ValueError: # Do nothing if the error occurred pass # Was no exception encountered? else: # Is the given value a proper one for the convar? if self._is_valid_setting(value): # If so, return the value return value # Get the client's uniqueid uniqueid = uniqueid_from_playerinfo(playerinfo_from_index(index)) # Is the uniqueid in the setting's storage dictionary? if uniqueid in _PlayerSettingsStorage: # Is the convar in the clients's dictionary? if convar in _PlayerSettingsStorage[uniqueid]: # Get the client's value for the convar value = _PlayerSettingsStorage[uniqueid][convar] # Use try/except to typecast the value try: # Typecast the given value value = self._type(value) # Was an exception encountered? except ValueError: # Do nothing if the error occurred pass # Was no exception encountered? else: # Is the given value a proper one for the convar? if self._is_valid_setting(value): # Return the value return value # Return the default value return self.default