4 #include "constants.qh"
6 #include <common/weapons/all.qh>
7 #include "../server/weapons/accuracy.qh"
8 #include "../server/defs.qh"
9 #include "playerstats.qh"
10 #include "../server/scores.qh"
14 void PlayerStats_Prematch()
19 void PlayerStats_GameReport_AddPlayer(entity e)
21 if((PS_GR_OUT_DB < 0) || (e.playerstats_id)) { return; }
23 // set up player identification
24 string s = string_null;
26 if((e.crypto_idfp != "") && (e.cvar_cl_allow_uidtracking == 1))
27 { s = e.crypto_idfp; }
28 else if(IS_BOT_CLIENT(e))
29 { s = sprintf("bot#%g#%s", skill, e.cleanname); }
31 if((s == "") || find(NULL, playerstats_id, s)) // already have one of the ID - next one can't be tracked then!
34 { s = sprintf("bot#%d", e.playerid); }
36 { s = sprintf("player#%d", e.playerid); }
39 e.playerstats_id = strzone(s);
41 // now add the player to the database
42 string key = sprintf("%s:*", e.playerstats_id);
43 string p = db_get(PS_GR_OUT_DB, key);
49 db_put(PS_GR_OUT_DB, key, PS_GR_OUT_PL);
50 strunzone(PS_GR_OUT_PL);
52 else { db_put(PS_GR_OUT_DB, key, "#"); }
53 PS_GR_OUT_PL = strzone(e.playerstats_id);
57 void PlayerStats_GameReport_AddTeam(float t)
59 if(PS_GR_OUT_DB < 0) { return; }
61 string key = sprintf("%d", t);
62 string p = db_get(PS_GR_OUT_DB, key);
68 db_put(PS_GR_OUT_DB, key, PS_GR_OUT_TL);
69 strunzone(PS_GR_OUT_TL);
71 else { db_put(PS_GR_OUT_DB, key, "#"); }
72 PS_GR_OUT_TL = strzone(key);
76 void PlayerStats_GameReport_AddEvent(string event_id)
78 if(PS_GR_OUT_DB < 0) { return; }
80 string key = sprintf("*:%s", event_id);
81 string p = db_get(PS_GR_OUT_DB, key);
87 db_put(PS_GR_OUT_DB, key, PS_GR_OUT_EVL);
88 strunzone(PS_GR_OUT_EVL);
90 else { db_put(PS_GR_OUT_DB, key, "#"); }
91 PS_GR_OUT_EVL = strzone(event_id);
95 // referred to by PS_GR_P_ADDVAL and PS_GR_T_ADDVAL
96 float PlayerStats_GameReport_Event(string prefix, string event_id, float value)
98 if((prefix == "") || PS_GR_OUT_DB < 0) { return 0; }
100 string key = sprintf("%s:%s", prefix, event_id);
101 float val = stof(db_get(PS_GR_OUT_DB, key));
103 db_put(PS_GR_OUT_DB, key, ftos(val));
107 void PlayerStats_GameReport_Accuracy(entity p)
109 #define ACCMAC(suffix, field) \
110 PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", it.netname, suffix), p.accuracy.(field[i-1]));
111 FOREACH(Weapons, it != WEP_Null, {
112 ACCMAC("hit", accuracy_hit)
113 ACCMAC("fired", accuracy_fired)
114 ACCMAC("cnt-hit", accuracy_cnt_hit)
115 ACCMAC("cnt-fired", accuracy_cnt_fired)
116 ACCMAC("frags", accuracy_frags)
121 void PlayerStats_GameReport_FinalizePlayer(entity p)
123 if((p.playerstats_id == "") || PS_GR_OUT_DB < 0) { return; }
128 PS_GR_P_ADDVAL(p, PLAYERSTATS_ALIVETIME, time - p.alivetime);
132 db_put(PS_GR_OUT_DB, sprintf("%s:_playerid", p.playerstats_id), ftos(p.playerid));
134 if(p.cvar_cl_allow_uid2name == 1 || IS_BOT_CLIENT(p))
135 db_put(PS_GR_OUT_DB, sprintf("%s:_netname", p.playerstats_id), p.netname);
138 db_put(PS_GR_OUT_DB, sprintf("%s:_team", p.playerstats_id), ftos(p.team));
140 if(stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p.playerstats_id, PLAYERSTATS_ALIVETIME))) > 0)
141 PS_GR_P_ADDVAL(p, PLAYERSTATS_JOINS, 1);
143 PlayerStats_GameReport_Accuracy(p);
145 if(IS_REAL_CLIENT(p))
149 float latency = (p.latency_sum / p.latency_cnt);
150 if(latency) { PS_GR_P_ADDVAL(p, PLAYERSTATS_AVGLATENCY, latency); }
154 strunzone(p.playerstats_id);
155 p.playerstats_id = string_null;
158 void PlayerStats_GameReport(float finished)
160 if(PS_GR_OUT_DB < 0) { return; }
162 PlayerScore_Sort(score_dummyfield, 0, 0, 0);
163 PlayerScore_Sort(scoreboard_pos, 1, 1, 1);
164 if(teamplay) { PlayerScore_TeamStats(); }
166 FOREACH_CLIENT(true, {
167 // add personal score rank
168 PS_GR_P_ADDVAL(it, PLAYERSTATS_RANK, it.score_dummyfield);
171 if(it.scoreboard_pos)
173 // scoreboard is valid!
174 PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_VALID, 1);
176 // add scoreboard position
177 PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_POS, it.scoreboard_pos);
179 // add scoreboard data
180 PlayerScore_PlayerStats(it);
182 // if the match ended normally, add winning info
185 PS_GR_P_ADDVAL(it, PLAYERSTATS_WINS, it.winning);
186 PS_GR_P_ADDVAL(it, PLAYERSTATS_MATCHES, 1);
190 // collect final player information
191 PlayerStats_GameReport_FinalizePlayer(it);
194 if(autocvar_g_playerstats_gamereport_uri != "")
196 PlayerStats_GameReport_DelayMapVote = true;
198 autocvar_g_playerstats_gamereport_uri,
200 PlayerStats_GameReport_Handler,
206 PlayerStats_GameReport_DelayMapVote = false;
207 db_close(PS_GR_OUT_DB);
212 void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that scores are added properly
214 if(autocvar_g_playerstats_gamereport_uri == "") { return; }
216 PS_GR_OUT_DB = db_create();
218 if(PS_GR_OUT_DB >= 0)
220 PlayerStats_GameReport_DelayMapVote = true;
222 serverflags |= SERVERFLAG_PLAYERSTATS;
224 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ALIVETIME);
225 PlayerStats_GameReport_AddEvent(PLAYERSTATS_AVGLATENCY);
226 PlayerStats_GameReport_AddEvent(PLAYERSTATS_WINS);
227 PlayerStats_GameReport_AddEvent(PLAYERSTATS_MATCHES);
228 PlayerStats_GameReport_AddEvent(PLAYERSTATS_JOINS);
229 PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_VALID);
230 PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_POS);
231 PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK);
234 FOREACH(Weapons, it != WEP_Null, {
235 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-hit"));
236 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-fired"));
237 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-hit"));
238 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-fired"));
239 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-frags"));
242 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3);
243 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5);
244 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10);
245 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15);
246 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20);
247 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25);
248 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30);
249 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_BOTLIKE);
250 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD);
251 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM);
253 else { PlayerStats_GameReport_DelayMapVote = false; }
256 void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
266 // ======================================
267 // -- OUTGOING GAME REPORT INFORMATION --
268 // ======================================
270 * V: format version (always a fixed number) - this MUST be the first line!
271 * #: comment (MUST be ignored by any parser)
272 * R: release information on the server
274 * O: mod name (icon request) as in server browser
276 * I: match ID (see "matchid" in g_world.qc)
277 * S: "hostname" of the server
278 * C: number of "unpure" cvar changes
279 * U: UDP port number of the server
280 * D: duration of the match
281 * L: "ladder" in which the server is participating in
282 * P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!)
283 * Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!)
285 * n: nickname of the player (optional)
287 * e: followed by an event name, a space, and the event count/score
288 * event names can be:
289 * alivetime: total playing time of the player
290 * avglatency: average network latency compounded throughout the match
291 * wins: number of games won (can only be set if matches is set)
292 * matches: number of matches played to the end (not aborted by map switch)
293 * joins: number of matches joined (always 1 unless player never played during the match)
294 * scoreboardvalid: set to 1 if the player was there at the end of the match
295 * total-<scoreboardname>: total score of that scoreboard item
296 * scoreboard-<scoreboardname>: end-of-game score of that scoreboard item (can differ in non-team games)
297 * achievement-<achievementname>: achievement counters (their "count" is usually 1 if nonzero at all)
298 * kills-<index>: number of kills against the indexed player
299 * rank <number>: rank of player
300 * acc-<weapon netname>-hit: total damage dealt
301 * acc-<weapon netname>-fired: total damage that all fired projectiles *could* have dealt
302 * acc-<weapon netname>-cnt-hit: amount of shots that actually hit
303 * acc-<weapon netname>-cnt-fired: amount of fired shots
304 * acc-<weapon netname>-frags: amount of frags dealt by weapon
306 case URL_READY_CANWRITE:
308 url_fputs(fh, "V 9\n");
310 url_fputs(fh, sprintf("R %s\n", WATERMARK));
312 url_fputs(fh, sprintf("G %s\n", GetGametype()));
313 url_fputs(fh, sprintf("O %s\n", modname));
314 url_fputs(fh, sprintf("M %s\n", GetMapname()));
315 url_fputs(fh, sprintf("I %s\n", matchid));
316 url_fputs(fh, sprintf("S %s\n", cvar_string("hostname")));
317 url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count));
318 url_fputs(fh, sprintf("U %d\n", cvar("port")));
319 url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime)));
320 url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_gamereport_ladder));
325 for(t = PS_GR_OUT_TL; (tn = db_get(PS_GR_OUT_DB, sprintf("%d", stof(t)))) != ""; t = tn)
327 // start team section
328 url_fputs(fh, sprintf("Q team#%s\n", t));
330 // output team events // todo: does this do unnecessary loops? perhaps we should do a separate "team_events_last" tracker..."
331 for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
333 float v = stof(db_get(PS_GR_OUT_DB, sprintf("team#%d:%s", stof(t), e)));
334 if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
340 for(p = PS_GR_OUT_PL; (pn = db_get(PS_GR_OUT_DB, sprintf("%s:*", p))) != ""; p = pn)
342 // start player section
343 url_fputs(fh, sprintf("P %s\n", p));
345 // playerid/index (entity number for this server)
346 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_playerid", p));
347 if(nn != "") { url_fputs(fh, sprintf("i %s\n", nn)); }
350 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_netname", p));
351 if(nn != "") { url_fputs(fh, sprintf("n %s\n", nn)); }
353 // team identification number
356 tt = db_get(PS_GR_OUT_DB, sprintf("%s:_team", p));
357 url_fputs(fh, sprintf("t %s\n", tt));
360 // output player events
361 for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
363 float v = stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p, e)));
364 if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
372 // ======================================
373 // -- INCOMING GAME REPORT INFORMATION --
374 // ======================================
378 case URL_READY_CANREAD:
380 // url_fclose is processing, we got a response for writing the data
381 // this must come from HTTP
382 LOG_TRACE("Got response from player stats server:\n");
383 while((s = url_fgets(fh))) { LOG_TRACE(" ", s, "\n"); }
384 LOG_TRACE("End of response.\n");
389 case URL_READY_CLOSED:
391 // url_fclose has finished
392 LOG_TRACE("Player stats written\n");
393 PlayerStats_GameReport_DelayMapVote = false;
394 if(PS_GR_OUT_DB >= 0)
396 db_close(PS_GR_OUT_DB);
402 case URL_READY_ERROR:
405 LOG_INFO("Player stats writing failed: ", ftos(status), "\n");
406 PlayerStats_GameReport_DelayMapVote = false;
407 if(PS_GR_OUT_DB >= 0)
409 db_close(PS_GR_OUT_DB);
417 void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
419 // http://stats.xonotic.org/player/GgXRw6piDtFIbMArMuiAi8JG4tiin8VLjZgsKB60Uds=/elo.txt
420 if(autocvar_g_playerstats_playerbasic_uri != "")
422 string uri = autocvar_g_playerstats_playerbasic_uri;
423 if(joiningplayer.crypto_idfp != "")
425 // create the database if it doesn't already exist
427 PS_B_IN_DB = db_create();
429 // now request the information
430 uri = strcat(uri, "/player/", uri_escape(uri_escape(uri_escape(joiningplayer.crypto_idfp))), "/elo.txt");
431 LOG_TRACE("Retrieving playerstats from URL: ", uri, "\n");
435 PlayerStats_PlayerBasic_Handler,
439 // set status appropriately // todo: check whether the player info exists in the database previously
442 // database still contains useful information, so don't clear it of a useful status
443 joiningplayer.playerstats_basicstatus = PS_B_STATUS_WAITING;
447 // database was previously empty or never hit received status for some reason
448 joiningplayer.playerstats_basicstatus = PS_B_STATUS_UPDATING;
454 // server has this disabled, kill the DB and set status to idle
457 db_close(PS_B_IN_DB);
460 FOREACH_CLIENT(IS_REAL_CLIENT(it), it.playerstats_basicstatus = PS_B_STATUS_IDLE);
465 void PlayerStats_PlayerBasic_CheckUpdate(entity joiningplayer)
467 // determine whether we should retrieve playerbasic information again
470 LOG_INFOF("PlayerStats_PlayerBasic_CheckUpdate('%s'): %f\n",
471 joiningplayer.netname,
476 // TODO: check to see if this playerid is inside the database already somehow...
477 // for now we'll just check the field, but this won't work for players who disconnect and reconnect properly
478 // although maybe we should just submit another request ANYWAY?
479 if(!joiningplayer.playerstats_basicstatus)
481 PlayerStats_PlayerBasic(
483 (joiningplayer.playerstats_basicstatus == PS_B_STATUS_RECEIVED)
488 void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
492 case URL_READY_CANWRITE:
494 LOG_TRACE("-- Sending data to player stats server\n");
495 /*url_fputs(fh, "V 1\n");
497 url_fputs(fh, sprintf("R %s\n", WATERMARK));
499 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
500 url_fputs(fh, sprintf("c %s\n", cvar_string("_menu_prvm_country"))); // country
501 url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
502 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
503 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
504 */url_fputs(fh, "\n");
509 case URL_READY_CANREAD:
512 LOG_TRACE("-- Got response from player stats server:\n");
513 //string gametype = string_null;
514 while((s = url_fgets(fh)))
516 LOG_TRACE(" ", s, "\n");
518 string key = "", value = "", data = "";
520 n = tokenizebyseparator(s, " "); // key (value) data
541 PlayerInfo_AddItem(p, "_version", data);
543 PlayerInfo_AddItem(p, "_release", data);
545 PlayerInfo_AddItem(p, "_time", data);
547 PlayerInfo_AddItem(p, "_statsurl", data);
549 PlayerInfo_AddItem(p, "_hashkey", data);
551 PlayerInfo_AddItem(p, "_playernick", data);
553 PlayerInfo_AddItem(p, "_playerid", data);
556 else if (key == "e" && value != "")
559 PlayerInfo_AddItem(p, value, data);
561 PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data);
567 LOG_TRACE("-- End of response.\n");
571 case URL_READY_CLOSED:
573 // url_fclose has finished
574 LOG_INFO("Player stats synchronized with server\n");
578 case URL_READY_ERROR:
581 LOG_INFO("Receiving player stats failed: ", ftos(status), "\n");
591 #if 0 // reading the entire DB at once
592 string e = "", en = "";
594 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
596 LOG_INFO(sprintf("%d:%s:%s\n", i, e, db_get(PS_D_IN_DB, sprintf("#%s", e))));
601 void PlayerStats_PlayerDetail_AddItem(string event, string data)
603 if(PS_D_IN_DB < 0) { return; }
605 // create a marker for the event so that we can access it later
606 string marker = sprintf("%s", event);
607 if(db_get(PS_D_IN_DB, marker) == "")
611 db_put(PS_D_IN_DB, marker, PS_D_IN_EVL);
612 strunzone(PS_D_IN_EVL);
614 else { db_put(PS_D_IN_DB, marker, "#"); }
615 PS_D_IN_EVL = strzone(marker);
618 // now actually set the event data
619 db_put(PS_D_IN_DB, sprintf("#%s", event), data);
620 LOG_TRACE("Added item ", sprintf("#%s", event), "=", data, " to PS_D_IN_DB\n");
623 void PlayerStats_PlayerDetail()
625 // http://stats.xonotic.org/player/me
626 if((autocvar_g_playerstats_playerdetail_uri != "") && (crypto_getmyidstatus(0) > 0))
628 // create the database if it doesn't already exist
630 PS_D_IN_DB = db_create();
632 //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
633 LOG_TRACE("Retrieving playerstats from URL: ", autocvar_g_playerstats_playerdetail_uri, "\n");
635 autocvar_g_playerstats_playerdetail_uri,
637 PlayerStats_PlayerDetail_Handler,
641 PlayerStats_PlayerDetail_Status = PS_D_STATUS_WAITING;
645 // player has this disabled, kill the DB and set status to idle
648 db_close(PS_D_IN_DB);
652 PlayerStats_PlayerDetail_Status = PS_D_STATUS_IDLE;
656 void PlayerStats_PlayerDetail_CheckUpdate()
658 // determine whether we should retrieve playerdetail information again
659 float gamecount = cvar("cl_matchcount");
662 LOG_INFOF("PlayerStats_PlayerDetail_CheckUpdate(): %f >= %f, %d > %d\n",
671 (time >= PS_D_NEXTUPDATETIME)
673 (gamecount > PS_D_LASTGAMECOUNT)
676 PlayerStats_PlayerDetail();
677 PS_D_NEXTUPDATETIME = (time + autocvar_g_playerstats_playerdetail_autoupdatetime);
678 PS_D_LASTGAMECOUNT = gamecount;
682 void PlayerStats_PlayerDetail_Handler(entity fh, entity unused, float status)
686 case URL_READY_CANWRITE:
688 LOG_TRACE("PlayerStats_PlayerDetail_Handler(): Sending data to player stats server...\n");
689 url_fputs(fh, "V 1\n");
691 url_fputs(fh, sprintf("R %s\n", WATERMARK));
693 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
694 //url_fputs(fh, sprintf("c %s\n", cvar_string("_cl_country"))); // country
695 //url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
696 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
697 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
703 case URL_READY_CANREAD:
705 //print("PlayerStats_PlayerDetail_Handler(): Got response from player stats server:\n");
707 string gametype = "overall";
708 while((input = url_fgets(fh)))
710 float count = tokenizebyseparator(input, " ");
711 string key = "", event = "", data = "";
713 if(argv(0) == "#") { continue; }
718 data = substring(input, argv_start_index(1), strlen(input) - argv_start_index(1));
724 data = substring(input, argv_start_index(2), strlen(input) - argv_start_index(2));
731 case "V": PlayerStats_PlayerDetail_AddItem("version", data); break;
732 case "R": PlayerStats_PlayerDetail_AddItem("release", data); break;
733 case "T": PlayerStats_PlayerDetail_AddItem("time", data); break;
736 case "S": PlayerStats_PlayerDetail_AddItem("statsurl", data); break;
737 case "P": PlayerStats_PlayerDetail_AddItem("hashkey", data); break;
738 case "n": PlayerStats_PlayerDetail_AddItem("playernick", data); break;
739 case "i": PlayerStats_PlayerDetail_AddItem("playerid", data); break;
742 case "G": gametype = data; break;
745 if(event != "" && data != "")
747 PlayerStats_PlayerDetail_AddItem(
762 "PlayerStats_PlayerDetail_Handler(): ERROR: "
763 "Key went unhandled? Is our version outdated?\n"
764 "PlayerStats_PlayerDetail_Handler(): "
765 "Key '%s', Event '%s', Data '%s'\n",
776 "PlayerStats_PlayerDetail_Handler(): "
777 "Key '%s', Event '%s', Data '%s'\n",
784 //print("PlayerStats_PlayerDetail_Handler(): End of response.\n");
786 PlayerStats_PlayerDetail_Status = PS_D_STATUS_RECEIVED;
787 statslist.getStats(statslist);
791 case URL_READY_CLOSED:
793 // url_fclose has finished
794 LOG_INFO("PlayerStats_PlayerDetail_Handler(): Player stats synchronized with server.\n");
798 case URL_READY_ERROR:
801 LOG_INFO("PlayerStats_PlayerDetail_Handler(): Receiving player stats failed: ", ftos(status), "\n");
802 PlayerStats_PlayerDetail_Status = PS_D_STATUS_ERROR;
805 db_close(PS_D_IN_DB);
815 void PlayerInfo_AddPlayer(entity e)
817 if(playerinfo_db < 0)
821 key = sprintf("#%d:*", e.playerid); // TODO: use hashkey instead?
824 p = db_get(playerinfo_db, key);
829 db_put(playerinfo_db, key, playerinfo_last);
830 strunzone(playerinfo_last);
833 db_put(playerinfo_db, key, "#");
834 playerinfo_last = strzone(ftos(e.playerid));
835 print(" Added player ", ftos(e.playerid), " to playerinfo_db\n");//DEBUG//
839 void PlayerInfo_AddItem(entity e, string item_id, string val)
841 if(playerinfo_db < 0)
845 key = sprintf("*:%s", item_id);
848 p = db_get(playerinfo_db, key);
851 if(playerinfo_events_last)
853 db_put(playerinfo_db, key, playerinfo_events_last);
854 strunzone(playerinfo_events_last);
857 db_put(playerinfo_db, key, "#");
858 playerinfo_events_last = strzone(item_id);
861 key = sprintf("#%d:%s", e.playerid, item_id);
862 db_put(playerinfo_db, key, val);
863 print(" Added item ", key, "=", val, " to playerinfo_db\n");//DEBUG//
866 string PlayerInfo_GetItem(entity e, string item_id)
868 if(playerinfo_db < 0)
872 key = sprintf("#%d:%s", e.playerid, item_id);
873 return db_get(playerinfo_db, key);
876 string PlayerInfo_GetItemLocal(string item_id)
880 return PlayerInfo_GetItem(p, item_id);
883 void PlayerInfo_ready(entity fh, entity p, float status)
888 PlayerInfo_AddPlayer(p);
892 case URL_READY_CANWRITE:
893 print("-- Sending data to player stats server\n");
894 url_fputs(fh, "V 1\n");
896 url_fputs(fh, sprintf("R %s\n", WATERMARK));
899 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
900 url_fputs(fh, sprintf("c %s\n", cvar_string("_menu_prvm_country"))); // country
901 url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
902 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
903 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
908 case URL_READY_CANREAD:
909 print("-- Got response from player stats server:\n");
910 string gametype = string_null;
911 while((s = url_fgets(fh)))
915 string key = "", value = "", data = "";
917 n = tokenizebyseparator(s, " "); // key (value) data
938 PlayerInfo_AddItem(p, "_version", data);
940 PlayerInfo_AddItem(p, "_release", data);
942 PlayerInfo_AddItem(p, "_time", data);
944 PlayerInfo_AddItem(p, "_statsurl", data);
946 PlayerInfo_AddItem(p, "_hashkey", data);
948 PlayerInfo_AddItem(p, "_playernick", data);
950 PlayerInfo_AddItem(p, "_playerid", data);
953 else if (key == "e" && value != "")
956 PlayerInfo_AddItem(p, value, data);
958 PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data);
963 print("-- End of response.\n");
966 case URL_READY_CLOSED:
967 // url_fclose has finished
968 print("Player stats synchronized with server\n");
970 case URL_READY_ERROR:
972 print("Receiving player stats failed: ", ftos(status), "\n");
977 void PlayerInfo_Init()
979 playerinfo_db = db_create();
983 void PlayerInfo_Basic(entity p)
985 print("-- Getting basic PlayerInfo for player ",ftos(p.playerid)," (SVQC)\n");
987 if(playerinfo_db < 0)
991 uri = autocvar_g_playerinfo_uri;
992 if(uri != "" && p.crypto_idfp != "")
994 uri = strcat(uri, "/elo/", uri_escape(p.crypto_idfp));
995 print("Retrieving playerstats from URL: ", uri, "\n");
996 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);
1002 void PlayerInfo_Details()
1004 print("-- Getting detailed PlayerInfo for local player (MENUQC)\n");
1006 if(playerinfo_db < 0)
1010 uri = autocvar_g_playerinfo_uri; // FIXME
1011 if(uri != "" && crypto_getmyidstatus(0) > 0)
1013 //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
1014 uri = strcat(uri, "/player/me");
1015 print("Retrieving playerstats from URL: ", uri, "\n");
1016 url_single_fopen(uri, FILE_APPEND, PlayerInfo_ready, NULL);
1022 // FIXME - crypto_* builtin functions missing in CSQC (csprogsdefs.qh:885)
1023 void PlayerInfo_Details()
1025 print("-- Getting detailed PlayerInfo for local player (CSQC)\n");
1027 if(playerinfo_db < 0)
1031 uri = autocvar_g_playerinfo_uri; // FIXME
1032 if(uri != "" && crypto_getmyidstatus(0) > 0)
1034 uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
1035 print("Retrieving playerstats from URL: ", uri, "\n");
1036 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);