-/*
- format spec:
-
- A collection of lines of the format <key> SPACE <value> NEWLINE, where
- <key> is always a single character.
-
- The following keys are defined:
-
- V: format version (always a fixed number) - this MUST be the first line!
- #: comment (MUST be ignored by any parser)
- R: release information on the server
- G: game type
- O: mod name (icon request) as in server browser
- M: map name
- I: match ID (see "matchid" in g_world.qc
- S: "hostname" of the server
- C: number of "unpure" cvar changes
- U: UDP port number of the server
- D: duration of the match
- P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!)
- Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!)
- n: nickname of the player (optional)
- t: team ID
- i: player index
- e: followed by an event name, a space, and the event count/score
- event names can be:
- alivetime: total playing time of the player
- avglatency: average network latency compounded throughout the match
- wins: number of games won (can only be set if matches is set)
- matches: number of matches played to the end (not aborted by map switch)
- joins: number of matches joined (always 1 unless player never played during the match)
- scoreboardvalid: set to 1 if the player was there at the end of the match
- total-<scoreboardname>: total score of that scoreboard item
- scoreboard-<scoreboardname>: end-of-game score of that scoreboard item (can differ in non-team games)
- achievement-<achievementname>: achievement counters (their "count" is usually 1 if nonzero at all)
- kills-<index>: number of kills against the indexed player
- rank <number>: rank of player
- acc-<weapon netname>-hit: total damage dealt
- acc-<weapon netname>-fired: total damage that all fired projectiles *could* have dealt
- acc-<weapon netname>-cnt-hit: amount of shots that actually hit
- acc-<weapon netname>-cnt-fired: amount of fired shots
- acc-<weapon netname>-frags: amount of frags dealt by weapon
-
- Response format (not used yet): see https://gist.github.com/4284222
-*/
+void PlayerStats_GameReport_FinalizePlayer(entity p)
+{
+ if((p.playerstats_id == "") || PS_GR_OUT_DB < 0) { return; }
+
+ // add global info!
+ if(p.alivetime)
+ {
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_ALIVETIME, time - p.alivetime);
+ p.alivetime = 0;
+ }
+
+ db_put(PS_GR_OUT_DB, sprintf("%s:_playerid", p.playerstats_id), ftos(p.playerid));
+
+ if(p.cvar_cl_allow_uid2name == 1 || IS_BOT_CLIENT(p))
+ db_put(PS_GR_OUT_DB, sprintf("%s:_netname", p.playerstats_id), p.netname);
+
+ if(teamplay)
+ db_put(PS_GR_OUT_DB, sprintf("%s:_team", p.playerstats_id), ftos(p.team));
+
+ if(stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p.playerstats_id, PLAYERSTATS_ALIVETIME))) > 0)
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_JOINS, 1);
+
+ PlayerStats_GameReport_Accuracy(p);
+
+ if(IS_REAL_CLIENT(p))
+ {
+ if(p.latency_cnt)
+ {
+ float latency = (p.latency_sum / p.latency_cnt);
+ if(latency) { PS_GR_P_ADDVAL(p, PLAYERSTATS_AVGLATENCY, latency); }
+ }
+ }
+
+ strunzone(p.playerstats_id);
+ p.playerstats_id = string_null;
+}
+
+void PlayerStats_GameReport(float finished)
+{
+ if(PS_GR_OUT_DB < 0) { return; }
+
+ PlayerScore_Sort(score_dummyfield, 0, 0, 0);
+ PlayerScore_Sort(scoreboard_pos, 1, 1, 1);
+ if(teamplay) { PlayerScore_TeamStats(); }
+
+ entity p;
+ FOR_EACH_CLIENT(p)
+ {
+ // add personal score rank
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_RANK, p.score_dummyfield);
+
+ // scoreboard data
+ if(p.scoreboard_pos)
+ {
+ // scoreboard is valid!
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
+
+ // add scoreboard position
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
+
+ // add scoreboard data
+ PlayerScore_PlayerStats(p);
+
+ // if the match ended normally, add winning info
+ if(finished)
+ {
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_WINS, p.winning);
+ PS_GR_P_ADDVAL(p, PLAYERSTATS_MATCHES, 1);
+ }
+ }
+
+ // collect final player information
+ PlayerStats_GameReport_FinalizePlayer(p);
+ }
+
+ if(autocvar_g_playerstats_gamereport_uri != "")
+ {
+ PlayerStats_GameReport_DelayMapVote = true;
+ url_multi_fopen(
+ autocvar_g_playerstats_gamereport_uri,
+ FILE_APPEND,
+ PlayerStats_GameReport_Handler,
+ world
+ );
+ }
+ else
+ {
+ PlayerStats_GameReport_DelayMapVote = false;
+ db_close(PS_GR_OUT_DB);
+ PS_GR_OUT_DB = -1;
+ }
+}
+
+void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that scores are added properly
+{
+ if(autocvar_g_playerstats_gamereport_uri == "") { return; }
+
+ PS_GR_OUT_DB = db_create();
+
+ if(PS_GR_OUT_DB >= 0)
+ {
+ PlayerStats_GameReport_DelayMapVote = true;
+
+ serverflags |= SERVERFLAG_PLAYERSTATS;
+
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_ALIVETIME);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_AVGLATENCY);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_WINS);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_MATCHES);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_JOINS);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_VALID);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_POS);
+ PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK);
+
+ // accuracy stats
+ entity w;
+ float i;
+ for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+ {
+ w = get_weaponinfo(i);
+ PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-hit"));
+ PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-fired"));
+ PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-hit"));
+ PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-fired"));
+ PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-frags"));
+ }