From f6234546c16f85a798ddf93de3a7338b0bd6ad4f Mon Sep 17 00:00:00 2001 From: Jan Behrens Date: Sat, 17 Aug 2013 12:44:17 +0200 Subject: [PATCH] Add basic and detailed playerinfo retrieve functions (hashkeys won't work in menuqc?) --- qcsrc/client/Main.qc | 6 ---- qcsrc/common/playerstats.qc | 66 +++++++++++++++++++--------------- qcsrc/common/playerstats.qh | 14 ++++++-- qcsrc/menu/command/menu_cmd.qc | 15 +++++--- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index f6339ac38..9eddcb353 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -156,12 +156,6 @@ 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) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 7389a61ca..d03b51a7b 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -436,7 +436,12 @@ void PlayerStats_EndMatch(float finished) #endif // SVQC -//// WIP -zykure + + +//// WIP -zykure ///////////////////////////////////////////////////// + + + float playerinfo_db; string playerinfo_last; @@ -445,15 +450,11 @@ string playerinfo_events_last; void PlayerInfo_AddPlayer(entity e) { - string s; - if(playerinfo_db < 0) return; - s = sprintf("#%d", e.playerid); - string key; - key = sprintf("%s:*", s); + key = sprintf("#%d:*", e.playerid); // TODO: use hashkey instead? string p; p = db_get(playerinfo_db, key); @@ -467,7 +468,7 @@ void PlayerInfo_AddPlayer(entity e) else db_put(playerinfo_db, key, "#"); playerinfo_last = strzone(ftos(e.playerid)); - print(" Added player ", s, " to playerinfo_db\n"); + print(" Added player ", ftos(e.playerid), " to playerinfo_db\n");//DEBUG// } } @@ -496,7 +497,7 @@ void PlayerInfo_AddItem(entity e, string item_id, string val) key = sprintf("#%d:%s", e.playerid, item_id); db_put(playerinfo_db, key, val); - print("Added event ", key, "=", val, " to playerinfo_db\n"); + print(" Added item ", key, "=", val, " to playerinfo_db\n");//DEBUG// } string PlayerInfo_GetItem(entity e, string item_id) @@ -622,34 +623,43 @@ void PlayerInfo_Init() playerinfo_db = db_create(); } -void PlayerInfo_Retrieve(entity p) +//#ifdef SVQC +void PlayerInfo_Basic(entity p) { if(playerinfo_db < 0) return; - string uri = "", hash = ""; -/* -#ifdef SVQC - uri = autocvar_g_playerstats_uri; - hash = p.crypto_idfp; -#endif -#ifdef CSQC - uri = "http://stats.xonotic.org"; // FIXME! - hash = "pQBWJrkNzHCMtndkICJacPENGctTNR59rmFS4x91FFo="; // FIXME! -#endif -*/ + string uri, hash; + //uri = "http://stats.xonotic.org"; // FIXME! + uri = "http://localhost:6543"; + hash = "pQBWJrkNzHCMtndkICJacPENGctTNR59rmFS4x91FFo="; + + if(uri != "") + { + uri = strcat(uri, "/elo/", uri_escape(hash)); + print("Retrieving playerstats from URL: ", uri, "\n"); + url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p); + } +} +//#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"); +void PlayerInfo_Details() +{ + if(playerinfo_db < 0) + return; - if(uri != "" && hash != "") + string uri; + //uri = "http://stats.xonotic.org"; // FIXME! + uri = "http://localhost:6543"; + + if(uri != "") { - uri = strcat(uri, "/hashkey/", uri_escape(hash)); + entity p = spawn(); + p.playerid = -1; // TODO: okay to use -1 for local player? or does local player already has an entity in MENUQC? + uri = strcat(uri, "/player/me"); print("Retrieving playerstats from URL: ", uri, "\n"); url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p); } } +#endif diff --git a/qcsrc/common/playerstats.qh b/qcsrc/common/playerstats.qh index dcc916e1e..980a4a406 100644 --- a/qcsrc/common/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -59,8 +59,18 @@ void PlayerStats_EndMatch(float finished); #endif //SVQC -//// WIP -zykure + + +//// WIP -zykure ///////////////////////////////////////////////////// + + + string PlayerInfo_GetItem(entity e, string item_id); void PlayerInfo_Init(); -void PlayerInfo_Retrieve(entity p); +//#ifdef SVQC +void PlayerInfo_Basic(entity p); +//#endif +#ifdef MENUQC +void PlayerInfo_Details(); +#endif diff --git a/qcsrc/menu/command/menu_cmd.qc b/qcsrc/menu/command/menu_cmd.qc index b78108756..a8b569cc3 100644 --- a/qcsrc/menu/command/menu_cmd.qc +++ b/qcsrc/menu/command/menu_cmd.qc @@ -110,12 +110,19 @@ void GameCommand(string theCommand) return; } - if(argv(0) == "debugstats") + if(argv(0) == "debugstats_details") { - entity p = spawn(); - //p.crypto_idfp = "pQBWJrkNzHCMtndkICJacPENGctTNR59rmFS4x91FFo="; // Antibody's hashkey PlayerInfo_Init(); - PlayerInfo_Retrieve(p); + PlayerInfo_Details(); + return; + } + + if(argv(0) == "debugstats_basic") + { + entity p = spawn(); + p.playerid = 0; + PlayerInfo_Init(); + PlayerInfo_Basic(p); return; } -- 2.39.2