def repackStatsVectors(): # remove disconnected players cleanoutStatsVector() cleanoutMedalsVector() # repack stats and medal vector so there are no holes. gamespy doesnt like holes. medalMap = getMedalMap() statsMap = getStatsMap() playerOrderIt = getPlayerConnectionOrderIterator() newOrderIterator = 0 newStatsMap = {} newMedalMap = {} highestId = 0 for id, statsItem in statsMap.iteritems(): newStatsMap[newOrderIterator] = statsItem if id in medalMap: newMedalMap[newOrderIterator] = medalMap[id] statsItem.connectionOrderNr = newOrderIterator newOrderIterator += 1 print "Repacked stats map. Stats map size=%d. OrderIt changed from %d to %d" % (len(statsMap), playerOrderIt, newOrderIterator) setPlayerConnectionOrderIterator(newOrderIterator) setStatsMap(newStatsMap) setMedalMap(newMedalMap)
def repackStatsVectors(): # remove disconnected players cleanoutStatsVector() cleanoutMedalsVector() # repack stats and medal vector so there are no holes. gamespy doesnt like holes. medalMap = getMedalMap() statsMap = getStatsMap() playerOrderIt = getPlayerConnectionOrderIterator() newOrderIterator = 0 newStatsMap = {} newMedalMap = {} highestId = 0 for id, statsItem in statsMap.iteritems(): newStatsMap[newOrderIterator] = statsItem if id in medalMap: newMedalMap[newOrderIterator] = medalMap[id] statsItem.connectionOrderNr = newOrderIterator newOrderIterator += 1 print "Repacked stats map. Stats map size=%d. OrderIt changed from %d to %d" % ( len(statsMap), playerOrderIt, newOrderIterator) setPlayerConnectionOrderIterator(newOrderIterator) setStatsMap(newStatsMap) setMedalMap(newMedalMap)
def givePositionalMedals(endOfRound, winningTeam): if endOfRound: # give medals for position sortedPlayers = [] statsMap = getStatsMap() for sp in statsMap.itervalues(): sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp.connectionOrderNr)] sortedPlayers.sort() sortedPlayers.reverse() global sessionPlayerMedalMap if len(sortedPlayers ) > 0 and sortedPlayers[0][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[0][1]].placeMedals[0] += 1 sessionPlayerMedalMap[sortedPlayers[0][1]].placeMedalThisRound = 1 if len(sortedPlayers ) > 1 and sortedPlayers[1][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[1][1]].placeMedals[1] += 1 sessionPlayerMedalMap[sortedPlayers[1][1]].placeMedalThisRound = 2 if len(sortedPlayers ) > 2 and sortedPlayers[2][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[2][1]].placeMedals[2] += 1 sessionPlayerMedalMap[sortedPlayers[2][1]].placeMedalThisRound = 3
def getSnapShot(): print "snapshot.py: Assembling snapshot" #snapShot = "\\" global map_start snapShot = snapshot_prefix + "\\" + bf2.gameLogic.getMapName() + "\\" snapShot += "mapstart\\" + str(map_start) + "\\mapend\\" + str(time()) + "\\" snapShot += "win\\" + str(bf2.gameLogic.getWinner()) + "\\" statsMap = getStatsMap() # ---------------------------------------------------------------------------- # omero 2006-04-10 # ---------------------------------------------------------------------------- # this will be used for detecting which mod is running and # set standardKeys['v'] accordingly # running_mod = str(host.sgl_getModDirectory()) if ( running_mod == "mods/bf2142" ): v_value = "bf2142" else: v_value = "!!!ERROR!!! fixme" if g_debug: print "snapshot.py: Running MOD: %s" % (str(v_value)) standardKeys = [ ("gm", getGameModeId(bf2.serverSettings.getGameMode())), ("m", getMapId(bf2.serverSettings.getMapName())), ("v", str(v_value)), ("pc", len(statsMap)), ] # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] stdKeyVals = [] for k in standardKeys: stdKeyVals.append ("\\".join((k[0], str(k[1])))) snapShot += "\\".join(stdKeyVals) if g_debug: print "snapshot.py: Snapshot Pre-processing complete: %s" % (str(snapShot)) playerSnapShots = "" if g_debug: print "snapshot.py: Num clients to base snap on: %d" % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print "snapshot.py: Processing PID: %s" % (str(sp.profileId)) playerSnapShot = getPlayerSnapshot(sp) playerSnapShots += playerSnapShot snapShot += playerSnapShots # Add EOF marker for validation snapShot += "\\EOF\\1" return snapShot
def cleanoutStatsVector(): print "snapshot.py: Cleaning out unconnected players from stats map" statsMap = getStatsMap() # remove disconnected players after snapshot was sent removeList = [] for pid in statsMap: foundPlayer = False for p in bf2.playerManager.getPlayers(): if p.stats == statsMap[pid]: foundPlayer = True break if not foundPlayer: removeList += [pid] for pid in removeList: print "snapshot.py: Removed player %d from stats." % pid del statsMap[pid]
def givePositionalMedals(endOfRound, winningTeam): if endOfRound: # give medals for position sortedPlayers = [] statsMap = getStatsMap() for sp in statsMap.itervalues(): sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp.connectionOrderNr)] sortedPlayers.sort() sortedPlayers.reverse() global sessionPlayerMedalMap if len(sortedPlayers) > 0 and sortedPlayers[0][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[0][1]].placeMedals[0] += 1 sessionPlayerMedalMap[sortedPlayers[0][1]].placeMedalThisRound = 1 if len(sortedPlayers) > 1 and sortedPlayers[1][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[1][1]].placeMedals[1] += 1 sessionPlayerMedalMap[sortedPlayers[1][1]].placeMedalThisRound = 2 if len(sortedPlayers) > 2 and sortedPlayers[2][1] in sessionPlayerMedalMap: sessionPlayerMedalMap[sortedPlayers[2][1]].placeMedals[2] += 1 sessionPlayerMedalMap[sortedPlayers[2][1]].placeMedalThisRound = 3
def getSnapShot(): print "Assembling snapshot" # Added by Chump - for bf2statistics stats #snapShot = "\\" #global PREFIX, map_start global map_start snapShot = snapshot_prefix + '\\' + bf2.gameLogic.getMapName() + '\\' snapShot += 'gameport\\' + str( bf2.serverSettings.getServerConfig('sv.serverPort')) + '\\' snapShot += 'queryport\\' + str( bf2.serverSettings.getServerConfig('sv.gameSpyPort')) + '\\' snapShot += 'mapstart\\' + str(map_start) + '\\mapend\\' + str( time()) + '\\' snapShot += 'win\\' + str(bf2.gameLogic.getWinner()) + '\\' statsMap = getStatsMap() # ---------------------------------------------------------------------------- # omero 2006-04-10 # ---------------------------------------------------------------------------- # this will be used for detecting which mod is running and # set standardKeys['v'] accordingly # defaults to 'bf2' # running_mod = str(host.sgl_getModDirectory()) if (running_mod.lower() == 'mods/bf2'): v_value = 'bf2' elif (running_mod.lower() == 'mods/bf2sp64'): v_value = 'bf2sp64' elif (running_mod.lower() == 'mods/xpack'): v_value = 'xpack' elif (running_mod.lower() == 'mods/poe2'): v_value = 'poe2' elif (running_mod.lower() == 'mods/aix2'): v_value = 'aix2' else: v_value = 'bf2' if g_debug: print 'Running MOD: %s' % (str(v_value)) standardKeys = [ # Added by Chump - for bf2statistics stats ("gm", getGameModeId(bf2.serverSettings.getGameMode())), ("m", getMapId(bf2.serverSettings.getMapName())), # Added by Chump - for bf2statistics stats ("v", str(v_value)), ("pc", len(statsMap)), ] # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] # get final ticket score if g_debug: print "Army 1 (%s) Score: %s" % (str( roundArmies[1]), str(bf2.gameLogic.getTickets(1))) if g_debug: print "Army 2 (%s) Score: %s" % (str( roundArmies[2]), str(bf2.gameLogic.getTickets(2))) standardKeys += [ ("ra1", str(roundArmies[1])), ("rs1", str(bf2.gameLogic.getTickets(1))), ("ra2", str(roundArmies[2])), ("rs2", str(bf2.gameLogic.getTickets(2))), ] standardKeys += [("rst2", str(bf2.gameLogic.getTickets(2)))] stdKeyVals = [] for k in standardKeys: stdKeyVals.append("\\".join((k[0], str(k[1])))) snapShot += "\\".join(stdKeyVals) if g_debug: print 'Snapshot Pre-processing complete: %s' % (str(snapShot)) playerSnapShots = "" if g_debug: print 'Num clients to base snap on: %d' % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print 'Processing PID: %s' % (str(sp.profileId)) playerSnapShot = getPlayerSnapshot(sp) # Added by Chump - for bf2statistics stats playerSnapShots += playerSnapShot # remove zero vals #zeroAllowedKeys = ('pid', 'a', 'mvns', 'mvks', 'vmns', 'vmks') #transformedSnapShot = "" #i = 0 #while i < len(playerSnapShot): # i += 1 # key = "" # while playerSnapShot[i] != "\\": # key += playerSnapShot[i] # i += 1 # i += 1 # value = "" # while i < len(playerSnapShot) and playerSnapShot[i] != "\\": # value += playerSnapShot[i] # i += 1 # if value != "0" or key[:key.find('_')] in zeroAllowedKeys: # keyVal = "\\" + key + "\\" + value # transformedSnapShot += keyVal #if len(transformedSnapShot) > 0: # playerSnapShots += transformedSnapShot print "Doing Player SNAPSHOTS" snapShot += playerSnapShots # Add EOF marker for validation snapShot += "\\EOF\\1" return snapShot
def getPlayerSnapshot(playerStat): if g_debug: print "snapshot.py: playerStat.profileId" awayBonus = int(playerStat.localScore.awayBonusScoreIAR + playerStat.localScore.awayBonusScore) totalScore = (playerStat.score - playerStat.localScore.diffRankScore) + int(playerStat.localScore.experienceScoreIAR + playerStat.localScore.experienceScore) + int(awayBonus) playerKeys = [ ("ban", playerStat.timesBanned ), #+ => total bans na server ("c", playerStat.complete ), #? => Complete ("capa", playerStat.localScore.cpAssists ), #+ => Capture Assists ("cpt", playerStat.localScore.cpCaptures ), #+ => Captured CPs ("crpt", totalScore ), #+ => Career Points ("cs", playerStat.localScore.commanderBonusScore ), #+ => Commander Score ("dass", playerStat.localScore.driverAssists ), #+ => Driver Assists ("dcpt", playerStat.localScore.cpDefends ), #+ => Defended Control Points ("dstrk", playerStat.longestDeathStreak ), #> => Worst Death Streak ("dths", playerStat.deaths ), #+ => Deaths ("gsco", playerStat.score ), #+ => Global Score ("hls", playerStat.localScore.heals ), #+ => Heals ("kick", playerStat.timesKicked ), #+ => total kicks from servers ("klla", playerStat.localScore.damageAssists ), #+ => Kill Assists ("klls", playerStat.kills ), #+ => Kills ("klstrk", playerStat.longestKillStreak ), #> => Kills Streak ("kluav", playerStat.weapons[WEAPON_TYPE_RECON_DRONE].kills ), #+ => Kills With Gun Drone ("nick", playerStat.name ), #? => Nickname ("ncpt", playerStat.localScore.cpNeutralizes ), #+ => Neutralized CPs #("pdt", playerStat.dogTags ), #+ => Unique Dog Tags Collected ("pdtc", playerStat.dogtagCount ), #+ => Dog Tags Collected ("pid", playerStat.profileId ), #? => pID ("resp", playerStat.localScore.ammos ), #+ => Re-supplies ("rnk", playerStat.rank ), #> => Rank ("rnkcg", playerStat.roundRankup ), #? => RankUp? ("rps", playerStat.localScore.repairs ), #+ => Repairs ("rvs", playerStat.localScore.revives ), #+ => Revives ("slbspn", playerStat.squadLeaderBeaconSpawns ), #+ => Spawns On Squad Beacons ("sluav", playerStat.squadLeaderUAV ), #+ => Spawn Dron Deployed ("suic", playerStat.localScore.suicides ), #+ => Suicides ("tac", int(playerStat.timeAsCmd) ), #+ => Time As Commander ("talw", int(playerStat.timePlayed - playerStat.timeAsCmd - playerStat.timeInSquad) ), #+ => Time As Lone Wolf ("tas", playerStat.localScore.titanAttackKills ), #+ => Titan Attack Score ("tasl", int(playerStat.timeAsSql) ), #+ => Time As Squad Leader ("tasm", int(playerStat.timeInSquad - playerStat.timeAsSql) ), #+ => Time As Squad Member ("tcd", playerStat.localScore.titanPartsDestroyed ), #+ => Titan Components Destroyed ("tcrd", playerStat.localScore.titanCoreDestroyed ), #+ => Titan Cores Destroyed ("tdmg", playerStat.localScore.teamDamages ), #+ => Team Damage ("tdrps", playerStat.localScore.titanDrops ), #+ => Titan Drops ("tds", playerStat.localScore.titanDefendKills ), #+ => Titan Defend Score ("tgd", playerStat.localScore.titanWeaponsDestroyed ), #+ => Titan Guns Destroyed ("tgr", playerStat.localScore.titanWeaponsRepaired ), #+ => Titan Guns Repaired ("tkls", playerStat.teamkills ), #+ => Team Kills ("toth", playerStat.bulletsHit ), #+ => Total Hits ("tots", playerStat.bulletsFired ), #+ => Total Fired ("tt", int(playerStat.timePlayed) ), #+ => Time Played ("tvdmg", playerStat.localScore.teamVehicleDamages ), #+ => Team Vehicle Damage ("twsc", playerStat.teamScore ), #+ => Teamwork Score ("t", playerStat.team ), # => TeamID ] # victims / victimizers statsMap = getStatsMap() for p in playerStat.killedPlayer: if not p in statsMap: if g_debug: print "snapshot.py: killedplayer_id victim connorder: ", playerStat.killedPlayer[p], " wasnt in statsmap!" else: playerKeys.append(("mvns", str(statsMap[p].profileId))) playerKeys.append(("mvks", str(playerStat.killedPlayer[p]))) keyvals = [] for k in playerKeys: keyvals.append ("\\".join((k[0], str(k[1])))) playerSnapShot = "\\".join(keyvals) # medals medalsSnapShot = "" if playerStat.medals: medalsSnapShot = playerStat.medals.getSnapShot() ################ vehicles vehiclesSS = {} for v in range(0, NUM_VEHICLE_TYPES): if g_debug: print "snapshot.py[311]: vehicle: " + str(v) + ", " + str(playerStat.vehicles[v].timeInObject) if v in IGNORED_VEHICLES: if g_debug: print "snapshot.py[313]: Ignoring vehicle " + str(v) continue vehicle = playerStat.vehicles[v] print str(vehicle) if vehicle.timeInObject > 0: if v in ARMOR_VEHICLE: keyName = "atp" if keyName in vehiclesSS: vehiclesSS["atp" + str(playerStat.playerId) ] += int(vehicle.timeInObject) else: vehiclesSS["atp" + str(playerStat.playerId) ] = int(vehicle.timeInObject) vehiclesSS["vdstry-" + str(v) ] = vehicle.destroyed vehiclesSS["vdths-" + str(v) ] = vehicle.killedBy vehiclesSS["vkls-" + str(v) ] = vehicle.kills vehiclesSS["vrkls-" + str(v) ] = vehicle.roadKills vehiclesSS["vtp-" + str(v) ] = int(vehicle.timeInObject) vehiclesSS["vbf-" + str(v) ] = vehicle.bulletsFired vehiclesSS["vbh-" + str(v) ] = vehicle.bulletsHit vehiclekeyvals = [] for v in vehiclesSS: vehiclekeyvals.append ("\\".join((v, str(vehiclesSS[v])))) vehicleSnapShot = "\\".join(vehiclekeyvals) # # kits kitKeys = [ ("kdths-0", playerStat.kits[KIT_TYPE_RECON].deaths ), #+ => deads as Recon ("kdths-1", playerStat.kits[KIT_TYPE_ASSAULT].deaths ), #+ => deads as Assault ("kdths-2", playerStat.kits[KIT_TYPE_ANTI_VEHICLE].deaths ), #+ => deads as Engineer ("kdths-3", playerStat.kits[KIT_TYPE_SUPPORT].deaths ), #+ => deads as Support ("kkls-0", playerStat.kits[KIT_TYPE_RECON].kills ), #+ => Kills As Recon ("kkls-1", playerStat.kits[KIT_TYPE_ASSAULT].kills ), #+ => Kills As Assault ("kkls-2", playerStat.kits[KIT_TYPE_ANTI_VEHICLE].kills ), #+ => Kills As Engineer ("kkls-3", playerStat.kits[KIT_TYPE_SUPPORT].kills ), #+ => Kills As Support ("ktt-0", int(playerStat.kits[KIT_TYPE_RECON].timeInObject) ), #+ => Time As Recon ("ktt-1", int(playerStat.kits[KIT_TYPE_ASSAULT].timeInObject) ), #+ => Time As Assault ("ktt-2", int(playerStat.kits[KIT_TYPE_ANTI_VEHICLE].timeInObject) ), #+ => Time As Engineer ("ktt-3", int(playerStat.kits[KIT_TYPE_SUPPORT].timeInObject) ), #+ => Time As Support ] kitkeyvals = [] for k in kitKeys: kitkeyvals.append ("\\".join((k[0], str(k[1])))) kitSnapShot = "\\".join(kitkeyvals) ############## weapons weaponsSS = {} for w in range(0, NUM_WEAPON_TYPES): if g_debug: print "snapshot.py[86]: weapon: " + str(w) + ", " + str(playerStat.weapons[w].timeInObject) if w >= IGNORED_WEAPON_INDEX: if g_debug: print "snapshot.py[88]: Ignoring weapon " + str(w) continue weapon = playerStat.weapons[w] if weapon.timeInObject > 0: weaponsSS["wdths-" + str(w) ] = weapon.killedBy weaponsSS["wkls-" + str(w) ] = weapon.kills weaponsSS["waccu-" + str(w) ] = "%.3g" % weapon.accuracy weaponsSS["wtp-" + str(w) ] = int(weapon.timeInObject) weaponsSS["wbf-" + str(v) ] = weapon.bulletsFired weaponsSS["wbh-" + str(v) ] = weapon.bulletsHit weaponkeyvals = [] for w in weaponsSS: weaponkeyvals.append ("\\".join((w, str(weaponsSS[w])))) weaponSnapShot = "\\".join(weaponkeyvals) allSnapShots = [] if len(playerSnapShot) > 0 : allSnapShots = allSnapShots + [playerSnapShot] if len(medalsSnapShot) > 0 : allSnapShots = allSnapShots + [medalsSnapShot] if len(vehicleSnapShot) > 0 : allSnapShots = allSnapShots + [vehicleSnapShot] if len(kitSnapShot) > 0 : allSnapShots = allSnapShots + [kitSnapShot] if len(weaponSnapShot) > 0 : allSnapShots = allSnapShots + [weaponSnapShot] playerSnapShot = "\\".join(allSnapShots) if g_debug: print "\n-------\n" + str(playerSnapShot) + "\n-------\n" # add pid to all keys (gamespy likes this) transformedSnapShot = "" i = 0 idString = "_" + str(playerStat.connectionOrderNr) while i < len(playerSnapShot): key = "" while playerSnapShot[i] != "\\": key += playerSnapShot[i] i += 1 i += 1 value = "" while i < len(playerSnapShot) and playerSnapShot[i] != "\\": value += playerSnapShot[i] i += 1 transformedKeyVal = key + idString + "\\" + value if i != len(playerSnapShot): transformedKeyVal += "\\" transformedSnapShot += transformedKeyVal i += 1 return "\\" + transformedSnapShot
def getPlayerSnapshot(playerStat): if g_debug: print "snapshot.py: playerStat.profileId" awayBonus = int(playerStat.localScore.awayBonusScoreIAR + playerStat.localScore.awayBonusScore) totalScore = (playerStat.score - playerStat.localScore.diffRankScore) + int(playerStat.localScore.experienceScoreIAR + playerStat.localScore.experienceScore) + int(awayBonus) playerKeys = [ ("ban", playerStat.timesBanned ), #+ => total bans na server ("c", playerStat.complete ), #? => Complete ("capa", playerStat.localScore.cpAssists ), #+ => Capture Assists ("cpt", playerStat.localScore.cpCaptures ), #+ => Captured CPs ("crpt", totalScore ), #+ => Career Points ("cs", playerStat.localScore.commanderBonusScore ), #+ => Commander Score ("dass", playerStat.localScore.driverAssists ), #+ => Driver Assists ("dcpt", playerStat.localScore.cpDefends ), #+ => Defended Control Points ("dstrk", playerStat.longestDeathStreak ), #> => Worst Death Streak ("dths", playerStat.deaths ), #+ => Deaths ("gsco", playerStat.score ), #+ => Global Score ("hls", playerStat.localScore.heals ), #+ => Heals ("kick", playerStat.timesKicked ), #+ => total kicks from servers ("klla", playerStat.localScore.damageAssists ), #+ => Kill Assists ("klls", playerStat.kills ), #+ => Kills ("klstrk", playerStat.longestKillStreak ), #> => Kills Streak ("kluav", playerStat.weapons[WEAPON_TYPE_RECON_DRONE].kills ), #+ => Kills With Gun Drone ("nick", playerStat.name ), #? => Nickname ("ncpt", playerStat.localScore.cpNeutralizes ), #+ => Neutralized CPs ("pdt", playerStat.dogTags ), #+ => Unique Dog Tags Collected ("pdtc", playerStat.dogtagCount ), #+ => Dog Tags Collected ("pid", playerStat.profileId ), #? => pID ("resp", playerStat.localScore.ammos ), #+ => Re-supplies ("rnk", playerStat.rank ), #> => Rank ("rnkcg", playerStat.roundRankup ), #? => RankUp? ("rps", playerStat.localScore.repairs ), #+ => Repairs ("rvs", playerStat.localScore.revives ), #+ => Revives ("slbspn", playerStat.squadLeaderBeaconSpawns ), #+ => Spawns On Squad Beacons ("sluav", playerStat.squadLeaderUAV ), #+ => Spawn Dron Deployed ("suic", playerStat.localScore.suicides ), #+ => Suicides ("tac", int(playerStat.timeAsCmd) ), #+ => Time As Commander ("talw", int(playerStat.timePlayed - playerStat.timeAsCmd - playerStat.timeInSquad) ), #+ => Time As Lone Wolf ("tas", playerStat.localScore.titanAttackKills ), #+ => Titan Attack Score ("tasl", int(playerStat.timeAsSql) ), #+ => Time As Squad Leader ("tasm", int(playerStat.timeInSquad - playerStat.timeAsSql) ), #+ => Time As Squad Member ("tcd", playerStat.localScore.titanPartsDestroyed ), #+ => Titan Components Destroyed ("tcrd", playerStat.localScore.titanCoreDestroyed ), #+ => Titan Cores Destroyed ("tdmg", playerStat.localScore.teamDamages ), #+ => Team Damage ("tdrps", playerStat.localScore.titanDrops ), #+ => Titan Drops ("tds", playerStat.localScore.titanDefendKills ), #+ => Titan Defend Score ("tgd", playerStat.localScore.titanWeaponsDestroyed ), #+ => Titan Guns Destroyed ("tgr", playerStat.localScore.titanWeaponsRepaired ), #+ => Titan Guns Repaired ("tkls", playerStat.teamkills ), #+ => Team Kills ("toth", playerStat.bulletsHit ), #+ => Total Hits ("tots", playerStat.bulletsFired ), #+ => Total Fired ("tt", int(playerStat.timePlayed) ), #+ => Time Played ("tvdmg", playerStat.localScore.teamVehicleDamages ), #+ => Team Vehicle Damage ("twsc", playerStat.teamScore ), #+ => Teamwork Score ("t", playerStat.team ), # => TeamID ] # victims / victimizers statsMap = getStatsMap() for p in playerStat.killedPlayer: if not p in statsMap: if g_debug: print "snapshot.py: killedplayer_id victim connorder: ", playerStat.killedPlayer[p], " wasnt in statsmap!" else: playerKeys.append(("mvns", str(statsMap[p].profileId))) playerKeys.append(("mvks", str(playerStat.killedPlayer[p]))) keyvals = [] for k in playerKeys: keyvals.append ("\\".join((k[0], str(k[1])))) playerSnapShot = "\\".join(keyvals) # medals medalsSnapShot = "" if playerStat.medals: medalsSnapShot = playerStat.medals.getSnapShot() ################ vehicles vehiclesSS = {} for v in range(0, NUM_VEHICLE_TYPES): if g_debug: print "snapshot.py[311]: vehicle: " + str(v) + ", " + str(playerStat.vehicles[v].timeInObject) if v in IGNORED_VEHICLES: if g_debug: print "snapshot.py[313]: Ignoring vehicle " + str(v) continue vehicle = playerStat.vehicles[v] print str(vehicle) if vehicle.timeInObject > 0: if v in ARMOR_VEHICLE: keyName = "atp" if keyName in vehiclesSS: vehiclesSS["atp" + str(playerStat.playerId) ] += int(vehicle.timeInObject) else: vehiclesSS["atp" + str(playerStat.playerId) ] = int(vehicle.timeInObject) vehiclesSS["vdstry-" + str(v) ] = vehicle.destroyed vehiclesSS["vdths-" + str(v) ] = vehicle.killedBy vehiclesSS["vkls-" + str(v) ] = vehicle.kills vehiclesSS["vrkls-" + str(v) ] = vehicle.roadKills vehiclesSS["vtp-" + str(v) ] = int(vehicle.timeInObject) vehiclesSS["vbf-" + str(v) ] = vehicle.bulletsFired vehiclesSS["vbh-" + str(v) ] = vehicle.bulletsHit vehiclekeyvals = [] for v in vehiclesSS: vehiclekeyvals.append ("\\".join((v, str(vehiclesSS[v])))) vehicleSnapShot = "\\".join(vehiclekeyvals) # # kits kitKeys = [ ("kdths-0", playerStat.kits[KIT_TYPE_RECON].deaths ), #+ => deads as Recon ("kdths-1", playerStat.kits[KIT_TYPE_ASSAULT].deaths ), #+ => deads as Assault ("kdths-2", playerStat.kits[KIT_TYPE_ANTI_VEHICLE].deaths ), #+ => deads as Engineer ("kdths-3", playerStat.kits[KIT_TYPE_SUPPORT].deaths ), #+ => deads as Support ("kkls-0", playerStat.kits[KIT_TYPE_RECON].kills ), #+ => Kills As Recon ("kkls-1", playerStat.kits[KIT_TYPE_ASSAULT].kills ), #+ => Kills As Assault ("kkls-2", playerStat.kits[KIT_TYPE_ANTI_VEHICLE].kills ), #+ => Kills As Engineer ("kkls-3", playerStat.kits[KIT_TYPE_SUPPORT].kills ), #+ => Kills As Support ("ktt-0", int(playerStat.kits[KIT_TYPE_RECON].timeInObject) ), #+ => Time As Recon ("ktt-1", int(playerStat.kits[KIT_TYPE_ASSAULT].timeInObject) ), #+ => Time As Assault ("ktt-2", int(playerStat.kits[KIT_TYPE_ANTI_VEHICLE].timeInObject) ), #+ => Time As Engineer ("ktt-3", int(playerStat.kits[KIT_TYPE_SUPPORT].timeInObject) ), #+ => Time As Support ] kitkeyvals = [] for k in kitKeys: kitkeyvals.append ("\\".join((k[0], str(k[1])))) kitSnapShot = "\\".join(kitkeyvals) ############## weapons weaponsSS = {} for w in range(0, NUM_WEAPON_TYPES): if g_debug: print "snapshot.py[86]: weapon: " + str(w) + ", " + str(playerStat.weapons[w].timeInObject) weapon = playerStat.weapons[w] if weapon.timeInObject > 0: weaponsSS["wdths-" + str(w) ] = weapon.killedBy weaponsSS["wkls-" + str(w) ] = weapon.kills weaponsSS["waccu-" + str(w) ] = "%.3g" % weapon.accuracy weaponsSS["wtp-" + str(w) ] = int(weapon.timeInObject) weaponsSS["wbf-" + str(w) ] = weapon.bulletsFired weaponsSS["wbh-" + str(w) ] = weapon.bulletsHit weaponkeyvals = [] for w in weaponsSS: weaponkeyvals.append ("\\".join((w, str(weaponsSS[w])))) weaponSnapShot = "\\".join(weaponkeyvals) allSnapShots = [] if len(playerSnapShot) > 0 : allSnapShots = allSnapShots + [playerSnapShot] if len(medalsSnapShot) > 0 : allSnapShots = allSnapShots + [medalsSnapShot] if len(vehicleSnapShot) > 0 : allSnapShots = allSnapShots + [vehicleSnapShot] if len(kitSnapShot) > 0 : allSnapShots = allSnapShots + [kitSnapShot] if len(weaponSnapShot) > 0 : allSnapShots = allSnapShots + [weaponSnapShot] playerSnapShot = "\\".join(allSnapShots) if g_debug: print "\n-------\n" + str(playerSnapShot) + "\n-------\n" # add pid to all keys (gamespy likes this) transformedSnapShot = "" i = 0 idString = "_" + str(playerStat.connectionOrderNr) while i < len(playerSnapShot): key = "" while playerSnapShot[i] != "\\": key += playerSnapShot[i] i += 1 i += 1 value = "" while i < len(playerSnapShot) and playerSnapShot[i] != "\\": value += playerSnapShot[i] i += 1 transformedKeyVal = key + idString + "\\" + value if i != len(playerSnapShot): transformedKeyVal += "\\" transformedSnapShot += transformedKeyVal i += 1 return "\\" + transformedSnapShot
def invoke(): if g_debug: print "endofround.py[20]: Invoked end-of-round data-send" # collect needed stats e = {} statsMap = getStatsMap() sortedPlayers = [] #ranked = host.ss_getParam('ranked') #if ranked: #e["r"] = ranked if g_debug: print "endofround.py[31]: EOR: statsMap length: " + str(len(statsMap)) # find top player in different categories for sp in statsMap.itervalues(): if sp.score > 0: sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp)] player = "_" + str(sp.name) if g_debug: print "endofround.py[39]: EOR: Found player" + player + " (" + str( sp.score) + ", " + str(sp.skillScore) + ", " + str( sp.teamScore) + ")" e["tt" + player] = int(sp.timePlayed) awayBonus = int(sp.localScore.awayBonusScoreIAR + sp.localScore.awayBonusScore) if awayBonus > 0: e["ab" + player] = awayBonus if sp.localScore.squadMemberBonusScore > 0: e["smb" + player] = int(sp.localScore.squadMemberBonusScore) if sp.localScore.squadLeaderBonusScore > 0: e["slb" + player] = int(sp.localScore.squadLeaderBonusScore) if sp.localScore.commanderBonusScore > 0: e["cb" + player] = int(sp.localScore.commanderBonusScore) if sp.roundRankup > 0: e["rr" + player] = 1 p = bf2.playerManager.getPlayerByIndex(sp.playerId) try: if p.getName() == sp.name: totalScore = (sp.score - sp.localScore.diffRankScore) + int( sp.localScore.experienceScoreIAR + sp.localScore.experienceScore) + int(awayBonus) #if ranked: if 'crpt' in p.medals.globalKeys: totalScore += int(p.medals.globalKeys['crpt']) if (sp.score - sp.localScore.diffRankScore) < 0: totalScore -= (sp.score - sp.localScore.diffRankScore) if g_debug: print "endofround.py[68]: Total player score: " + str( totalScore) e["gs" + player] = totalScore else: if g_debug: print "endofround.py[71]: Duplicate player id found: " + sp.name + ", found: " + p.getName( ) + " (" + str(sp.playerId) + ")" except: if g_debug: "No total score for player index: " + str(sp.playerId) for k in range(0, NUM_KIT_TYPES): if g_debug: print "endofround.py[77]: kit time: " + str(k) + ", " + str( sp.kits[k].timeInObject) kit = sp.kits[k] if kit.timeInObject > 0: e["ktw" + str(k) + player] = int(kit.timeInObject) e["ks" + str(k) + player] = kit.score for w in range(0, NUM_WEAPON_TYPES): if g_debug: print "endofround.py[86]: weapon: " + str(w) + ", " + str( sp.weapons[w].timeInObject) if w >= IGNORED_WEAPON_INDEX and not w in SPECIAL_WEAPONS: if g_debug: print "endofround.py[88]: Ignoring weapon " + str(w) continue weapon = sp.weapons[w] if weapon.timeInObject > 0: kills = weapon.kills accuracy = "%.3g" % weapon.accuracy timeWithWeapon = int(weapon.timeInObject) if w in SPECIAL_WEAPONS: w = SPECIAL_WEAPONS[w] keyName = "wk" + str(w) + player if keyName in e: kills += int(e[keyName]) accuracy = "%.3g" % ( (float(accuracy) + float(e["wa" + str(w) + player])) / 2.0) timeWithWeapon += int(e["wtw" + str(w) + player]) e["wk" + str(w) + player] = kills e["wa" + str(w) + player] = accuracy e["wtw" + str(w) + player] = timeWithWeapon for v in range(0, NUM_VEHICLE_TYPES): if g_debug: print "endofround.py[114]: vehicle: " + str(v) + ", " + str( sp.vehicles[v].timeInObject) if v in IGNORED_VEHICLES: if g_debug: print "endofround.py[116]: Ignoring vehicle " + str(v) continue vehicle = sp.vehicles[v] if vehicle.timeInObject > 0: timeInVehicle = int(vehicle.timeInObject) killsWithVehicle = vehicle.kills if v in SPECIAL_VEHICLE: v = SPECIAL_VEHICLE[v] keyName = "vtw" + str(v) + player if keyName in e: timeInVehicle += int(e[keyName]) killsWithVehicle += int(e["vtw" + str(v) + player]) e["vtw" + str(v) + player] = timeInVehicle e["vk" + str(v) + player] = killsWithVehicle if g_debug: print "\n-----------------\n%s\n---------------------\n" % e # stats for top-3 scoring players sortedPlayers.sort() sortedPlayers.reverse() if g_debug: for p in range(0, len(sortedPlayers)): print "endofround.py[144]: EOR: Sorted player " + str( p + 1) + ": n:" + sortedPlayers[p][1].name + ", s:" + str( sortedPlayers[p][1].score) for i in range(3): if len(sortedPlayers) <= i: break sp = sortedPlayers[i][1] e["tp" + str(i)] = sp.name keyvals = [] for k in e: keyvals.append("\\".join((k, str(e[k])))) dataString = "\\" + "\\".join(keyvals) if g_debug: print "endofround.py[160]: ", dataString host.gl_sendEndOfRoundData(dataString)
def getSnapShot(): print "Assembling snapshot" # Added by Chump - for bf2statistics stats #snapShot = "\\" #global PREFIX, map_start global map_start snapShot = snapshot_prefix + '\\' + bf2.gameLogic.getMapName() + '\\' snapShot += 'gameport\\' + str(bf2.serverSettings.getServerConfig('sv.serverPort')) + '\\' snapShot += 'queryport\\' + str(bf2.serverSettings.getServerConfig('sv.gameSpyPort')) + '\\' snapShot += 'mapstart\\' + str(map_start) + '\\mapend\\' + str(time()) + '\\' snapShot += 'win\\' + str(bf2.gameLogic.getWinner()) + '\\' statsMap = getStatsMap() # ---------------------------------------------------------------------------- # omero 2006-04-10 # ---------------------------------------------------------------------------- # this will be used for detecting which mod is running and # set standardKeys['v'] accordingly # defaults to 'bf2' # running_mod = str(host.sgl_getModDirectory()) if ( running_mod.lower() == 'mods/bf2' ): v_value = 'bf2' elif ( running_mod.lower() == 'mods/bf2sp64' ): v_value = 'bf2sp64' elif ( running_mod.lower() == 'mods/xpack' ): v_value = 'xpack' elif ( running_mod.lower() == 'mods/poe2' ): v_value = 'poe2' elif ( running_mod.lower() == 'mods/aix2' ): v_value = 'aix2' else: v_value = 'bf2' if g_debug: print 'Running MOD: %s' % (str(v_value)) standardKeys = [ # Added by Chump - for bf2statistics stats ("gm", getGameModeId(bf2.serverSettings.getGameMode())), ("m", getMapId(bf2.serverSettings.getMapName())), # Added by Chump - for bf2statistics stats ("v", str(v_value)), ("pc", len(statsMap)), ] # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] # get final ticket score if g_debug: print "Army 1 (%s) Score: %s" % (str(roundArmies[1]), str(bf2.gameLogic.getTickets(1))) if g_debug: print "Army 2 (%s) Score: %s" % (str(roundArmies[2]), str(bf2.gameLogic.getTickets(2))) standardKeys += [ ("ra1", str(roundArmies[1])), ("rs1", str(bf2.gameLogic.getTickets(1))), ("ra2", str(roundArmies[2])), ("rs2", str(bf2.gameLogic.getTickets(2))), ] standardKeys += [("rst2", str(bf2.gameLogic.getTickets(2)))] stdKeyVals = [] for k in standardKeys: stdKeyVals.append ("\\".join((k[0], str(k[1])))) snapShot += "\\".join(stdKeyVals) if g_debug: print 'Snapshot Pre-processing complete: %s' % (str(snapShot)) playerSnapShots = "" if g_debug: print 'Num clients to base snap on: %d' % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print 'Processing PID: %s' % (str(sp.profileId)) playerSnapShot = getPlayerSnapshot(sp) # Added by Chump - for bf2statistics stats playerSnapShots += playerSnapShot # remove zero vals #zeroAllowedKeys = ('pid', 'a', 'mvns', 'mvks', 'vmns', 'vmks') #transformedSnapShot = "" #i = 0 #while i < len(playerSnapShot): # i += 1 # key = "" # while playerSnapShot[i] != "\\": # key += playerSnapShot[i] # i += 1 # i += 1 # value = "" # while i < len(playerSnapShot) and playerSnapShot[i] != "\\": # value += playerSnapShot[i] # i += 1 # if value != "0" or key[:key.find('_')] in zeroAllowedKeys: # keyVal = "\\" + key + "\\" + value # transformedSnapShot += keyVal #if len(transformedSnapShot) > 0: # playerSnapShots += transformedSnapShot print "Doing Player SNAPSHOTS" snapShot += playerSnapShots # Add EOF marker for validation snapShot += "\\EOF\\1" return snapShot
def invoke(): if g_debug: print "Invoked end-of-round data-send" # collect needed stats e = {} statsMap = getStatsMap() # find top player in different categories for sp in statsMap.itervalues(): for k in range(0, NUM_KIT_TYPES + 1): if k in sp.kits and sp.kits[k].timeInObject > 0: findTop(e, "sk" + str(k), "skn" + str(k), sp.kits[k].score, sp.name) for v in range(0, NUM_VEHICLE_TYPES + 1): if v in sp.vehicles and sp.vehicles[v].timeInObject > 0: findTop(e, "sv" + str(v), "svn" + str(v), sp.vehicles[v].score, sp.name) findTop(e, "ts", "tsn", sp.teamScore, sp.name) findTop(e, "ss", "ssn", sp.skillScore, sp.name) findTop(e, "cpc", "cpcn", sp.localScore.cpCaptures, sp.name) findTop(e, "cpa", "cpan", sp.localScore.cpAssists, sp.name) findTop(e, "cpd", "cpdn", sp.localScore.cpDefends, sp.name) findTop( e, "ka", "kan", sp.localScore.damageAssists + sp.localScore.targetAssists + sp.localScore.passengerAssists, sp.name) findTop(e, "he", "hen", sp.localScore.heals, sp.name) findTop(e, "rev", "revn", sp.localScore.revives, sp.name) findTop(e, "rsp", "rspn", sp.localScore.ammos, sp.name) findTop(e, "rep", "repn", sp.localScore.repairs, sp.name) findTop(e, "drs", "drsn", sp.localScore.driverSpecials + sp.localScore.driverAssists, sp.name) # find top-3 if len(statsMap) > 0: sortedPlayers = [] for sp in statsMap.itervalues(): sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp)] sortedPlayers.sort() sortedPlayers.reverse() # stats for top-3 scoring players for i in range(3): if len(sortedPlayers) <= i: break sp = sortedPlayers[i][1] e["np" + str(i)] = sp.name e["tsp" + str(i)] = sp.teamScore e["ssp" + str(i)] = sp.skillScore e["csp" + str(i)] = sp.cmdScore e["bfp" + str(i)] = sp.bulletsFired e["bhp" + str(i)] = sp.bulletsHit for k in range(0, NUM_KIT_TYPES + 1): if sp.kits[k].timeInObject > 0: e["tk" + str(k) + "p" + str(i)] = int( sp.kits[k].timeInObject) for v in range(0, NUM_VEHICLE_TYPES + 1): if sp.vehicles[v].timeInObject > 0: e["tv" + str(v) + "p" + str(i)] = int( sp.vehicles[v].timeInObject) keyvals = [] for k in e: keyvals.append("\\".join((k, str(e[k])))) dataString = "\\" + "\\".join(keyvals) if g_debug: print dataString host.gl_sendEndOfRoundData(dataString)
def getPlayerSnapshot(playerStat): # The player didn't spawn in... if playerStat.timePlayed == 0: return "" playerKeys = [ # main keys ("pID", playerStat.profileId), ("name", playerStat.name), ("t", playerStat.team), ("a", playerStat.army), ("ctime", int(playerStat.timePlayed)), ("c", playerStat.complete), ("ip", playerStat.ipaddr), ("ai", playerStat.isAIPlayer), # score keys ("rs", playerStat.score), ("cs", playerStat.cmdScore), #("ss", playerStat.skillScore), // Processed in Backend ("ts", playerStat.teamScore), ("kills", playerStat.kills), ("deaths", playerStat.deaths), ("cpc", playerStat.localScore.cpCaptures + playerStat.localScore.cpNeutralizes), ("cpa", playerStat.localScore.cpAssists + playerStat.localScore.cpNeutralizeAssists), #("cpc", playerStat.localScore.cpCaptures), // Processed in backend #("cpn", playerStat.localScore.cpNeutralizes), // Processed in backend #("cpa", playerStat.localScore.cpAssists), // Processed in backend #("cpna", playerStat.localScore.cpNeutralizeAssists), // Processed in backend ("cpd", playerStat.localScore.cpDefends), ("ka", playerStat.localScore.damageAssists), ("he", playerStat.localScore.heals), ("rev", playerStat.localScore.revives), ("rsp", playerStat.localScore.ammos), ("rep", playerStat.localScore.repairs), ("tre", playerStat.localScore.targetAssists), ("drs", playerStat.localScore.driverSpecials + playerStat.localScore.driverAssists), #("drs", playerStat.localScore.driverSpecials), // Processed in backend #("dra", playerStat.localScore.driverAssists), // Processed in backend #("pa", playerStat.localScore.passengerAssists), // Processed in backend # Additional player stats ("tmkl", playerStat.teamkills), ("tmdg", playerStat.localScore.teamDamages), ("tmvd", playerStat.localScore.teamVehicleDamages), ("su", playerStat.localScore.suicides), ("ks", playerStat.longestKillStreak), ("ds", playerStat.longestDeathStreak), ("rank", playerStat.rank), ("ban", playerStat.timesBanned), ("kck", playerStat.timesKicked), # time keys ("tco", int(playerStat.timeAsCmd)), ("tsl", int(playerStat.timeAsSql)), ("tsm", int(playerStat.timeInSquad - playerStat.timeAsSql)), ("tlw", int(playerStat.timePlayed - playerStat.timeAsCmd - playerStat.timeInSquad)), # Base Game Stuff ("ta0", int(playerStat.timeAsArmy[ARMY_USA])), ("ta1", int(playerStat.timeAsArmy[ARMY_MEC])), ("ta2", int(playerStat.timeAsArmy[ARMY_CHINESE])), #XPack1 Stuff ("ta3", int(playerStat.timeAsArmy[ARMY_SEALS])), ("ta4", int(playerStat.timeAsArmy[ARMY_SAS])), ("ta5", int(playerStat.timeAsArmy[ARMY_SPETZNAS])), ("ta6", int(playerStat.timeAsArmy[ARMY_MECSF])), ("ta7", int(playerStat.timeAsArmy[ARMY_REBELS])), ("ta8", int(playerStat.timeAsArmy[ARMY_INSURGENTS])), #EF Booster Pack Stuff ("ta9", int(playerStat.timeAsArmy[ARMY_EURO])), #POE2 Stuff ("ta10", int(playerStat.timeAsArmy[ARMY_GER])), ("ta11", int(playerStat.timeAsArmy[ARMY_UKR])), #AIX ("ta12", int(playerStat.timeAsArmy[ARMY_UN])), #CANADIAN FORCES ("ta13", int(playerStat.timeAsArmy[ARMY_CANADIAN])), ] # victims / victimizers statsMap = getStatsMap() for p in playerStat.killedPlayer: if not p in statsMap: if g_debug: print "killedplayer_id victim connorder: ", playerStat.killedPlayer[p], " wasnt in statsmap!" else: playerKeys.append(("mvns", str(statsMap[p].profileId))) playerKeys.append(("mvks", str(playerStat.killedPlayer[p]))) # Added by Chump - for bf2statistics stats #for p in playerStat.killedByPlayer: # if not p in statsMap: # if g_debug: print "killedBYplayer_id victim connorder: ", playerStat.killedByPlayer[p], " wasnt in statsmap!" # else: # playerKeys.append(("vmns", str(statsMap[p].profileId))) # playerKeys.append(("vmks", str(playerStat.killedByPlayer[p]))) keyvals = [] for k in playerKeys: keyvals.append ("\\".join((k[0], str(k[1])))) playerSnapShot = "\\".join(keyvals) # medals medalsSnapShot = "" if playerStat.medals: if g_debug: print "Medals Found (%s), Processing Medals Snapshot" % (playerStat.profileId) medalsSnapShot = playerStat.medals.getSnapShot() # vehicles vehicleKeys = [ ("tv0", int(playerStat.vehicles[VEHICLE_TYPE_ARMOR].timeInObject)), ("tv1", int(playerStat.vehicles[VEHICLE_TYPE_AVIATOR].timeInObject)), ("tv2", int(playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].timeInObject)), ("tv3", int(playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].timeInObject)), ("tv4", int(playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].timeInObject)), ("tv5", int(playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].timeInObject)), ("tv6", int(playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].timeInObject)), ("tvp", int(playerStat.vehicles[VEHICLE_TYPE_PARACHUTE].timeInObject)), # Added by Chump - these do not register with onEnterVehicle() # XPack1 Stuff #("tnv", int(playerStat.vehicles[VEHICLE_TYPE_NIGHTVISION].timeInObject)), #("tgm", int(playerStat.vehicles[VEHICLE_TYPE_GASMASK].timeInObject)), ("kv0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].kills), ("kv1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].kills), ("kv2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].kills), ("kv3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].kills), ("kv4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].kills), ("kv5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].kills), ("kv6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].kills), ("bv0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].deaths), ("bv1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].deaths), ("bv2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].deaths), ("bv3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].deaths), ("bv4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].deaths), ("bv5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].deaths), ("bv6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].deaths), ("kvr0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].roadKills), ("kvr1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].roadKills), ("kvr2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].roadKills), ("kvr3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].roadKills), ("kvr4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].roadKills), ("kvr5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].roadKills), ("kvr6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].roadKills), ] vehkeyvals = [] for k in vehicleKeys: #if k[1] == 0: continue vehkeyvals.append ("\\".join((k[0], str(k[1])))) vehicleSnapShot = "\\".join(vehkeyvals) # kits kitKeys = [ ("tk0", int(playerStat.kits[KIT_TYPE_AT].timeInObject)), ("tk1", int(playerStat.kits[KIT_TYPE_ASSAULT].timeInObject)), ("tk2", int(playerStat.kits[KIT_TYPE_ENGINEER].timeInObject)), ("tk3", int(playerStat.kits[KIT_TYPE_MEDIC].timeInObject)), ("tk4", int(playerStat.kits[KIT_TYPE_SPECOPS].timeInObject)), ("tk5", int(playerStat.kits[KIT_TYPE_SUPPORT].timeInObject)), ("tk6", int(playerStat.kits[KIT_TYPE_SNIPER].timeInObject)), ("kk0", playerStat.kits[KIT_TYPE_AT].kills), ("kk1", playerStat.kits[KIT_TYPE_ASSAULT].kills), ("kk2", playerStat.kits[KIT_TYPE_ENGINEER].kills), ("kk3", playerStat.kits[KIT_TYPE_MEDIC].kills), ("kk4", playerStat.kits[KIT_TYPE_SPECOPS].kills), ("kk5", playerStat.kits[KIT_TYPE_SUPPORT].kills), ("kk6", playerStat.kits[KIT_TYPE_SNIPER].kills), ("dk0", playerStat.kits[KIT_TYPE_AT].deaths), ("dk1", playerStat.kits[KIT_TYPE_ASSAULT].deaths), ("dk2", playerStat.kits[KIT_TYPE_ENGINEER].deaths), ("dk3", playerStat.kits[KIT_TYPE_MEDIC].deaths), ("dk4", playerStat.kits[KIT_TYPE_SPECOPS].deaths), ("dk5", playerStat.kits[KIT_TYPE_SUPPORT].deaths), ("dk6", playerStat.kits[KIT_TYPE_SNIPER].deaths), ] kitkeyvals = [] for k in kitKeys: kitkeyvals.append ("\\".join((k[0], str(k[1])))) kitSnapShot = "\\".join(kitkeyvals) # weapons weaponKeys = [ ("tw0", int(playerStat.weapons[WEAPON_TYPE_ASSAULT].timeInObject)), ("tw1", int(playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].timeInObject)), ("tw2", int(playerStat.weapons[WEAPON_TYPE_CARBINE].timeInObject)), ("tw3", int(playerStat.weapons[WEAPON_TYPE_LMG].timeInObject)), ("tw4", int(playerStat.weapons[WEAPON_TYPE_SNIPER].timeInObject)), ("tw5", int(playerStat.weapons[WEAPON_TYPE_PISTOL].timeInObject)), ("tw6", int(playerStat.weapons[WEAPON_TYPE_ATAA].timeInObject)), ("tw7", int(playerStat.weapons[WEAPON_TYPE_SMG].timeInObject)), ("tw8", int(playerStat.weapons[WEAPON_TYPE_SHOTGUN].timeInObject)), ("te0", int(playerStat.weapons[WEAPON_TYPE_KNIFE].timeInObject)), ("te1", int(playerStat.weapons[WEAPON_TYPE_C4].timeInObject)), ("te3", int(playerStat.weapons[WEAPON_TYPE_HANDGRENADE].timeInObject)), ("te2", int(playerStat.weapons[WEAPON_TYPE_CLAYMORE].timeInObject)), ("te4", int(playerStat.weapons[WEAPON_TYPE_SHOCKPAD].timeInObject)), ("te5", int(playerStat.weapons[WEAPON_TYPE_ATMINE].timeInObject)), # XPack1 Stuff ("te6", int(playerStat.weapons[WEAPON_TYPE_TACTICAL].timeInObject)), ("te7", int(playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].timeInObject)), ("te8", int(playerStat.weapons[WEAPON_TYPE_ZIPLINE].timeInObject)), ("kw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].kills), ("kw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].kills), ("kw2", playerStat.weapons[WEAPON_TYPE_CARBINE].kills), ("kw3", playerStat.weapons[WEAPON_TYPE_LMG].kills), ("kw4", playerStat.weapons[WEAPON_TYPE_SNIPER].kills), ("kw5", playerStat.weapons[WEAPON_TYPE_PISTOL].kills), ("kw6", playerStat.weapons[WEAPON_TYPE_ATAA].kills), ("kw7", playerStat.weapons[WEAPON_TYPE_SMG].kills), ("kw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].kills), ("ke0", playerStat.weapons[WEAPON_TYPE_KNIFE].kills), ("ke1", playerStat.weapons[WEAPON_TYPE_C4].kills), ("ke3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].kills), ("ke2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].kills), ("ke4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].kills), ("ke5", playerStat.weapons[WEAPON_TYPE_ATMINE].kills), ("bw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].deaths), ("bw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].deaths), ("bw2", playerStat.weapons[WEAPON_TYPE_CARBINE].deaths), ("bw3", playerStat.weapons[WEAPON_TYPE_LMG].deaths), ("bw4", playerStat.weapons[WEAPON_TYPE_SNIPER].deaths), ("bw5", playerStat.weapons[WEAPON_TYPE_PISTOL].deaths), ("bw6", playerStat.weapons[WEAPON_TYPE_ATAA].deaths), ("bw7", playerStat.weapons[WEAPON_TYPE_SMG].deaths), ("bw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].deaths), ("be0", playerStat.weapons[WEAPON_TYPE_KNIFE].deaths), ("be1", playerStat.weapons[WEAPON_TYPE_C4].deaths), ("be3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].deaths), ("be2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].deaths), ("be4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].deaths), ("be5", playerStat.weapons[WEAPON_TYPE_ATMINE].deaths), # XPack1 Stuff ("be8", playerStat.weapons[WEAPON_TYPE_ZIPLINE].deaths), ("be9", playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].deaths), # XPack1 Stuff ("de6", playerStat.weapons[WEAPON_TYPE_TACTICAL].deployed), ("de7", playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].deployed), ("de8", playerStat.weapons[WEAPON_TYPE_ZIPLINE].deployed), ("sw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].bulletsFired), ("sw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].bulletsFired), ("sw2", playerStat.weapons[WEAPON_TYPE_CARBINE].bulletsFired), ("sw3", playerStat.weapons[WEAPON_TYPE_LMG].bulletsFired), ("sw4", playerStat.weapons[WEAPON_TYPE_SNIPER].bulletsFired), ("sw5", playerStat.weapons[WEAPON_TYPE_PISTOL].bulletsFired), ("sw6", playerStat.weapons[WEAPON_TYPE_ATAA].bulletsFired), ("sw7", playerStat.weapons[WEAPON_TYPE_SMG].bulletsFired), ("sw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].bulletsFired), ("se0", playerStat.weapons[WEAPON_TYPE_KNIFE].bulletsFired), ("se1", playerStat.weapons[WEAPON_TYPE_C4].bulletsFired), ("se2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].bulletsFired), ("se3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].bulletsFired), ("se4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].bulletsFired), ("se5", playerStat.weapons[WEAPON_TYPE_ATMINE].bulletsFired), ("hw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].bulletsHit), ("hw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].bulletsHit), ("hw2", playerStat.weapons[WEAPON_TYPE_CARBINE].bulletsHit), ("hw3", playerStat.weapons[WEAPON_TYPE_LMG].bulletsHit), ("hw4", playerStat.weapons[WEAPON_TYPE_SNIPER].bulletsHit), ("hw5", playerStat.weapons[WEAPON_TYPE_PISTOL].bulletsHit), ("hw6", playerStat.weapons[WEAPON_TYPE_ATAA].bulletsHit), ("hw7", playerStat.weapons[WEAPON_TYPE_SMG].bulletsHit), ("hw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].bulletsHit), ("he0", playerStat.weapons[WEAPON_TYPE_KNIFE].bulletsHit), ("he1", playerStat.weapons[WEAPON_TYPE_C4].bulletsHit), ("he2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].bulletsHit), ("he3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].bulletsHit), ("he4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].bulletsHit), ("he5", playerStat.weapons[WEAPON_TYPE_ATMINE].bulletsHit), ] weapkeyvals = [] for k in weaponKeys: weapkeyvals.append ("\\".join((k[0], str(k[1])))) weaponSnapShot = "\\".join(weapkeyvals) allSnapShots = [] if len(playerSnapShot) > 0: allSnapShots = allSnapShots + [playerSnapShot] if len(medalsSnapShot) > 0: allSnapShots = allSnapShots + [medalsSnapShot] if len(vehicleSnapShot) > 0: allSnapShots = allSnapShots + [vehicleSnapShot] if len(kitSnapShot) > 0: allSnapShots = allSnapShots + [kitSnapShot] if len(weaponSnapShot) > 0: allSnapShots = allSnapShots + [weaponSnapShot] playerSnapShot = "\\".join(allSnapShots) # add pid to all keys (gamespy likes this) transformedSnapShot = "" i = 0 idString = "_" + str(playerStat.connectionOrderNr) while i < len(playerSnapShot): key = "" while playerSnapShot[i] != "\\": key += playerSnapShot[i] i += 1 i += 1 value = "" while i < len(playerSnapShot) and playerSnapShot[i] != "\\": value += playerSnapShot[i] i += 1 transformedKeyVal = key + idString + "\\" + value if i != len(playerSnapShot): transformedKeyVal += "\\" transformedSnapShot += transformedKeyVal i += 1 return "\\" + transformedSnapShot
def invoke(): if g_debug: print "endofround.py[20]: Invoked end-of-round data-send" # collect needed stats e = {} statsMap = getStatsMap() sortedPlayers = [] #ranked = host.ss_getParam('ranked') #if ranked: #e["r"] = ranked if g_debug: print "endofround.py[31]: EOR: statsMap length: " + str( len(statsMap) ) # find top player in different categories for sp in statsMap.itervalues(): if sp.score > 0: sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp)] player = "_" + str(sp.name) if g_debug: print "endofround.py[39]: EOR: Found player" + player + " (" + str(sp.score) + ", " + str(sp.skillScore) + ", " + str(sp.teamScore) + ")" e["tt" + player] = int(sp.timePlayed) awayBonus = int(sp.localScore.awayBonusScoreIAR + sp.localScore.awayBonusScore) if awayBonus > 0: e["ab" + player] = awayBonus if sp.localScore.squadMemberBonusScore > 0: e["smb" + player] = int(sp.localScore.squadMemberBonusScore) if sp.localScore.squadLeaderBonusScore > 0: e["slb" + player] = int(sp.localScore.squadLeaderBonusScore) if sp.localScore.commanderBonusScore > 0: e["cb" + player] = int(sp.localScore.commanderBonusScore) if sp.roundRankup > 0: e["rr" + player] = 1 p = bf2.playerManager.getPlayerByIndex(sp.playerId) try: if p.getName() == sp.name: totalScore = (sp.score - sp.localScore.diffRankScore) + int(sp.localScore.experienceScoreIAR + sp.localScore.experienceScore) + int(awayBonus) #if ranked: if 'crpt' in p.medals.globalKeys: totalScore += int(p.medals.globalKeys['crpt']) if (sp.score - sp.localScore.diffRankScore) < 0: totalScore -= (sp.score - sp.localScore.diffRankScore) if g_debug: print "endofround.py[68]: Total player score: " + str(totalScore) e["gs" + player] = totalScore else: if g_debug: print "endofround.py[71]: Duplicate player id found: " + sp.name + ", found: " + p.getName() + " (" + str(sp.playerId) + ")" except: if g_debug: "No total score for player index: " + str(sp.playerId) for k in range(0, NUM_KIT_TYPES): if g_debug: print "endofround.py[77]: kit time: " + str(k) + ", " + str(sp.kits[k].timeInObject) kit = sp.kits[k] if kit.timeInObject > 0: e["ktw" + str(k) + player ] = int(kit.timeInObject) e["ks" + str(k) + player ] = kit.score for w in range(0, NUM_WEAPON_TYPES): if g_debug: print "endofround.py[86]: weapon: " + str(w) + ", " + str(sp.weapons[w].timeInObject) weapon = sp.weapons[w] if weapon.timeInObject > 0: kills = weapon.kills accuracy = "%.3g" % weapon.accuracy timeWithWeapon = int(weapon.timeInObject) if w in SPECIAL_WEAPONS: w = SPECIAL_WEAPONS[ w ] keyName = "wk" + str(w) + player if keyName in e: kills += int(e[ keyName ]) accuracy = "%.3g" % ( ( float(accuracy) + float( e[ "wa" + str(w) + player ]) ) / 2.0 ) timeWithWeapon += int( e["wtw" + str(w) + player ] ) e["wk" + str(w) + player ] = kills e["wa" + str(w) + player ] = accuracy e["wtw" + str(w) + player ] = timeWithWeapon for v in range(0, NUM_VEHICLE_TYPES): if g_debug: print "endofround.py[114]: vehicle: " + str(v) + ", " + str(sp.vehicles[v].timeInObject) if v in IGNORED_VEHICLES: if g_debug: print "endofround.py[116]: Ignoring vehicle " + str(v) continue vehicle = sp.vehicles[v] if vehicle.timeInObject > 0: timeInVehicle = int(vehicle.timeInObject) killsWithVehicle = vehicle.kills if v in SPECIAL_VEHICLE: v = SPECIAL_VEHICLE[ v ] keyName = "vtw" + str(v) + player if keyName in e: timeInVehicle += int(e[ keyName ]) killsWithVehicle += int(e["vtw" + str(v) + player ]) e["vtw" + str(v) + player ] = timeInVehicle e["vk" + str(v) + player ] = killsWithVehicle if g_debug: print "\n-----------------\n%s\n---------------------\n" %e # stats for top-3 scoring players sortedPlayers.sort() sortedPlayers.reverse() if g_debug: for p in range(0, len(sortedPlayers)): print "endofround.py[144]: EOR: Sorted player " + str(p+1) + ": n:" + sortedPlayers[p][1].name + ", s:" + str(sortedPlayers[p][1].score) for i in range(3): if len(sortedPlayers) <= i: break sp = sortedPlayers[i][1] e["tp" + str(i)] = sp.name keyvals = [] for k in e: keyvals.append ("\\".join((k, str(e[k])))) dataString = "\\" + "\\".join(keyvals) if g_debug: print "endofround.py[160]: ", dataString host.gl_sendEndOfRoundData(dataString)
def getSnapShot(): print "Assembling snapshot" global map_start statsMap = getStatsMap() # ---------------------------------------------------------------------------- # Wilson212 2016-06-24 # ---------------------------------------------------------------------------- # Changed standardKeys['v'] from mod, to python version! # standardKeys['m'] is now for mod name # running_mod = str(host.sgl_getModDirectory()) running_mod = running_mod.lower().replace("mods/", "") if g_debug: print 'Running MOD: %s' % running_mod standardKeys = [ ("authId", str(stats_auth_id)), ("authToken", str(stats_auth_token)), ("serverName", str(bf2.serverSettings.getServerConfig('sv.serverName'))), ("gamePort", str(bf2.serverSettings.getServerConfig('sv.serverPort'))), ("queryPort", str(bf2.serverSettings.getServerConfig('sv.gameSpyPort'))), ("mapId", str(getMapId(bf2.serverSettings.getMapName()))), ("mapName", str(bf2.gameLogic.getMapName())), ("mapStart", str(map_start)), ("mapEnd", str(time())), ("winner", str(bf2.gameLogic.getWinner())), ("gameMode", str(getGameModeId(bf2.serverSettings.getGameMode()))), ("mod", str(running_mod)), ("version", "3.0"), ("pc", len(statsMap)), ] if g_debug: print 'Finished Pre-Compile SNAPSHOT' # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] # get final ticket score if g_debug: print "Army 1 (%s) Score: %s" % (str(roundArmies[1]), str(bf2.gameLogic.getTickets(1))) if g_debug: print "Army 2 (%s) Score: %s" % (str(roundArmies[2]), str(bf2.gameLogic.getTickets(2))) standardKeys += [ ("ra1", str(roundArmies[1])), ("rs1", str(bf2.gameLogic.getTickets(1))), ("ra2", str(roundArmies[2])), ("rs2", str(bf2.gameLogic.getTickets(2))), ] standardKeys += [("rst2", str(bf2.gameLogic.getTickets(2)))] stdKeyVals = [] for k in standardKeys: stdKeyVals.append (":".join(( '"' + str(k[0]) + '"', '"' + str(k[1]) + '"'))) snapShot = "{" snapShot += ",".join(stdKeyVals) if g_debug: print 'Snapshot Pre-processing complete: %s' % (str(snapShot)) playerSnapShots = [] if g_debug: print 'Num clients to base snap on: %d' % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print 'Processing PID: %s' % (str(sp.profileId)) playerSnap = getPlayerSnapshot(sp) if len(playerSnap) > 0: playerSnapShots.append (playerSnap) print "Doing Player SNAPSHOTS" snapShot += ',"players":[' + ",".join(playerSnapShots) + ']' # Add EOF marker for validation snapShot += "}" return snapShot
def getPlayerSnapshot(playerStat): # The player didn't spawn in... if playerStat.timePlayed == 0: return "" playerKeys = [ # main keys ("pID", playerStat.profileId), ("name", playerStat.name), ("t", playerStat.team), ("a", playerStat.army), ("ctime", int(playerStat.timePlayed)), ("c", playerStat.complete), ("ip", playerStat.ipaddr), ("ai", playerStat.isAIPlayer), # score keys ("rs", playerStat.score), ("cs", playerStat.cmdScore), ("ss", playerStat.skillScore), ("ts", playerStat.teamScore), ("kills", playerStat.kills), ("deaths", playerStat.deaths), ("cpc", playerStat.localScore.cpCaptures), ("cpn", playerStat.localScore.cpNeutralizes), ("cpa", playerStat.localScore.cpAssists), ("cpna", playerStat.localScore.cpNeutralizeAssists), ("cpd", playerStat.localScore.cpDefends), ("ka", playerStat.localScore.damageAssists), ("he", playerStat.localScore.heals), ("rev", playerStat.localScore.revives), ("rsp", playerStat.localScore.ammos), ("rep", playerStat.localScore.repairs), ("tre", playerStat.localScore.targetAssists), ("drs", playerStat.localScore.driverSpecials + playerStat.localScore.driverAssists), #("drs", playerStat.localScore.driverSpecials), // Processed in backend #("dra", playerStat.localScore.driverAssists), // Processed in backend #("pa", playerStat.localScore.passengerAssists), // Processed in backend # Additional player stats ("tmkl", playerStat.teamkills), ("tmdg", playerStat.localScore.teamDamages), ("tmvd", playerStat.localScore.teamVehicleDamages), ("su", playerStat.localScore.suicides), ("ks", playerStat.longestKillStreak), ("ds", playerStat.longestDeathStreak), ("rank", playerStat.rank), ("ban", playerStat.timesBanned), ("kck", playerStat.timesKicked), # time keys ("tco", int(playerStat.timeAsCmd)), ("tsl", int(playerStat.timeAsSql)), ("tsm", int(playerStat.timeInSquad - playerStat.timeAsSql)), ("tlw", int(playerStat.timePlayed - playerStat.timeAsCmd - playerStat.timeInSquad)), ("tvp", str(int(playerStat.vehicles[VEHICLE_TYPE_PARACHUTE].timeInObject)) ) ] # Combine current keys into player snapshot keyvals = [] for k in playerKeys: keyvals.append (":".join(( '"' + str(k[0]) + '"', '"' + str(k[1]) + '"'))) playerSnapShot = ",".join(keyvals) # army time keyvals = [] for index in range(NUM_ARMIES): aTime = int(playerStat.timeAsArmy[index]) if aTime > 0: keyvals.append ('{"id":' + str(index) + ',"time":' + str(aTime) + '}') armySnapShot = '"armyData":[' + ",".join(keyvals) + ']' # victims keyvals = [] statsMap = getStatsMap() for p in playerStat.killedPlayer: if not p in statsMap: if g_debug: print "killedplayer_id victim connorder: ", playerStat.killedPlayer[p], " wasnt in statsmap!" else: keyvals.append ('{"id":' + str(statsMap[p].profileId) + ',"count":' + str(playerStat.killedPlayer[p]) + '}') victimSnapShot = '"victims":[' +",".join(keyvals) + ']' # medals medalsSnapShot = '"awards":[' if playerStat.medals: if g_debug: print "Medals Found (%s), Processing Medals Snapshot" % (playerStat.profileId) medalsSnapShot += playerStat.medals.getSnapShot() medalsSnapShot = medalsSnapShot + ']' # vehicles - Backend does not care about VEHICLE_TYPE_[SOLDIER, NIGHTVISION, or GASMASK] # NOTE: VEHICLE_TYPE_NIGHTVISION and VEHICLE_TYPE_GASMASK do not register with onEnterVehicle() vehkeyvals = [] for i in range(7): index = str(i) v = playerStat.vehicles[i] vTime = int(v.timeInObject) if vTime > 0: keyvals = [] keyvals.append ('"id":' + str(i)) keyvals.append ('"time":' + str(vTime)) keyvals.append ('"kills":' + str(v.kills)) keyvals.append ('"deaths":' + str(v.deaths)) keyvals.append ('"roadkills":' + str(v.roadKills)) vehkeyvals.append ('{' + ",".join(keyvals) + '}') vehicleSnapShot = '"vehicleData":[' + ",".join(vehkeyvals) + ']' # kits kitkeyvals = [] for i in range(NUM_KIT_TYPES): index = str(i) k = playerStat.kits[i] kTime = int(k.timeInObject) if kTime > 0: keyvals = [] keyvals.append ('"id":' + str(i)) keyvals.append ('"time":' + str(kTime)) keyvals.append ('"kills":' + str(k.kills)) keyvals.append ('"deaths":' + str(k.deaths)) kitkeyvals.append ('{' + ",".join(keyvals) + '}') kitSnapShot = '"kitData":[' + ",".join(kitkeyvals) + ']' # weapons # NOTE Backend does not care about WEAPON_TYPE_TARGETING, so skip it! i = 0 weapkeyvals = [] for j in range(NUM_WEAPON_TYPES): # Skip targetting if (j == WEAPON_TYPE_TARGETING): continue index = str(i) w = playerStat.weapons[i] wTime = int(w.timeInObject) if wTime > 0: keyvals = [] keyvals.append ('"id":' + str(i)) keyvals.append ('"time":' + str(wTime)) keyvals.append ('"kills":' + str(w.kills)) keyvals.append ('"deaths":' + str(w.deaths)) keyvals.append ('"fired":' + str(w.bulletsFired)) keyvals.append ('"hits":' + str(w.bulletsHit)) keyvals.append ('"deployed":' + str(w.deployed)) weapkeyvals.append ('{' + ",".join(keyvals) + '}') i += 1 weaponSnapShot = '"weaponData":[' + ",".join(weapkeyvals) + ']' allSnapShots = [playerSnapShot, armySnapShot, kitSnapShot, vehicleSnapShot, weaponSnapShot, victimSnapShot, medalsSnapShot] playerSnapShot = ",".join(allSnapShots) return "{" + playerSnapShot + "}"
def getSnapShot(): print "Assembling snapshot" global map_start snapShot = snapshot_prefix + '\\' + str(bf2.serverSettings.getServerConfig('sv.serverName')) + '\\' snapShot += 'gameport\\' + str(bf2.serverSettings.getServerConfig('sv.serverPort')) + '\\' snapShot += 'queryport\\' + str(bf2.serverSettings.getServerConfig('sv.gameSpyPort')) + '\\' snapShot += 'mapname\\' + str(bf2.gameLogic.getMapName()) + '\\' snapShot += 'mapid\\' + str(getMapId(bf2.serverSettings.getMapName())) + '\\' snapShot += 'mapstart\\' + str(map_start) + '\\mapend\\' + str(time()) + '\\' snapShot += 'win\\' + str(bf2.gameLogic.getWinner()) + '\\' if g_debug: print 'Finished Pre-Compile SNAPSHOT' statsMap = getStatsMap() # ---------------------------------------------------------------------------- # omero 2006-04-10 # ---------------------------------------------------------------------------- # this will be used for detecting which mod is running and # set standardKeys['v'] accordingly # defaults to 'bf2' # running_mod = str(host.sgl_getModDirectory()) if ( running_mod.lower() == 'mods/bf2' ): v_value = 'bf2' elif ( running_mod.lower() == 'mods/bf2sp64' ): v_value = 'bf2sp64' elif ( running_mod.lower() == 'mods/xpack' ): v_value = 'xpack' elif ( running_mod.lower() == 'mods/poe2' ): v_value = 'poe2' elif ( running_mod.lower() == 'mods/aix2' ): v_value = 'aix2' else: v_value = 'bf2' if g_debug: print 'Running MOD: %s' % (str(v_value)) standardKeys = [ ("gm", getGameModeId(bf2.serverSettings.getGameMode())), ("m", getMapId(bf2.serverSettings.getMapName())), ("v", str(v_value)), ("pc", len(statsMap)), ] # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] # get final ticket score if g_debug: print "Army 1 (%s) Score: %s" % (str(roundArmies[1]), str(bf2.gameLogic.getTickets(1))) if g_debug: print "Army 2 (%s) Score: %s" % (str(roundArmies[2]), str(bf2.gameLogic.getTickets(2))) standardKeys += [ ("ra1", str(roundArmies[1])), ("rs1", str(bf2.gameLogic.getTickets(1))), ("ra2", str(roundArmies[2])), ("rs2", str(bf2.gameLogic.getTickets(2))), ] standardKeys += [("rst2", str(bf2.gameLogic.getTickets(2)))] stdKeyVals = [] for k in standardKeys: stdKeyVals.append ("\\".join((k[0], str(k[1])))) snapShot += "\\".join(stdKeyVals) if g_debug: print 'Snapshot Pre-processing complete: %s' % (str(snapShot)) playerSnapShots = "" if g_debug: print 'Num clients to base snap on: %d' % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print 'Processing PID: %s' % (str(sp.profileId)) playerSnapShots += getPlayerSnapshot(sp) print "Doing Player SNAPSHOTS" snapShot += playerSnapShots # Add EOF marker for validation snapShot += "\\EOF\\1" return snapShot
def getPlayerSnapshot(playerStat): # The player didn't spawn in... if playerStat.timePlayed == 0: return "" playerKeys = [ # main keys ("pID", playerStat.profileId), # Added by Chump - for bf2statistics stats ("name", playerStat.name), ("t", playerStat.team), ("a", playerStat.army), ("ctime", int(playerStat.timePlayed)), ("c", playerStat.complete), ("ip", playerStat.ipaddr), # score keys ("rs", playerStat.score), ("cs", playerStat.cmdScore), #("ss", playerStat.skillScore), ("ts", playerStat.teamScore), # Added by Chump - for bf2statistics stats ("kills", playerStat.kills), ("deaths", playerStat.deaths), # Added by Chump - for bf2statistics stats ("cpc", playerStat.localScore.cpCaptures + playerStat.localScore.cpNeutralizes ), ("cpa", playerStat.localScore.cpAssists + playerStat.localScore.cpNeutralizeAssists), #("cpc", playerStat.localScore.cpCaptures), #("cpn", playerStat.localScore.cpNeutralizes), #("cpa", playerStat.localScore.cpAssists), #("cpna", playerStat.localScore.cpNeutralizeAssists), ("cpd", playerStat.localScore.cpDefends), ("ka", playerStat.localScore.damageAssists), ("he", playerStat.localScore.heals), ("rev", playerStat.localScore.revives), ("rsp", playerStat.localScore.ammos), ("rep", playerStat.localScore.repairs), ("tre", playerStat.localScore.targetAssists), # Added by Chump - for bf2statistics stats ("drs", playerStat.localScore.driverSpecials + playerStat.localScore.driverAssists), #("drs", playerStat.localScore.driverSpecials), #("dra", playerStat.localScore.driverAssists), #("pa", playerStat.localScore.passengerAssists), ("tmkl", playerStat.teamkills), ("tmdg", playerStat.localScore.teamDamages), ("tmvd", playerStat.localScore.teamVehicleDamages), ("su", playerStat.localScore.suicides), ("ks", playerStat.longestKillStreak), ("ds", playerStat.longestDeathStreak), ("rank", playerStat.rank), ("ban", playerStat.timesBanned), ("kck", playerStat.timesKicked), # time keys ("tco", int(playerStat.timeAsCmd)), ("tsl", int(playerStat.timeAsSql)), ("tsm", int(playerStat.timeInSquad - playerStat.timeAsSql)), ("tlw", int(playerStat.timePlayed - playerStat.timeAsCmd - playerStat.timeInSquad)), ("ta0", int(playerStat.timeAsArmy[ARMY_USA])), ("ta1", int(playerStat.timeAsArmy[ARMY_MEC])), ("ta2", int(playerStat.timeAsArmy[ARMY_CHINESE])), #XPack1 Stuff ("ta3", int(playerStat.timeAsArmy[ARMY_SEALS])), ("ta4", int(playerStat.timeAsArmy[ARMY_SAS])), ("ta5", int(playerStat.timeAsArmy[ARMY_SPETZNAS])), ("ta6", int(playerStat.timeAsArmy[ARMY_MECSF])), ("ta7", int(playerStat.timeAsArmy[ARMY_REBELS])), ("ta8", int(playerStat.timeAsArmy[ARMY_INSURGENTS])), #EF Booster Pack Stuff ("ta9", int(playerStat.timeAsArmy[ARMY_EURO])), #POE2 Stuff ("ta10", int(playerStat.timeAsArmy[ARMY_GER])), ("ta11", int(playerStat.timeAsArmy[ARMY_UKR])), #AIX ("ta12", int(playerStat.timeAsArmy[ARMY_UN])), #CANADIAN FORCES ("ta13", int(playerStat.timeAsArmy[ARMY_CANADIAN])), ] # victims / victimizers statsMap = getStatsMap() for p in playerStat.killedPlayer: if not p in statsMap: if g_debug: print "killedplayer_id victim connorder: ", playerStat.killedPlayer[ p], " wasnt in statsmap!" else: playerKeys.append(("mvns", str(statsMap[p].profileId))) playerKeys.append(("mvks", str(playerStat.killedPlayer[p]))) # Added by Chump - for bf2statistics stats #for p in playerStat.killedByPlayer: # if not p in statsMap: # if g_debug: print "killedBYplayer_id victim connorder: ", playerStat.killedByPlayer[p], " wasnt in statsmap!" # else: # playerKeys.append(("vmns", str(statsMap[p].profileId))) # playerKeys.append(("vmks", str(playerStat.killedByPlayer[p]))) keyvals = [] for k in playerKeys: keyvals.append("\\".join((k[0], str(k[1])))) playerSnapShot = "\\".join(keyvals) # medals medalsSnapShot = "" if playerStat.medals: if g_debug: print "Medals Found (%s), Processing Medals Snapshot" % ( playerStat.profileId) medalsSnapShot = playerStat.medals.getSnapShot() # vehicles vehicleKeys = [ ("tv0", int(playerStat.vehicles[VEHICLE_TYPE_ARMOR].timeInObject)), ("tv1", int(playerStat.vehicles[VEHICLE_TYPE_AVIATOR].timeInObject)), ("tv2", int(playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].timeInObject)), ("tv3", int(playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].timeInObject)), ("tv4", int(playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].timeInObject)), ("tv5", int(playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].timeInObject)), ("tv6", int(playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].timeInObject)), ("tvp", int(playerStat.vehicles[VEHICLE_TYPE_PARACHUTE].timeInObject)), # Added by Chump - these do not register with onEnterVehicle() # XPack1 Stuff #("tnv", int(playerStat.vehicles[VEHICLE_TYPE_NIGHTVISION].timeInObject)), #("tgm", int(playerStat.vehicles[VEHICLE_TYPE_GASMASK].timeInObject)), ("kv0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].kills), ("kv1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].kills), ("kv2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].kills), ("kv3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].kills), ("kv4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].kills), ("kv5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].kills), ("kv6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].kills), ("bv0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].deaths), ("bv1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].deaths), ("bv2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].deaths), ("bv3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].deaths), ("bv4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].deaths), ("bv5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].deaths), ("bv6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].deaths), ("kvr0", playerStat.vehicles[VEHICLE_TYPE_ARMOR].roadKills), ("kvr1", playerStat.vehicles[VEHICLE_TYPE_AVIATOR].roadKills), ("kvr2", playerStat.vehicles[VEHICLE_TYPE_AIRDEFENSE].roadKills), ("kvr3", playerStat.vehicles[VEHICLE_TYPE_HELICOPTER].roadKills), ("kvr4", playerStat.vehicles[VEHICLE_TYPE_TRANSPORT].roadKills), ("kvr5", playerStat.vehicles[VEHICLE_TYPE_ARTILLERY].roadKills), ("kvr6", playerStat.vehicles[VEHICLE_TYPE_GRNDDEFENSE].roadKills), ] vehkeyvals = [] for k in vehicleKeys: #if k[1] == 0: continue vehkeyvals.append("\\".join((k[0], str(k[1])))) vehicleSnapShot = "\\".join(vehkeyvals) # kits kitKeys = [ ("tk0", int(playerStat.kits[KIT_TYPE_AT].timeInObject)), ("tk1", int(playerStat.kits[KIT_TYPE_ASSAULT].timeInObject)), ("tk2", int(playerStat.kits[KIT_TYPE_ENGINEER].timeInObject)), ("tk3", int(playerStat.kits[KIT_TYPE_MEDIC].timeInObject)), ("tk4", int(playerStat.kits[KIT_TYPE_SPECOPS].timeInObject)), ("tk5", int(playerStat.kits[KIT_TYPE_SUPPORT].timeInObject)), ("tk6", int(playerStat.kits[KIT_TYPE_SNIPER].timeInObject)), ("kk0", playerStat.kits[KIT_TYPE_AT].kills), ("kk1", playerStat.kits[KIT_TYPE_ASSAULT].kills), ("kk2", playerStat.kits[KIT_TYPE_ENGINEER].kills), ("kk3", playerStat.kits[KIT_TYPE_MEDIC].kills), ("kk4", playerStat.kits[KIT_TYPE_SPECOPS].kills), ("kk5", playerStat.kits[KIT_TYPE_SUPPORT].kills), ("kk6", playerStat.kits[KIT_TYPE_SNIPER].kills), ("dk0", playerStat.kits[KIT_TYPE_AT].deaths), ("dk1", playerStat.kits[KIT_TYPE_ASSAULT].deaths), ("dk2", playerStat.kits[KIT_TYPE_ENGINEER].deaths), ("dk3", playerStat.kits[KIT_TYPE_MEDIC].deaths), ("dk4", playerStat.kits[KIT_TYPE_SPECOPS].deaths), ("dk5", playerStat.kits[KIT_TYPE_SUPPORT].deaths), ("dk6", playerStat.kits[KIT_TYPE_SNIPER].deaths), ] kitkeyvals = [] for k in kitKeys: kitkeyvals.append("\\".join((k[0], str(k[1])))) kitSnapShot = "\\".join(kitkeyvals) # weapons weaponKeys = [ ("tw0", int(playerStat.weapons[WEAPON_TYPE_ASSAULT].timeInObject)), ("tw1", int(playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].timeInObject)), ("tw2", int(playerStat.weapons[WEAPON_TYPE_CARBINE].timeInObject)), ("tw3", int(playerStat.weapons[WEAPON_TYPE_LMG].timeInObject)), ("tw4", int(playerStat.weapons[WEAPON_TYPE_SNIPER].timeInObject)), ("tw5", int(playerStat.weapons[WEAPON_TYPE_PISTOL].timeInObject)), ("tw6", int(playerStat.weapons[WEAPON_TYPE_ATAA].timeInObject)), ("tw7", int(playerStat.weapons[WEAPON_TYPE_SMG].timeInObject)), ("tw8", int(playerStat.weapons[WEAPON_TYPE_SHOTGUN].timeInObject)), ("te0", int(playerStat.weapons[WEAPON_TYPE_KNIFE].timeInObject)), ("te1", int(playerStat.weapons[WEAPON_TYPE_C4].timeInObject)), ("te3", int(playerStat.weapons[WEAPON_TYPE_HANDGRENADE].timeInObject)), ("te2", int(playerStat.weapons[WEAPON_TYPE_CLAYMORE].timeInObject)), ("te4", int(playerStat.weapons[WEAPON_TYPE_SHOCKPAD].timeInObject)), ("te5", int(playerStat.weapons[WEAPON_TYPE_ATMINE].timeInObject)), # XPack1 Stuff ("te6", int(playerStat.weapons[WEAPON_TYPE_TACTICAL].timeInObject)), ("te7", int(playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].timeInObject)), ("te8", int(playerStat.weapons[WEAPON_TYPE_ZIPLINE].timeInObject)), ("kw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].kills), ("kw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].kills), ("kw2", playerStat.weapons[WEAPON_TYPE_CARBINE].kills), ("kw3", playerStat.weapons[WEAPON_TYPE_LMG].kills), ("kw4", playerStat.weapons[WEAPON_TYPE_SNIPER].kills), ("kw5", playerStat.weapons[WEAPON_TYPE_PISTOL].kills), ("kw6", playerStat.weapons[WEAPON_TYPE_ATAA].kills), ("kw7", playerStat.weapons[WEAPON_TYPE_SMG].kills), ("kw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].kills), ("ke0", playerStat.weapons[WEAPON_TYPE_KNIFE].kills), ("ke1", playerStat.weapons[WEAPON_TYPE_C4].kills), ("ke3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].kills), ("ke2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].kills), ("ke4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].kills), ("ke5", playerStat.weapons[WEAPON_TYPE_ATMINE].kills), ("bw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].deaths), ("bw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].deaths), ("bw2", playerStat.weapons[WEAPON_TYPE_CARBINE].deaths), ("bw3", playerStat.weapons[WEAPON_TYPE_LMG].deaths), ("bw4", playerStat.weapons[WEAPON_TYPE_SNIPER].deaths), ("bw5", playerStat.weapons[WEAPON_TYPE_PISTOL].deaths), ("bw6", playerStat.weapons[WEAPON_TYPE_ATAA].deaths), ("bw7", playerStat.weapons[WEAPON_TYPE_SMG].deaths), ("bw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].deaths), ("be0", playerStat.weapons[WEAPON_TYPE_KNIFE].deaths), ("be1", playerStat.weapons[WEAPON_TYPE_C4].deaths), ("be3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].deaths), ("be2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].deaths), ("be4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].deaths), ("be5", playerStat.weapons[WEAPON_TYPE_ATMINE].deaths), # XPack1 Stuff ("be8", playerStat.weapons[WEAPON_TYPE_ZIPLINE].deaths), ("be9", playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].deaths), # XPack1 Stuff ("de6", playerStat.weapons[WEAPON_TYPE_TACTICAL].deployed), ("de7", playerStat.weapons[WEAPON_TYPE_GRAPPLINGHOOK].deployed), ("de8", playerStat.weapons[WEAPON_TYPE_ZIPLINE].deployed), ("sw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].bulletsFired), ("sw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].bulletsFired), ("sw2", playerStat.weapons[WEAPON_TYPE_CARBINE].bulletsFired), ("sw3", playerStat.weapons[WEAPON_TYPE_LMG].bulletsFired), ("sw4", playerStat.weapons[WEAPON_TYPE_SNIPER].bulletsFired), ("sw5", playerStat.weapons[WEAPON_TYPE_PISTOL].bulletsFired), ("sw6", playerStat.weapons[WEAPON_TYPE_ATAA].bulletsFired), ("sw7", playerStat.weapons[WEAPON_TYPE_SMG].bulletsFired), ("sw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].bulletsFired), ("se0", playerStat.weapons[WEAPON_TYPE_KNIFE].bulletsFired), ("se1", playerStat.weapons[WEAPON_TYPE_C4].bulletsFired), ("se2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].bulletsFired), ("se3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].bulletsFired), ("se4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].bulletsFired), ("se5", playerStat.weapons[WEAPON_TYPE_ATMINE].bulletsFired), ("hw0", playerStat.weapons[WEAPON_TYPE_ASSAULT].bulletsHit), ("hw1", playerStat.weapons[WEAPON_TYPE_ASSAULTGRN].bulletsHit), ("hw2", playerStat.weapons[WEAPON_TYPE_CARBINE].bulletsHit), ("hw3", playerStat.weapons[WEAPON_TYPE_LMG].bulletsHit), ("hw4", playerStat.weapons[WEAPON_TYPE_SNIPER].bulletsHit), ("hw5", playerStat.weapons[WEAPON_TYPE_PISTOL].bulletsHit), ("hw6", playerStat.weapons[WEAPON_TYPE_ATAA].bulletsHit), ("hw7", playerStat.weapons[WEAPON_TYPE_SMG].bulletsHit), ("hw8", playerStat.weapons[WEAPON_TYPE_SHOTGUN].bulletsHit), ("he0", playerStat.weapons[WEAPON_TYPE_KNIFE].bulletsHit), ("he1", playerStat.weapons[WEAPON_TYPE_C4].bulletsHit), ("he2", playerStat.weapons[WEAPON_TYPE_CLAYMORE].bulletsHit), ("he3", playerStat.weapons[WEAPON_TYPE_HANDGRENADE].bulletsHit), ("he4", playerStat.weapons[WEAPON_TYPE_SHOCKPAD].bulletsHit), ("he5", playerStat.weapons[WEAPON_TYPE_ATMINE].bulletsHit), ] weapkeyvals = [] for k in weaponKeys: weapkeyvals.append("\\".join((k[0], str(k[1])))) weaponSnapShot = "\\".join(weapkeyvals) allSnapShots = [] if len(playerSnapShot) > 0: allSnapShots = allSnapShots + [playerSnapShot] if len(medalsSnapShot) > 0: allSnapShots = allSnapShots + [medalsSnapShot] if len(vehicleSnapShot) > 0: allSnapShots = allSnapShots + [vehicleSnapShot] if len(kitSnapShot) > 0: allSnapShots = allSnapShots + [kitSnapShot] if len(weaponSnapShot) > 0: allSnapShots = allSnapShots + [weaponSnapShot] playerSnapShot = "\\".join(allSnapShots) # add pid to all keys (gamespy likes this) transformedSnapShot = "" i = 0 idString = "_" + str(playerStat.connectionOrderNr) while i < len(playerSnapShot): key = "" while playerSnapShot[i] != "\\": key += playerSnapShot[i] i += 1 i += 1 value = "" while i < len(playerSnapShot) and playerSnapShot[i] != "\\": value += playerSnapShot[i] i += 1 transformedKeyVal = key + idString + "\\" + value if i != len(playerSnapShot): transformedKeyVal += "\\" transformedSnapShot += transformedKeyVal i += 1 return "\\" + transformedSnapShot
def invoke(): if g_debug: print "Invoked end-of-round data-send" # collect needed stats e = {} statsMap = getStatsMap() # find top player in different categories for sp in statsMap.itervalues(): for k in range(0, NUM_KIT_TYPES + 1): if k in sp.kits and sp.kits[k].timeInObject > 0: findTop(e, "sk" + str(k), "skn" + str(k), sp.kits[k].score, sp.name) for v in range(0, NUM_VEHICLE_TYPES + 1): if v in sp.vehicles and sp.vehicles[v].timeInObject > 0: findTop(e, "sv" + str(v), "svn" + str(v), sp.vehicles[v].score, sp.name) findTop(e, "ts", "tsn", sp.teamScore, sp.name) findTop(e, "ss", "ssn", sp.skillScore, sp.name) findTop(e, "cpc", "cpcn", sp.localScore.cpCaptures, sp.name) findTop(e, "cpa", "cpan", sp.localScore.cpAssists, sp.name) findTop(e, "cpd", "cpdn", sp.localScore.cpDefends, sp.name) findTop(e, "ka", "kan", sp.localScore.damageAssists + sp.localScore.targetAssists + sp.localScore.passengerAssists, sp.name) findTop(e, "he", "hen", sp.localScore.heals, sp.name) findTop(e, "rev", "revn", sp.localScore.revives, sp.name) findTop(e, "rsp", "rspn", sp.localScore.ammos, sp.name) findTop(e, "rep", "repn", sp.localScore.repairs, sp.name) findTop(e, "drs", "drsn", sp.localScore.driverSpecials + sp.localScore.driverAssists, sp.name) # find top-3 if len(statsMap) > 0: sortedPlayers = [] for sp in statsMap.itervalues(): sortedPlayers += [((sp.score, sp.skillScore, -sp.deaths), sp)] sortedPlayers.sort() sortedPlayers.reverse() # stats for top-3 scoring players for i in range(3): if len(sortedPlayers) <= i: break sp = sortedPlayers[i][1] e["np" + str(i)] = sp.name e["tsp" + str(i)] = sp.teamScore e["ssp" + str(i)] = sp.skillScore e["csp" + str(i)] = sp.cmdScore e["bfp" + str(i)] = sp.bulletsFired e["bhp" + str(i)] = sp.bulletsHit for k in range(0, NUM_KIT_TYPES + 1): if sp.kits[k].timeInObject > 0: e["tk" + str(k) + "p" + str(i)] = int(sp.kits[k].timeInObject) for v in range(0, NUM_VEHICLE_TYPES + 1): if sp.vehicles[v].timeInObject > 0: e["tv" + str(v) + "p" + str(i)] = int(sp.vehicles[v].timeInObject) keyvals = [] for k in e: keyvals.append ("\\".join((k, str(e[k])))) dataString = "\\" + "\\".join(keyvals) if g_debug: print dataString host.gl_sendEndOfRoundData(dataString)
def getSnapShot(): print "Assembling snapshot" global map_start snapShot = snapshot_prefix + '\\' + str( bf2.serverSettings.getServerConfig('sv.serverName')) + '\\' snapShot += 'gameport\\' + str( bf2.serverSettings.getServerConfig('sv.serverPort')) + '\\' snapShot += 'queryport\\' + str( bf2.serverSettings.getServerConfig('sv.gameSpyPort')) + '\\' snapShot += 'mapname\\' + str(bf2.gameLogic.getMapName()) + '\\' snapShot += 'mapid\\' + str(getMapId( bf2.serverSettings.getMapName())) + '\\' snapShot += 'mapstart\\' + str(map_start) + '\\mapend\\' + str( time()) + '\\' snapShot += 'win\\' + str(bf2.gameLogic.getWinner()) + '\\' if g_debug: print 'Finished Pre-Compile SNAPSHOT' statsMap = getStatsMap() # ---------------------------------------------------------------------------- # omero 2006-04-10 # ---------------------------------------------------------------------------- # this will be used for detecting which mod is running and # set standardKeys['v'] accordingly # defaults to 'bf2' # running_mod = str(host.sgl_getModDirectory()) if (running_mod.lower() == 'mods/bf2'): v_value = 'bf2' elif (running_mod.lower() == 'mods/bf2sp64'): v_value = 'bf2sp64' elif (running_mod.lower() == 'mods/xpack'): v_value = 'xpack' elif (running_mod.lower() == 'mods/poe2'): v_value = 'poe2' elif (running_mod.lower() == 'mods/aix2'): v_value = 'aix2' else: v_value = 'bf2' if g_debug: print 'Running MOD: %s' % (str(v_value)) standardKeys = [ ("gm", getGameModeId(bf2.serverSettings.getGameMode())), ("m", getMapId(bf2.serverSettings.getMapName())), ("v", str(v_value)), ("pc", len(statsMap)), ] # only send rwa key if there was a winner winner = bf2.gameLogic.getWinner() if winner != 0: standardKeys += [("rwa", roundArmies[winner])] # get final ticket score if g_debug: print "Army 1 (%s) Score: %s" % (str( roundArmies[1]), str(bf2.gameLogic.getTickets(1))) if g_debug: print "Army 2 (%s) Score: %s" % (str( roundArmies[2]), str(bf2.gameLogic.getTickets(2))) standardKeys += [ ("ra1", str(roundArmies[1])), ("rs1", str(bf2.gameLogic.getTickets(1))), ("ra2", str(roundArmies[2])), ("rs2", str(bf2.gameLogic.getTickets(2))), ] standardKeys += [("rst2", str(bf2.gameLogic.getTickets(2)))] stdKeyVals = [] for k in standardKeys: stdKeyVals.append("\\".join((k[0], str(k[1])))) snapShot += "\\".join(stdKeyVals) if g_debug: print 'Snapshot Pre-processing complete: %s' % (str(snapShot)) playerSnapShots = "" if g_debug: print 'Num clients to base snap on: %d' % (len(statsMap)) for sp in statsMap.itervalues(): if g_debug: print 'Processing PID: %s' % (str(sp.profileId)) playerSnapShots += getPlayerSnapshot(sp) print "Doing Player SNAPSHOTS" snapShot += playerSnapShots # Add EOF marker for validation snapShot += "\\EOF\\1" return snapShot