]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
player stats: send all info from scoreboard
authorRudolf Polzer <divverent@alientrap.org>
Fri, 14 Jan 2011 22:14:56 +0000 (23:14 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Fri, 14 Jan 2011 22:20:24 +0000 (23:20 +0100)
defaultXonotic.cfg
qcsrc/server/autocvars.qh
qcsrc/server/g_damage.qc
qcsrc/server/g_world.qc
qcsrc/server/playerstats.qc
qcsrc/server/playerstats.qh
qcsrc/server/scores.qc

index 60d98576a65539698b103a465b555852ddcdabc2..51aebb91f091e4fe3e7fdac63a66df81c2490d7f 100644 (file)
@@ -2070,6 +2070,7 @@ set g_weapon_charge_colormod_blue_full -1
 
 // player statistics server URI
 set g_playerstats_uri ""
+set g_playerstats_debug 0 "when 1, player stats are dumped to the console too"
 
 // create this cvar in case the engine did not
 set snd_soundradius 1200
index c90f32b23fa79c4a1b1def1fb054b2e81005e509..e791e71440ad7e890abb8d57359f7760f1349525 100644 (file)
@@ -869,6 +869,7 @@ float autocvar_g_player_alpha;
 float autocvar_g_player_brightness;
 float autocvar_g_playerclip_collisions;
 string autocvar_g_playerstats_uri;
+float autocvar_g_playerstats_debug;
 float autocvar_g_powerup_shield;
 float autocvar_g_powerup_strength;
 float autocvar_g_powerup_superhealth;
index 69f5bfa2488620d9c93e23810f52b3ce1495b2e5..8583d8ca986cdd583c68947c58bc429fc943f484 100644 (file)
@@ -120,14 +120,12 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                {
                        // teamkill
                        PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
-                       PlayerStats_Event(attacker, PLAYERSTATS_KILLS, -1);
                }
        }
        else
        {
                // regular frag
                PlayerScore_Add(attacker, SP_KILLS, 1);
-               PlayerStats_Event(attacker, PLAYERSTATS_KILLS, 1);
        }
 
        PlayerScore_Add(targ, SP_DEATHS, 1);
index 02d82f27a91cdbfbe579f1e371cb690cc81e2eab..b01d8515b8194f43915942dd80a97dfe6ea7a55b 100644 (file)
@@ -1595,6 +1595,7 @@ void NextLevel()
        VoteReset();
 
        DumpStats(TRUE);
+       PlayerStats_EndMatch();
 
        if(autocvar_sv_eventlog)
                GameLogEcho(":gameover");
index 7904e30ef1efab3ce7ed4dba8214781522401020..822a284d67364e9a37619e37b1a2e3630d632e1e 100644 (file)
@@ -3,6 +3,7 @@ string playerstats_last;
 string events_last;
 .float playerstats_addedglobalinfo;
 float playerstats_requested;
+.string playerstats_id;
 
 void PlayerStats_Init()
 {
@@ -17,16 +18,24 @@ void PlayerStats_Init()
                playerstats_waitforme = FALSE; // must wait for it at match end
        
        PlayerStats_AddEvent(PLAYERSTATS_ALIVETIME);
-       PlayerStats_AddEvent(PLAYERSTATS_KILLS);
+       PlayerStats_AddEvent(PLAYERSTATS_WINS);
+       PlayerStats_AddEvent(PLAYERSTATS_MATCHES);
 }
 
 void PlayerStats_AddPlayer(entity e)
 {
-       if(!e.crypto_idfp || playerstats_db < 0)
+       if(playerstats_db < 0)
                return;
+
+       if(e.crypto_idfp != "")
+               e.playerstats_id = strzone(e.crypto_idfp);
+       else if(clienttype(e) == CLIENTTYPE_BOT)
+               e.playerstats_id = strzone(sprintf("bot#%d", e.playerid));
+       else
+               e.playerstats_id = strzone(sprintf("player#%d", e.playerid));
        
        string key;
-       key = sprintf("%s:*", e.crypto_idfp);
+       key = sprintf("%s:*", e.playerstats_id);
        
        string p;
        p = db_get(playerstats_db, key);
@@ -39,7 +48,7 @@ void PlayerStats_AddPlayer(entity e)
                }
                else
                        db_put(playerstats_db, key, "#");
-               playerstats_last = strzone(e.crypto_idfp);
+               playerstats_last = strzone(e.playerstats_id);
        }
 }
 
@@ -68,12 +77,12 @@ void PlayerStats_AddEvent(string event_id)
 
 void PlayerStats_Event(entity e, string event_id, float value)
 {
-       if(!e.crypto_idfp || playerstats_db < 0)
+       if(!e.playerstats_id || playerstats_db < 0)
                return;
        
        string key;
        float val;
-       key = sprintf("%s:%s", e.crypto_idfp, event_id);
+       key = sprintf("%s:%s", e.playerstats_id, event_id);
        val = stof(db_get(playerstats_db, key));
        val += value;
        db_put(playerstats_db, key, ftos(val));
@@ -127,6 +136,12 @@ void PlayerStats_Shutdown()
                }
                bufstr_set(b, i++, "");
 
