def address_from_playerinfo(playerinfo): """Return the IP address for the given player. If the player is a bot, an empty string will be returned. :param PlayerInfo playerinfo: The PlayerInfo instance to get the UniqueID from. :return: The IP address. E.g. '127.0.0.1:27015' :rtype: str """ # Is the player a bot? if playerinfo.is_fake_client() or 'BOT' in playerinfo.steamid: # Return an empty string, since using <netinfo>.address crashes # with bots return '' # Get the player's index index = index_from_playerinfo(playerinfo) # Get the player's NetInfo instance netinfo = engine_server.get_player_net_info(index) # Return the player's IP Address return netinfo.address
def address_from_playerinfo(playerinfo): """Return the IP address for the given player. If the player is a bot, an empty string will be returned. :param PlayerInfo playerinfo: The PlayerInfo instance to get the UniqueID from. :return: The IP address. E.g. '127.0.0.1:27015' :rtype: str """ # Is the player a bot? if playerinfo.is_fake_client(): # Return an empty string, since using <netinfo>.address crashes # with bots return '' # Get the player's index index = index_from_playerinfo(playerinfo) # Get the player's NetInfo instance netinfo = engine_server.get_player_net_info(index) # Return the player's IP Address return netinfo.address
def index_from_steamid(steamid): """Return an index from the given SteamID.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's SteamID the same as the one given? if playerinfo.get_networkid_string() == steamid: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching SteamID, raise an error raise ValueError('Invalid SteamID "{0}"'.format(steamid))
def index_from_name(name): """Return an index from the given player name.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's name the same as the one given? if playerinfo.get_name() == name: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching name, raise an error raise ValueError('Invalid name "{0}"'.format(name))
def index_from_uniqueid(uniqueid): """Return an index from the given UniqueID.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's UniqueID the same as the one given? if uniqueid_from_playerinfo(playerinfo) == uniqueid: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching UniqueID, raise an error raise ValueError('Invalid UniqueID "{0}"'.format(uniqueid))
def address_from_playerinfo(playerinfo): """Return the IP address for the given player.""" # Is the player a bot? if playerinfo.is_fake_client(): # Return a base value, since using # <netinfo>.get_address() crashes with bots return "0" # Get the player's index index = index_from_playerinfo(playerinfo) # Get the player's NetInfo instance netinfo = engine_server.get_player_net_info(index) # Return the player's IP Address return netinfo.get_address()
def index_from_steamid(steamid): """Return an index from the given SteamID. :param str steamid: The SteamID to get the index of. :rtype: int """ # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's SteamID the same as the one given? if playerinfo.steamid == steamid: # Return the index of the current player return index_from_playerinfo(playerinfo) raise ValueError( 'Conversion from "SteamID" ({}) to "Index" failed.'.format(steamid))
def index_from_name(name): """Return an index from the given player name. :param str name: The player name to get the index of. :rtype: int """ # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's name the same as the one given? if playerinfo.name == name: # Return the index of the current player return index_from_playerinfo(playerinfo) raise ValueError( 'Conversion from "Name" ({}) to "Index" failed.'.format(name))