]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup endmatch/shutdown for gamereport
authorSamual Lenks <samual@xonotic.org>
Sun, 1 Dec 2013 03:05:25 +0000 (22:05 -0500)
committerSamual Lenks <samual@xonotic.org>
Sun, 1 Dec 2013 03:05:25 +0000 (22:05 -0500)
qcsrc/common/playerstats.qc
qcsrc/common/playerstats.qh
qcsrc/server/autocvars.qh
qcsrc/server/cl_client.qc
qcsrc/server/g_world.qc

index 8f6af5cc392b7be6001584a11327b1bc0342dbcd..daf31b0d1de57f65c6c091147198637dfc0ae545 100644 (file)
@@ -138,7 +138,7 @@ void PlayerStats_GameReport_Accuracy(entity p)
     #undef PAC
 }
 
-void PlayerStats_GameReport_AddGlobalInfo(entity p)
+void PlayerStats_GameReport_FinalizePlayer(entity p)
 {
        if((p.playerstats_id == "") || PS_GR_OUT_DB < 0) { return; }
 
@@ -178,32 +178,57 @@ void PlayerStats_GameReport_AddGlobalInfo(entity p)
 .float scoreboard_pos;
 void PlayerStats_GameReport_EndMatch(float finished)
 {
-       entity p;
+       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);
 
-               if(!p.scoreboard_pos) { continue; }
-
-               // scoreboard is valid!
-               PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
+               // 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 position
+                       PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
 
-               // add scoreboard data
-               PlayerScore_PlayerStats(p);
+                       // 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);
+                       // 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;
        }
 }
 
@@ -255,26 +280,6 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that
        PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM);
 }
 
-void PlayerStats_GameReport_Shutdown()
-{
-       string uri;
-
-       if(PS_GR_OUT_DB < 0) { return; }
-
-       uri = autocvar_g_playerstats_uri;
-       if(uri != "")
-       {
-               PlayerStats_GameReport_DelayMapVote = TRUE;
-               url_multi_fopen(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_Handler(entity fh, entity pass, float status)
 {
        string t, tn;
@@ -339,7 +344,7 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
                        url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count));
                        url_fputs(fh, sprintf("U %d\n", cvar("port")));
                        url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime)));
-                       url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_ladder));
+                       url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_gamereport_ladder));
 
                        // TEAMS
                        if(teamplay)
index d381f28967ded54249eb3a196a15225d8f378dfe..5c8c81f914240e65e167cb517a5df70167b0687d 100644 (file)
@@ -50,7 +50,7 @@ void PlayerStats_GameReport_Shutdown(); // send stats to the server
 void PlayerStats_GameReport_Accuracy(entity p);
 
 // call this whenever a player leaves
-void PlayerStats_GameReport_AddGlobalInfo(entity p);
+void PlayerStats_GameReport_FinalizePlayer(entity p);
 
 // call this at the end of the match
 void PlayerStats_GameReport_EndMatch(float finished);
@@ -60,6 +60,8 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status);
 .string playerstats_id;
 
 string autocvar_g_playerstats_uri;
+string autocvar_g_playerstats_gamereport_ladder;
+string autocvar_g_playerstats_gamereport_uri;
 
 #endif //SVQC
 
index 2d10b6a2bd1bf78b7053a749a09548394f3d9de8..8a308d2d576a64cf9de8f6c3d7368ffdac8b3655 100644 (file)
@@ -1247,4 +1247,3 @@ float autocvar_g_campcheck_damage;
 float autocvar_g_campcheck_distance;
 float autocvar_g_campcheck_interval;
 float autocvar_g_jump_grunt;
-string autocvar_g_playerstats_ladder;
index ae8e1b41f2e2475d955c5f08c97abeafe7293b6c..79934eb82c7926727be18f8231a0780611881f0d 100644 (file)
@@ -1256,7 +1256,7 @@ void ClientDisconnect (void)
                return;
        }
 
-       PlayerStats_GameReport_AddGlobalInfo(self);
+       PlayerStats_GameReport_FinalizePlayer(self);
 
        CheatShutdownClient();
 
index 006a4f240005fb13c8fa50bf59c7923d75927027..36f6d14f4b268f171998af1c400f277ede5c6215 100644 (file)
@@ -1505,12 +1505,8 @@ void NextLevel()
 
        DumpStats(TRUE);
 
-       // send statistics // fixme
-       entity e;
-       PlayerStats_GameReport_EndMatch(1);
-       FOR_EACH_CLIENT(e)
-               PlayerStats_GameReport_AddGlobalInfo(e);
-       PlayerStats_GameReport_Shutdown();
+       // send statistics
+       PlayerStats_GameReport_EndMatch(TRUE);
        WeaponStats_Shutdown();
 
        Kill_Notification(NOTIF_ALL, world, MSG_CENTER, 0); // kill all centerprints now
@@ -2834,8 +2830,6 @@ void RestoreGame()
 
 void Shutdown()
 {
-       entity e;
-
        gameover = 2;
 
        if(world_initialized > 0)
@@ -2844,11 +2838,8 @@ void Shutdown()
                print("Saving persistent data...\n");
                Ban_SaveBans();
 
-               // fixme
-               PlayerStats_GameReport_EndMatch(0);
-               FOR_EACH_CLIENT(e)
-                       PlayerStats_GameReport_AddGlobalInfo(e);
-               PlayerStats_GameReport_Shutdown();
+               // playerstats with unfinished match
+               PlayerStats_GameReport_EndMatch(FALSE);
 
                if(!cheatcount_total)
                {