]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
WIP commit; retrieving data from xonstats works
authorJan Behrens <zykure@web.de>
Sun, 4 Aug 2013 18:05:15 +0000 (20:05 +0200)
committerJan Behrens <zykure@web.de>
Sun, 4 Aug 2013 18:05:15 +0000 (20:05 +0200)
qcsrc/client/Main.qc
qcsrc/client/autocvars.qh
qcsrc/client/progs.src
qcsrc/common/playerstats.qc
qcsrc/common/playerstats.qh
qcsrc/menu/command/menu_cmd.qc
qcsrc/menu/progs.src

index 42fadc0c18a86b0cc0cec1eb145409adebe08efb..f6339ac38fe95cf8c24e4daafc156870b0433802 100644 (file)
@@ -81,7 +81,7 @@ void CSQC_Init(void)
        //registercommand("hud_configure");
        //registercommand("hud_save");
        //registercommand("menu_action");
-       
+
        ConsoleCommand_macro_init();
 
        registercvar("hud_usecsqc", "1");
@@ -125,13 +125,13 @@ void CSQC_Init(void)
        turrets_precache();
        Tuba_Precache();
        CSQCPlayer_Precache();
-       
+
        if(autocvar_cl_reticle)
        {
                if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
                if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
        }
-       
+
        get_mi_min_max_texcoords(1); // try the CLEVER way first
        minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
        shortmapname = mi_shortname;
@@ -156,6 +156,12 @@ void CSQC_Init(void)
        hud_configure_prev = -1;
 
        draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
+
+
+       //// WIP - zykure
+
+       PlayerInfo_Init();
+       PlayerInfo_Retrieve(self.owner);
 }
 
 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
@@ -651,7 +657,7 @@ void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
        spn_origin_x = ReadShort();
        spn_origin_y = ReadShort();
        spn_origin_z = ReadShort();
-       
+
        if(is_new)
        {
                self.origin = spn_origin;
@@ -682,7 +688,7 @@ void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
                                }
                        }
                        else { self.cnt = particleeffectnum("spawn_point_neutral"); }
-                       
+
                        self.draw = Spawn_Draw;
                }
        }
@@ -696,7 +702,7 @@ void Ent_ReadSpawnEvent(float is_new)
        // this way the server can disable the sending of
        // spawn origin or such to clients if wanted.
        float entnum = ReadByte();
-       
+
        if(entnum)
        {
                self.origin_x = ReadShort();
@@ -724,7 +730,7 @@ void Ent_ReadSpawnEvent(float is_new)
                        }
                }
        }
-       
+
        // local spawn actions
        if(is_new && (!entnum || (entnum == player_localentnum)))
        {
@@ -737,7 +743,7 @@ void Ent_ReadSpawnEvent(float is_new)
                        button_zoom = FALSE;
                }
        }
-       
+
        //print(sprintf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum));
 }
 
@@ -822,9 +828,9 @@ void CSQC_Ent_Update(float bIsNewEntity)
                case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
                case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
                case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
-               case ENT_CLIENT_TURRET: ent_turret(); break; 
+               case ENT_CLIENT_TURRET: ent_turret(); break;
                case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
-               case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;  
+               case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;
                case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;
                case ENT_CLIENT_SPAWNPOINT: Ent_ReadSpawnPoint(bIsNewEntity); break;
                case ENT_CLIENT_SPAWNEVENT: Ent_ReadSpawnEvent(bIsNewEntity); break;
index 8175695abb0ac5ef0a4c033e671a742a907776fb..403792020ac7c7e08aa6a412f15abd5e98cffa9b 100644 (file)
@@ -337,7 +337,7 @@ float autocvar_hud_panel_weapons_timeout;
 float autocvar_hud_panel_weapons_timeout_effect;
 float autocvar_hud_panel_weapons_timeout_fadebgmin;
 float autocvar_hud_panel_weapons_timeout_fadefgmin;
-var float autocvar_hud_panel_weapons_timeout_speed_in = 0.25; 
+var float autocvar_hud_panel_weapons_timeout_speed_in = 0.25;
 var float autocvar_hud_panel_weapons_timeout_speed_out = 0.75;
 float autocvar_hud_progressbar_alpha;
 float autocvar_hud_showbinds;
index 114f0a5b5c77fdd666db5ae4953b653fa40302e5..1bae6f980ce9cd9d232dd6f4cdf52f9f7f339fdc 100644 (file)
@@ -14,6 +14,7 @@ Defs.qc
 ../warpzonelib/common.qh
 ../warpzonelib/client.qh
 
+../common/playerstats.qh
 ../common/teams.qh
 ../common/util.qh
 ../common/test.qh
@@ -102,6 +103,7 @@ noise.qc
 
 ../common/test.qc
 ../common/util.qc
