def getProfileId(self): pid = self.profileid if not host.pmgr_p_get("ai", self.index) and pid == 0: # Don't bother doing this if player is 'bot pid = int(host.pmgr_p_get("profileid", self.index)) self.profileid = pid if pid == 0: if pm_backend_pid_manager == 1: # Try Backend playerID first - idea by ArmEagle if g_debug: print "Retrieving Profile ID (%s) via HTTP/1.1 miniclient" % str(host.pmgr_p_get("name", self.index)) # URL for retrieving player ID via internal miniclient player_nick = string.replace(str(host.pmgr_p_get("name", self.index)), ' ', '%20') asp_playerid = '/ASP/getplayerid.aspx?nick=' + player_nick if g_debug: print "URI: %s" % (asp_playerid) # Fetch Data data = http_get( http_backend_addr, http_backend_port, asp_playerid ) if data and data[0] == 'O': if g_debug: print "Received PID data is VALID, length %d" % int(len(data)) datalines = data.splitlines() pidval = datalines[2].split('\t') pid = int(pidval[1]) else: print "Received PID data is INVALID, length %d" % int(len(data)) # Use PID.TXT to find PlayerID if pid == 0: # Backend check is disabled or failed if g_debug: print "Retrieving Profile ID (%s) via PID file" % str(host.pmgr_p_get("name", self.index)) try: fh = file(pm_local_pid_txt_file, 'rb') line = fh.readlines() fh.close() count = 0 while count < len(line): if line[count].rstrip() == host.pmgr_p_get("name", self.index): pid = int(line[count + 1].rstrip()) break count += 2 # create a new PID - idea by FiberLetalis if pid == 0: if g_debug: print "New player, creating Profile ID..." new_pid = int(line[count - 1].rstrip()) + 1 fh = file(pm_local_pid_txt_file, 'ab') fh.write('\r\n' + host.pmgr_p_get("name", self.index) + '\r\n' + str(new_pid)) fh.close() pid = new_pid except IOError: print 'PID file not found!' self.profileid = pid return pid else: return pid
def getProfileId(self): # No stats, Then we dont bother fetching Pid from ASP if not stats_enable: return host.pmgr_p_get("profileid", self.index) pid = self.profileid # If we are a human player, attempt to get PID from the bf2 server if not host.pmgr_p_get("ai", self.index) and pid == 0: pid = int(host.pmgr_p_get("profileid", self.index)) # If we don't have a PID up to this point, fetch it from ASP back end if pid == 0: if g_debug: print "Retrieving Profile ID (%s) via HTTP/1.1 miniclient" % str( host.pmgr_p_get("name", self.index)) # URL for retrieving player ID via internal miniclient player_nick = string.replace( str(host.pmgr_p_get("name", self.index)), ' ', '%20') asp_playerid = '/ASP/getplayerid.aspx?nick=' + player_nick + '&ai=' + str( host.pmgr_p_get("ai", self.index)) if g_debug: print "URI: %s" % (asp_playerid) # Fetch Data using miniclient data = http_get(http_backend_addr, http_backend_port, asp_playerid) if data and data[0] == 'O': if g_debug: print "Received PID data is VALID, length %d" % int( len(data)) datalines = data.splitlines() pidval = datalines[2].split('\t') pid = int(pidval[1]) else: print "Received PID data is INVALID, length %d" % int( len(data)) self.profileid = pid return pid
def onPlayerConnect(aPlayer): # Ignore AI players if aPlayer.isAIPlayer(): return #if g_debug: player_nick = string.replace(aPlayer.getName(), ' ', '%20') asp_URI = '/ASP/verifyplayer.aspx?pid=%d&nick=%s' % (int( aPlayer.getProfileId()), player_nick) # Run check print "Running CSE Verification Check on Player (%s)" % str( aPlayer.getName()) if g_debug: print "URI: %s" % (asp_URI) data = http_get(http_backend_addr, http_backend_port, asp_URI) if data and data[0] == 'O': # Split the response into an array datalines = data.splitlines() # Parse result and message items = datalines[2].split('\t') result = str(items[1]) message = str(items[2]) #if g_debug: print "Backend CSE Response on Player (%s): %s - %s " % (str( aPlayer.getName()), str(result), str(message)) # Is player OK? if (result == "NOK"): host.rcon_invoke('admin.kickPlayer ' + str(aPlayer.index)) else: print "Backend CSE Response on Player (%s) is INVALID, length %d" % int( len(data))
def getPlayerListData(asp_URI): playerListData = [] data = http_get( http_backend_addr, http_backend_port, asp_URI ) if data and data[0] == 'O': if g_debug: print "Received Clan list data is VALID, length %d" % int(len(data)) datalines = data.splitlines() skip = True i = 0 for dataline in datalines: # the first dataline retrieved only contains count and timestamp, # do nothing and mark the skip flag to false. # all subsequent datalines will be processed normally if dataline[0] == 'D' and skip: skip = False elif dataline[0] == 'D': items = dataline.split('\t') playerListData += [int(items[1])] if g_debug: print "List Member: %s (%s)" % (str(items[2]), str(items[1])) else: print "Received list Member data is INVALID, length %d" % int(len(data)) return playerListData
def onPlayerConnect(player): global updateTimer id = player.stats.connectionOrderNr # Check if player already in MedalMap, if so reconnect them reconnect = id in sessionPlayerMedalMap if id in sessionPlayerMedalMap: if g_debug: print "Player id=%d found in sessionPlayerMedalMap" % int(id) if not reconnect: newMedalSet = MedalSet() sessionPlayerMedalMap[id] = newMedalSet player.medals = sessionPlayerMedalMap[id] player.medals.connect(reconnect) if not reconnect: #rank player.score.rank = 0 # Added by Chump - for bf2statistics stats #if g_debug: print "Added player %d to medal checking" % (player.index) if g_debug: print "Added player %d, %s (%s) to medal/rank checking" % ( player.index, player.getName(), str(player.getProfileId()) ) else: player.score.rank = player.stats.rank # Added by Chump - for bf2statistics stats #if g_debug: print "Readded player %d to medal checking" % (player.index) if g_debug: print "Readded player %d to medal/rank checking" % player.index # This code is used to reduce the "request storm" generated at the start of a round. # Check if this player's STATS were updated in the last 30 seconds # We only need to do this at the start of a round, just ignore otherwise if player.getGlobalUpdateTime() > 30 and player.stats.wasHereAtStart == 1: # STATS are a bit stale, force gamespy request (this should only occur ONCE per round) # Final check just to make sure player isn't reconnecting mid-round due to a CTD if player.stats.timeOnLine < 30: reconnect = False if player.getProfileId() > 2000 and not reconnect: if g_debug: print "Getting Stats..." # get persistant stats from gamespy # Added by Chump - for bf2statistics stats (plus de-indenting) #if host.ss_getParam('ranked'): player.score.rank = player.stats.rank # STATS success = False if not player.isAIPlayer(): if g_debug: print "Requesting player STATS" success = host.pers_plrRequestStats(player.index, 1, globalKeyString) # Player is either AI or Offline, so we will manually get STATS if not success: if g_debug: print "Retrieving player STATS via HTTP/1.1 miniclient" # URL for retrieving player's awards and stats records via internal miniclient asp_playerinfo = '/ASP/getplayerinfo.aspx?pid=' + str(player.getProfileId()) + globalKeyString # Fetch Data data = http_get( http_backend_addr, http_backend_port, asp_playerinfo ) if data and data[0] == 'O': print "Received STATS data is VALID, length %d" % int(len(data)) stats = {} datalines = data.splitlines() keys = datalines[3].split('\t') vals = datalines[4].split('\t') if (len(keys) == len(vals)): if g_debug: print "Assembling STATS dictionary with %d keys" % int(len(keys)) for idx in range(1,len(keys)): stats[keys[idx]] = vals[idx] # eventually reattach persistent stats records to this player attachPlayerStats(player,stats) else: print "ERROR: Received STATS data is NOT VALID, length %d" % int(len(data)) # AWARDS success = False if not player.isAIPlayer(): if g_debug: print "Requesting player AWARDS" success = host.pers_plrRequestAwards(player.index, 1, "") # Player is either AI or Offline, so we will manually get AWARDS if not success: if g_debug: print "Retrieving player AWARDS via HTTP/1.1 miniclient" # URL for retrieving player's awards and stats records via internal miniclient asp_awardsinfo = '/ASP/getawardsinfo.aspx?pid=' + str(player.getProfileId()) # Fetch Data data = http_get( http_backend_addr, http_backend_port, asp_awardsinfo ) if data and data[0] == 'O': print "Received AWARDS data is VALID, lenght %d" % int(len(data)) awards = {} datalines = data.splitlines() skip = True for dataline in datalines: # the first dataline retrieved only contains pid and nick, # do nothing and mark the skip flag to false. # all subsequent datalines will be processed normally if dataline[0] == 'D' and skip: skip = False elif dataline[0] == 'D': items = dataline.split('\t') medalkey = items[1] medallev = items[2] awards[medalkey] = medallev # eventually reattach persistent awards records to this player attachPlayerAwards(player,awards) else: print "ERROR: Received AWARDS data is NOT VALID, length %d" % int(len(data)) # Record STATS update time player.setGlobalUpdateTime()
def onPlayerConnect(player): global updateTimer id = player.stats.connectionOrderNr # Check if player already in MedalMap, if so reconnect them reconnect = id in sessionPlayerMedalMap if id in sessionPlayerMedalMap: if g_debug: print "Player id=%d found in sessionPlayerMedalMap" % int(id) if not reconnect: newMedalSet = MedalSet() sessionPlayerMedalMap[id] = newMedalSet player.medals = sessionPlayerMedalMap[id] player.medals.connect(reconnect) if not reconnect: #rank player.score.rank = 0 # Added by Chump - for bf2statistics stats #if g_debug: print "Added player %d to medal checking" % (player.index) if g_debug: print "Added player %d, %s (%s) to medal/rank checking" % ( player.index, player.getName(), str(player.getProfileId())) else: player.score.rank = player.stats.rank # Added by Chump - for bf2statistics stats #if g_debug: print "Readded player %d to medal checking" % (player.index) if g_debug: print "Readded player %d to medal/rank checking" % player.index # This code is used to reduce the "request storm" generated at the start of a round. # Check if this player's STATS were updated in the last 30 seconds # We only need to do this at the start of a round, just ignore otherwise if player.getGlobalUpdateTime( ) > 30 and player.stats.wasHereAtStart == 1: # STATS are a bit stale, force gamespy request (this should only occur ONCE per round) # Final check just to make sure player isn't reconnecting mid-round due to a CTD if player.stats.timeOnLine < 30: reconnect = False if player.getProfileId() > 2000 and not reconnect: if g_debug: print "Getting Stats..." # get persistant stats from gamespy # Added by Chump - for bf2statistics stats (plus de-indenting) #if host.ss_getParam('ranked'): player.score.rank = player.stats.rank # STATS success = False if not player.isAIPlayer(): if g_debug: print "Requesting player STATS" success = host.pers_plrRequestStats(player.index, 1, globalKeyString) # Player is either AI or Offline, so we will manually get STATS if not success: if g_debug: print "Retrieving player STATS via HTTP/1.1 miniclient" # URL for retrieving player's awards and stats records via internal miniclient asp_playerinfo = '/ASP/getplayerinfo.aspx?pid=' + str( player.getProfileId()) + globalKeyString # Fetch Data data = http_get(http_backend_addr, http_backend_port, asp_playerinfo) if data and data[0] == 'O': print "Received STATS data is VALID, length %d" % int( len(data)) stats = {} datalines = data.splitlines() keys = datalines[3].split('\t') vals = datalines[4].split('\t') if (len(keys) == len(vals)): if g_debug: print "Assembling STATS dictionary with %d keys" % int( len(keys)) for idx in range(1, len(keys)): stats[keys[idx]] = vals[idx] # eventually reattach persistent stats records to this player attachPlayerStats(player, stats) else: print "ERROR: Received STATS data is NOT VALID, length %d" % int( len(data)) # AWARDS success = False if not player.isAIPlayer(): if g_debug: print "Requesting player AWARDS" success = host.pers_plrRequestAwards(player.index, 1, "") # Player is either AI or Offline, so we will manually get AWARDS if not success: if g_debug: print "Retrieving player AWARDS via HTTP/1.1 miniclient" # URL for retrieving player's awards and stats records via internal miniclient asp_awardsinfo = '/ASP/getawardsinfo.aspx?pid=' + str( player.getProfileId()) # Fetch Data data = http_get(http_backend_addr, http_backend_port, asp_awardsinfo) if data and data[0] == 'O': print "Received AWARDS data is VALID, lenght %d" % int( len(data)) awards = {} datalines = data.splitlines() skip = True for dataline in datalines: # the first dataline retrieved only contains pid and nick, # do nothing and mark the skip flag to false. # all subsequent datalines will be processed normally if dataline[0] == 'D' and skip: skip = False elif dataline[0] == 'D': items = dataline.split('\t') medalkey = items[1] medallev = items[2] awards[medalkey] = medallev # eventually reattach persistent awards records to this player attachPlayerAwards(player, awards) else: print "ERROR: Received AWARDS data is NOT VALID, length %d" % int( len(data)) # Record STATS update time player.setGlobalUpdateTime()