+               if(autocvar_g_playerstats_debug)
+               {
+                       for(i = 0; i < buf_getsize(b); ++i)
+                               print(bufstr_get(b, i), "\n");
+               }
+
                if(crypto_uri_postbuf(uri, URI_GET_PLAYERSTATS_SENT, "text/plain", "\n", b, 0))
                        playerstats_requested = TRUE;
                else
@@ -146,14 +161,31 @@ void PlayerStats_AddGlobalInfo(entity p)
 {
        if(playerstats_db < 0)
                return;
-       if(!p.crypto_idfp || playerstats_db < 0)
+       if(!p.playerstats_id || playerstats_db < 0)
                return;
        p.playerstats_addedglobalinfo = TRUE;
 
        // add global info!
        if(p.alivetime)
                PlayerStats_Event(p, PLAYERSTATS_ALIVETIME, time - p.alivetime);
+
+       if(p.alivetime)
+               PlayerStats_Event(p, PLAYERSTATS_ALIVETIME, time - p.alivetime);
        
        if(p.cvar_cl_allow_uid2name == 1)
-               db_put(playerstats_db, sprintf("%s:_netname", p.crypto_idfp), p.netname);
+               db_put(playerstats_db, sprintf("%s:_netname", p.playerstats_id), p.netname);
+
+       strunzone(p.playerstats_id);
+       p.playerstats_id = string_null;
+}
+
+void PlayerStats_EndMatch()
+{
+       entity p;
+       FOR_EACH_PLAYER(p)
+       {
+               PlayerScore_PlayerStats(p);
+               PlayerStats_Event(p, PLAYERSTATS_WINS, p.winning);
+               PlayerStats_Event(p, PLAYERSTATS_MATCHES, 1);
+       }
 }
index fea546a123d5e4719bbac67b2fd6d1739563f4a9..1dea13ce7e268bd73dad398c4fffbd59297df2c2 100644 (file)
@@ -1,6 +1,9 @@
 // time the player was alive and kicking
-string PLAYERSTATS_ALIVETIME = "alivetime";
-string PLAYERSTATS_KILLS     = "kills";
+string PLAYERSTATS_ALIVETIME  = "alivetime";
+string PLAYERSTATS_WINS = "wins";
+string PLAYERSTATS_MATCHES = "matches";
+string PLAYERSTATS_TOTAL = "total-";
+string PLAYERSTATS_SCOREBOARD = "scoreboard-";
 
 // delay map switch until this is set
 float playerstats_waitforme;
@@ -25,3 +28,6 @@ void PlayerStats_Sent_URI_Get_Callback(float id, float status, string data);
 
 // call this whenever a player leaves
 void PlayerStats_AddGlobalInfo(entity p);
+
+// call this at the end of the match
+void PlayerStats_EndMatch()
index b0f9293db27344666d605ba4cb5f3b2b55977778..be843339729ddb09ac5bfe34f3742899baccc93c 100644 (file)
@@ -150,6 +150,8 @@ void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags)
                scores_primary = scores[i];
                scores_flags_primary = scoreflags;
        }
+       PlayerStats_AddEvent(strcat(PLAYERSTATS_TOTAL, label));
+       PlayerStats_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label));
 }
 
 void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
@@ -257,7 +259,6 @@ void PlayerScore_Clear(entity player)
                        if(scores_label[i] != "")
                                sk.SendFlags |= pow(2, i);
                sk.(scores[i]) = 0;
-               // do NOT clear scores_accumulated!
        }
 }
 
@@ -276,7 +277,6 @@ void Score_ClearAll()
                                if(scores_label[i] != "")
                                        sk.SendFlags |= pow(2, i);
                        sk.(scores[i]) = 0;
-                       // do NOT clear scores_accumulated!
                }
        }
        for(t = 0; t < 16; ++t)
@@ -333,6 +333,7 @@ float PlayerScore_Add(entity player, float scorefield, float score)
        if(score)
                if(scores_label[scorefield] != "")
                        s.SendFlags |= pow(2, scorefield);
+       PlayerStats_Event(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label[scorefield]), score);
        s.(scores_accumulated[scorefield]) += score;
        return (s.(scores[scorefield]) += score);
 }
@@ -868,3 +869,14 @@ void Score_NicePrint(entity to)
        }
 }
 
+void PlayerScore_PlayerStats(entity p)
+{
+       entity s;
+       float i;
+       s = p.scorekeeper;
+
+       for(i = 0; i < MAX_SCORE; ++i)
+               if(s.(scores[i]) != 0)
+                       if(scores_label[i] != "")
+                               PlayerStats_Event(s.owner, strcat(PLAYERSTATS_SCOREBOARD, scores_label[i]), s.(scores[i]));
+}