+../common/playerstats.qc
 ../common/notifications.qc
 ../common/command/markup.qc
 ../common/command/rpn.qc
index b6f795ed814c3e6326bd33fa36fb86ac45dcb1ed..7389a61cab3e4638c40b325aba71c072c21b5f04 100644 (file)
@@ -433,82 +433,176 @@ void PlayerStats_EndMatch(float finished)
        }
 }
 
+#endif // SVQC
+
 
 //// WIP -zykure
 
-/*
-       format spec:
+float playerinfo_db;
+string playerinfo_last;
+string playerinfo_events_last;
+.float playerid;
 
-       A collection of lines of the format <key> SPACE <value> NEWLINE, where
-       <key> is always a single character.
+void PlayerInfo_AddPlayer(entity e)
+{
+       string s;
 
-       The following keys are defined:
+       if(playerinfo_db < 0)
+               return;
 
-       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
-       T: time at which the game ended
-       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
+       s = sprintf("#%d", e.playerid);
 
-       Response format (not used yet): see https://gist.github.com/4284222
-*/
-/*
-void PlayerStatsEntity_ready(entity fh, entity player_stats, float status)
+       string key;
+       key = sprintf("%s:*", s);
+
+       string p;
+       p = db_get(playerinfo_db, key);
+       if(p == "")
+       {
+               if(playerinfo_last)
+               {
+                       db_put(playerinfo_db, key, playerinfo_last);
+                       strunzone(playerinfo_last);
+               }
+               else
+                       db_put(playerinfo_db, key, "#");
+               playerinfo_last = strzone(ftos(e.playerid));
+               print("  Added player ", s, " to playerinfo_db\n");
+       }
+}
+
+void PlayerInfo_AddItem(entity e, string item_id, string val)
 {
+       if(playerinfo_db < 0)
+               return;
+
+       string key;
+       key = sprintf("*:%s", item_id);
+
+       string p;
+       p = db_get(playerinfo_db, key);
+       if(p == "")
+       {
+               if(playerinfo_events_last)
+               {
+                       db_put(playerinfo_db, key, playerinfo_events_last);
+                       strunzone(playerinfo_events_last);
+               }
+               else
+                       db_put(playerinfo_db, key, "#");
+               playerinfo_events_last = strzone(item_id);
+       }
+
+       key = sprintf("#%d:%s", e.playerid, item_id);
+       db_put(playerinfo_db, key, val);
+
+       print("Added event ", key, "=", val, " to playerinfo_db\n");
+}
+
+string PlayerInfo_GetItem(entity e, string item_id)
+{
+       if(playerinfo_db < 0)
+               return string_null;
+
+       string key;
+       key = sprintf("#%d:%s",  e.playerid, item_id);
+       return db_get(playerinfo_db, key);
+}
+
+void PlayerInfo_ready(entity fh, entity p, float status)
+{
+       float n;
        string s;
-       string key, value;
+
+       PlayerInfo_AddPlayer(p);
 
        switch(status)
        {
                case URL_READY_CANREAD:
-                       print("Got response from player stats server:\n");
+                       print("-- Got response from player stats server:\n");
+                       float in_group = FALSE;
+                       string gametype = string_null;
                        while((s = url_fgets(fh)))
                        {
-                               print("  ", s, "\n");
+                               print("  >> ", s, "\n");
+
+                               string key = string_null, value = string_null, data = string_null;
+
+                               n = tokenizebyseparator(s, " "); // key (value) data
+                               if (n == 1)
+                               {
+                                       if (argv(0) == "}")
+                                               in_group = FALSE;
+                               }
+                               else if (n == 2)
+                               {
+                                       key = argv(0);
+                                       data = argv(1);
+                               }
+                               else if (n == 3)
+                               {
+                                       if (argv(0) == "{")
+                                       {
+                                               in_group = TRUE;
+                                               key = argv(1);
+                                               data = argv(2);
+                                       }
+                                       else
+                                       {
+                                               key = argv(0);
+                                               value = argv(1);
+                                               data = argv(2);
+                                       }
+                               }
+                               else if (n == 4)
+                               {
+                                       key = argv(0);
+                                       value = argv(1);
+                                       data = argv(2);
+                               }
+                               else
+                                       continue;
+
+                               if (data == "")
+                                       continue;
 
-                               key = substring(s, 0, 1);
-                               value = substring(s, 2, -1);
                                if (key == "#")
+                                       // comment
                                        continue;
                                else if (key == "V")
                                        // version
-                                       continue;
+                                       PlayerInfo_AddItem(p, "_version", data);
+                               else if (key == "R")
+                                       // watermark
+                                       PlayerInfo_AddItem(p, "_release", data);
+                               else if (key == "T")
+                                       // timestamp
+                                       PlayerInfo_AddItem(p, "_time", data);
+                               else if (key == "S")
+                                       // stats page URL
+                                       PlayerInfo_AddItem(p, "_statsurl", data);
                                else if (key == "P")
-                                       player_stats.playerid = stof(value);
+                                       // player hashkey
+                                       PlayerInfo_AddItem(p, "_hashkey", data);
                                else if (key == "n")
-                                       player_stats.playernick = value;
+                                       // player nick
+                                       PlayerInfo_AddItem(p, "_playernick", data);
+                               else if (key == "i")
+                                       // xonstats id
+                                       PlayerInfo_AddItem(p, "_playerid", data);
+                               else if (key == "G" && in_group)
+                                       gametype = data;
+                               else if (key == "e" && value != "")
+                               {
+                                       if (gametype == "")
+                                               PlayerInfo_AddItem(p, value, data);
+                                       else
+                                               PlayerInfo_AddItem(p, sprintf("%s-%s", gametype, value), data);
+                               }
+                               else
+                                       continue;
                        }
-                       print("End of response.\n");
+                       print("-- End of response.\n");
                        url_fclose(fh);
                        break;
                case URL_READY_CLOSED:
@@ -522,16 +616,40 @@ void PlayerStatsEntity_ready(entity fh, entity player_stats, float status)
        }
 }
 
-void PlayerStats_GetPlayerInfo(entity p)
+void PlayerInfo_Init()
 {
-       string uri;
+       playerinfo_db = -1;
+       playerinfo_db = db_create();
+}
+
+void PlayerInfo_Retrieve(entity p)
+{
+       if(playerinfo_db < 0)
+               return;
 
+       string uri = "", hash = "";
+/*
+#ifdef SVQC
        uri = autocvar_g_playerstats_uri;
-       if(uri != "")
+       hash = p.crypto_idfp;
+#endif
+#ifdef CSQC
+       uri = "http://stats.xonotic.org"; // FIXME!
+       hash = "pQBWJrkNzHCMtndkICJacPENGctTNR59rmFS4x91FFo="; // FIXME!
+#endif
+*/
+#ifdef MENUQC
+       uri = "http://stats.xonotic.org"; // FIXME!
+       hash = crypto_getmyidfp(0);
+       if (hash == "")
+               print("Error: could not retrive hashkey for player (status: ", ftos(crypto_getmyidstatus(0)), ")\n");
+#endif
+       print("Checking for player hashkey: <", hash, "> (playerid=", ftos(p.playerid), ")\n");
+
+       if(uri != "" && hash != "")
        {
-               url_single_fopen(strcat(uri, "/"), FILE_READ, PlayerStatsEntity_ready, p.player_stats);
+               uri = strcat(uri, "/hashkey/", uri_escape(hash));
+               print("Retrieving playerstats from URL: ", uri, "\n");
+               url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);
        }
 }
-*/
-
-#endif // SVQC
index 1cc08854506d67835417ed574ad5caee8039dc05..dcc916e1e011bb84eaac004edba8a1cb0c95fae3 100644 (file)
@@ -56,9 +56,11 @@ void PlayerStats_AddGlobalInfo(entity p);
 // call this at the end of the match
 void PlayerStats_EndMatch(float finished);
 
+#endif //SVQC
 
-//// WIP -zykure
 
-//void PlayerStats_GetPlayerInfo(entity p);
+//// WIP -zykure
 
-#endif //SVQC
+string PlayerInfo_GetItem(entity e, string item_id);
+void PlayerInfo_Init();
+void PlayerInfo_Retrieve(entity p);
index 2c0b1edf38aa33fcd42e6117bf4a5c6c108bd04a..b7810875664ca1216286090531dafdbd822f7267 100644 (file)
@@ -110,5 +110,14 @@ void GameCommand(string theCommand)
                return;
        }
 
+       if(argv(0) == "debugstats")
+       {
+               entity p = spawn();
+               //p.crypto_idfp = "pQBWJrkNzHCMtndkICJacPENGctTNR59rmFS4x91FFo="; // Antibody's hashkey
+               PlayerInfo_Init();
+               PlayerInfo_Retrieve(p);
+               return;
+       }
+
        print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));
 }
index b6ea698cdf7e96352d2af6de20ec0620eddfad75..f0e0bd748baac04bf73039b1e67ef4580986e6c1 100644 (file)
@@ -11,10 +11,10 @@ config.qh
 ../warpzonelib/mathlib.qh
 ../common/util.qh
 ../common/test.qh
-../common/playerstats.qh
 
 oo/base.h
 
+../common/playerstats.qh
 ../common/teams.qh
 ../common/constants.qh
 ../common/mapinfo.qh