4 #include "constants.qh"
6 #include "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(world, 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, LAMBDA(
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(); }
169 // add personal score rank
170 PS_GR_P_ADDVAL(p, PLAYERSTATS_RANK, p.score_dummyfield);
175 // scoreboard is valid!
176 PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
178 // add scoreboard position
179 PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
181 // add scoreboard data
182 PlayerScore_PlayerStats(p);
184 // if the match ended normally, add winning info
187 PS_GR_P_ADDVAL(p, PLAYERSTATS_WINS, p.winning);
188 PS_GR_P_ADDVAL(p, PLAYERSTATS_MATCHES, 1);
192 // collect final player information
193 PlayerStats_GameReport_FinalizePlayer(p);
196 if(autocvar_g_playerstats_gamereport_uri != "")
198 PlayerStats_GameReport_DelayMapVote = true;
200 autocvar_g_playerstats_gamereport_uri,
202 PlayerStats_GameReport_Handler,
208 PlayerStats_GameReport_DelayMapVote = false;
209 db_close(PS_GR_OUT_DB);
214 void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that scores are added properly
216 if(autocvar_g_playerstats_gamereport_uri == "") { return; }
218 PS_GR_OUT_DB = db_create();
220 if(PS_GR_OUT_DB >= 0)
222 PlayerStats_GameReport_DelayMapVote = true;
224 serverflags |= SERVERFLAG_PLAYERSTATS;
226 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ALIVETIME);
227 PlayerStats_GameReport_AddEvent(PLAYERSTATS_AVGLATENCY);
228 PlayerStats_GameReport_AddEvent(PLAYERSTATS_WINS);
229 PlayerStats_GameReport_AddEvent(PLAYERSTATS_MATCHES);
230 PlayerStats_GameReport_AddEvent(PLAYERSTATS_JOINS);
231 PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_VALID);
232 PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_POS);
233 PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK);
236 FOREACH(Weapons, it != WEP_Null, LAMBDA(
237 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-hit"));
238 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-fired"));
239 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-hit"));
240 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-fired"));
241 PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-frags"));
244 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3);
245 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5);
246 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10);
247 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15);
248 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20);
249 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25);
250 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30);
251 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_BOTLIKE);
252 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD);
253 PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM);
255 else { PlayerStats_GameReport_DelayMapVote = false; }
258 void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
268 // ======================================
269 // -- OUTGOING GAME REPORT INFORMATION --
270 // ======================================
272 * V: format version (always a fixed number) - this MUST be the first line!
273 * #: comment (MUST be ignored by any parser)
274 * R: release information on the server
276 * O: mod name (icon request) as in server browser
278 * I: match ID (see "matchid" in g_world.qc)
279 * S: "hostname" of the server
280 * C: number of "unpure" cvar changes
281 * U: UDP port number of the server
282 * D: duration of the match
283 * L: "ladder" in which the server is participating in
284 * P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!)
285 * Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!)
287 * n: nickname of the player (optional)
289 * e: followed by an event name, a space, and the event count/score
290 * event names can be:
291 * alivetime: total playing time of the player
292 * avglatency: average network latency compounded throughout the match
293 * wins: number of games won (can only be set if matches is set)
294 * matches: number of matches played to the end (not aborted by map switch)
295 * joins: number of matches joined (always 1 unless player never played during the match)
296 * scoreboardvalid: set to 1 if the player was there at the end of the match
297 * total-<scoreboardname>: total score of that scoreboard item
298 * scoreboard-<scoreboardname>: end-of-game score of that scoreboard item (can differ in non-team games)
299 * achievement-<achievementname>: achievement counters (their "count" is usually 1 if nonzero at all)
300 * kills-<index>: number of kills against the indexed player
301 * rank <number>: rank of player
302 * acc-<weapon netname>-hit: total damage dealt
303 * acc-<weapon netname>-fired: total damage that all fired projectiles *could* have dealt
304 * acc-<weapon netname>-cnt-hit: amount of shots that actually hit
305 * acc-<weapon netname>-cnt-fired: amount of fired shots
306 * acc-<weapon netname>-frags: amount of frags dealt by weapon
308 case URL_READY_CANWRITE:
310 url_fputs(fh, "V 9\n");
312 url_fputs(fh, sprintf("R %s\n", WATERMARK));
314 url_fputs(fh, sprintf("G %s\n", GetGametype()));
315 url_fputs(fh, sprintf("O %s\n", modname));
316 url_fputs(fh, sprintf("M %s\n", GetMapname()));
317 url_fputs(fh, sprintf("I %s\n", matchid));
318 url_fputs(fh, sprintf("S %s\n", cvar_string("hostname")));
319 url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count));
320 url_fputs(fh, sprintf("U %d\n", cvar("port")));
321 url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime)));
322 url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_gamereport_ladder));
327 for(t = PS_GR_OUT_TL; (tn = db_get(PS_GR_OUT_DB, sprintf("%d", stof(t)))) != ""; t = tn)
329 // start team section
330 url_fputs(fh, sprintf("Q team#%s\n", t));
332 // output team events // todo: does this do unnecessary loops? perhaps we should do a separate "team_events_last" tracker..."
333 for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
335 float v = stof(db_get(PS_GR_OUT_DB, sprintf("team#%d:%s", stof(t), e)));
336 if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
342 for(p = PS_GR_OUT_PL; (pn = db_get(PS_GR_OUT_DB, sprintf("%s:*", p))) != ""; p = pn)
344 // start player section
345 url_fputs(fh, sprintf("P %s\n", p));
347 // playerid/index (entity number for this server)
348 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_playerid", p));
349 if(nn != "") { url_fputs(fh, sprintf("i %s\n", nn)); }
352 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_netname", p));
353 if(nn != "") { url_fputs(fh, sprintf("n %s\n", nn)); }
355 // team identification number
358 tt = db_get(PS_GR_OUT_DB, sprintf("%s:_team", p));
359 url_fputs(fh, sprintf("t %s\n", tt));
362 // output player events
363 for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
365 float v = stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p, e)));
366 if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
374 // ======================================
375 // -- INCOMING GAME REPORT INFORMATION --
376 // ======================================
380 case URL_READY_CANREAD:
382 // url_fclose is processing, we got a response for writing the data
383 // this must come from HTTP
384 LOG_TRACE("Got response from player stats server:\n");
385 while((s = url_fgets(fh))) { LOG_TRACE(" ", s, "\n"); }
386 LOG_TRACE("End of response.\n");
391 case URL_READY_CLOSED:
393 // url_fclose has finished
394 LOG_TRACE("Player stats written\n");
395 PlayerStats_GameReport_DelayMapVote = false;
396 if(PS_GR_OUT_DB >= 0)
398 db_close(PS_GR_OUT_DB);
404 case URL_READY_ERROR:
407 LOG_INFO("Player stats writing failed: ", ftos(status), "\n");
408 PlayerStats_GameReport_DelayMapVote = false;
409 if(PS_GR_OUT_DB >= 0)
411 db_close(PS_GR_OUT_DB);
419 void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
421 // http://stats.xonotic.org/player/GgXRw6piDtFIbMArMuiAi8JG4tiin8VLjZgsKB60Uds=/elo.txt
422 if(autocvar_g_playerstats_playerbasic_uri != "")
424 string uri = autocvar_g_playerstats_playerbasic_uri;
425 if(joiningplayer.crypto_idfp != "")
427 // create the database if it doesn't already exist
429 PS_B_IN_DB = db_create();
431 // now request the information
432 uri = strcat(uri, "/player/", uri_escape(uri_escape(joiningplayer.crypto_idfp)), "/elo.txt");
433 LOG_TRACE("Retrieving playerstats from URL: ", uri, "\n");
437 PlayerStats_PlayerBasic_Handler,
441 // set status appropriately // todo: check whether the player info exists in the database previously
444 // database still contains useful information, so don't clear it of a useful status
445 joiningplayer.playerstats_basicstatus = PS_B_STATUS_WAITING;
449 // database was previously empty or never hit received status for some reason
450 joiningplayer.playerstats_basicstatus = PS_B_STATUS_UPDATING;
456 // server has this disabled, kill the DB and set status to idle
459 db_close(PS_B_IN_DB);
462 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(it.playerstats_basicstatus = PS_B_STATUS_IDLE));
467 void PlayerStats_PlayerBasic_CheckUpdate(entity joiningplayer)
469 // determine whether we should retrieve playerbasic information again
472 LOG_INFOF("PlayerStats_PlayerBasic_CheckUpdate('%s'): %f\n",
473 joiningplayer.netname,
478 // TODO: check to see if this playerid is inside the database already somehow...
479 // for now we'll just check the field, but this won't work for players who disconnect and reconnect properly
480 // although maybe we should just submit another request ANYWAY?
481 if(!joiningplayer.playerstats_basicstatus)
483 PlayerStats_PlayerBasic(
485 (joiningplayer.playerstats_basicstatus == PS_B_STATUS_RECEIVED)
490 void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
494 case URL_READY_CANWRITE:
496 LOG_TRACE("-- Sending data to player stats server\n");
497 /*url_fputs(fh, "V 1\n");
499 url_fputs(fh, sprintf("R %s\n", WATERMARK));
501 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
502 url_fputs(fh, sprintf("c %s\n", cvar_string("_menu_prvm_country"))); // country
503 url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
504 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
505 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
506 */url_fputs(fh, "\n");
511 case URL_READY_CANREAD:
514 LOG_TRACE("-- Got response from player stats server:\n");
515 //string gametype = string_null;
516 while((s = url_fgets(fh)))
518 LOG_TRACE(" ", s, "\n");
520 string key = "", value = "", data = "";
522 n = tokenizebyseparator(s, " "); // key (value) data
543 PlayerInfo_AddItem(p, "_version", data);
545 PlayerInfo_AddItem(p, "_release", data);
547 PlayerInfo_AddItem(p, "_time", data);
549 PlayerInfo_AddItem(p, "_statsurl", data);
551 PlayerInfo_AddItem(p, "_hashkey", data);
553 PlayerInfo_AddItem(p, "_playernick", data);
555 PlayerInfo_AddItem(p, "_playerid", data);
558 else if (key == "e" && value != "")
561 PlayerInfo_AddItem(p, value, data);
563 PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data);
569 LOG_TRACE("-- End of response.\n");
573 case URL_READY_CLOSED:
575 // url_fclose has finished
576 LOG_INFO("Player stats synchronized with server\n");
580 case URL_READY_ERROR:
583 LOG_INFO("Receiving player stats failed: ", ftos(status), "\n");
593 #if 0 // reading the entire DB at once
594 string e = "", en = "";
596 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
598 LOG_INFO(sprintf("%d:%s:%s\n", i, e, db_get(PS_D_IN_DB, sprintf("#%s", e))));
603 void PlayerStats_PlayerDetail_AddItem(string event, string data)
605 if(PS_D_IN_DB < 0) { return; }
607 // create a marker for the event so that we can access it later
608 string marker = sprintf("%s", event);
609 if(db_get(PS_D_IN_DB, marker) == "")
613 db_put(PS_D_IN_DB, marker, PS_D_IN_EVL);
614 strunzone(PS_D_IN_EVL);
616 else { db_put(PS_D_IN_DB, marker, "#"); }
617 PS_D_IN_EVL = strzone(marker);
620 // now actually set the event data
621 db_put(PS_D_IN_DB, sprintf("#%s", event), data);
622 LOG_TRACE("Added item ", sprintf("#%s", event), "=", data, " to PS_D_IN_DB\n");
625 void PlayerStats_PlayerDetail()
627 // http://stats.xonotic.org/player/me
628 if((autocvar_g_playerstats_playerdetail_uri != "") && (crypto_getmyidstatus(0) > 0))
630 // create the database if it doesn't already exist
632 PS_D_IN_DB = db_create();
634 //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
635 LOG_TRACE("Retrieving playerstats from URL: ", autocvar_g_playerstats_playerdetail_uri, "\n");
637 autocvar_g_playerstats_playerdetail_uri,
639 PlayerStats_PlayerDetail_Handler,
643 PlayerStats_PlayerDetail_Status = PS_D_STATUS_WAITING;
647 // player has this disabled, kill the DB and set status to idle
650 db_close(PS_D_IN_DB);
654 PlayerStats_PlayerDetail_Status = PS_D_STATUS_IDLE;
658 void PlayerStats_PlayerDetail_CheckUpdate()
660 // determine whether we should retrieve playerdetail information again
661 float gamecount = cvar("cl_matchcount");
664 LOG_INFOF("PlayerStats_PlayerDetail_CheckUpdate(): %f >= %f, %d > %d\n",
673 (time >= PS_D_NEXTUPDATETIME)
675 (gamecount > PS_D_LASTGAMECOUNT)
678 PlayerStats_PlayerDetail();
679 PS_D_NEXTUPDATETIME = (time + autocvar_g_playerstats_playerdetail_autoupdatetime);
680 PS_D_LASTGAMECOUNT = gamecount;
684 void PlayerStats_PlayerDetail_Handler(entity fh, entity unused, float status)
688 case URL_READY_CANWRITE:
690 LOG_TRACE("PlayerStats_PlayerDetail_Handler(): Sending data to player stats server...\n");
691 url_fputs(fh, "V 1\n");
693 url_fputs(fh, sprintf("R %s\n", WATERMARK));
695 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
696 //url_fputs(fh, sprintf("c %s\n", cvar_string("_cl_country"))); // country
697 //url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
698 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
699 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
705 case URL_READY_CANREAD:
707 //print("PlayerStats_PlayerDetail_Handler(): Got response from player stats server:\n");
709 string gametype = "overall";
710 while((input = url_fgets(fh)))
712 float count = tokenizebyseparator(input, " ");
713 string key = "", event = "", data = "";
715 if(argv(0) == "#") { continue; }
720 data = substring(input, argv_start_index(1), strlen(input) - argv_start_index(1));
726 data = substring(input, argv_start_index(2), strlen(input) - argv_start_index(2));
733 case "V": PlayerStats_PlayerDetail_AddItem("version", data); break;
734 case "R": PlayerStats_PlayerDetail_AddItem("release", data); break;
735 case "T": PlayerStats_PlayerDetail_AddItem("time", data); break;
738 case "S": PlayerStats_PlayerDetail_AddItem("statsurl", data); break;
739 case "P": PlayerStats_PlayerDetail_AddItem("hashkey", data); break;
740 case "n": PlayerStats_PlayerDetail_AddItem("playernick", data); break;
741 case "i": PlayerStats_PlayerDetail_AddItem("playerid", data); break;
744 case "G": gametype = data; break;
747 if(event != "" && data != "")
749 PlayerStats_PlayerDetail_AddItem(
764 "PlayerStats_PlayerDetail_Handler(): ERROR: "
765 "Key went unhandled? Is our version outdated?\n"
766 "PlayerStats_PlayerDetail_Handler(): "
767 "Key '%s', Event '%s', Data '%s'\n",
778 "PlayerStats_PlayerDetail_Handler(): "
779 "Key '%s', Event '%s', Data '%s'\n",
786 //print("PlayerStats_PlayerDetail_Handler(): End of response.\n");
788 PlayerStats_PlayerDetail_Status = PS_D_STATUS_RECEIVED;
789 statslist.getStats(statslist);
793 case URL_READY_CLOSED:
795 // url_fclose has finished
796 LOG_INFO("PlayerStats_PlayerDetail_Handler(): Player stats synchronized with server.\n");
800 case URL_READY_ERROR:
803 LOG_INFO("PlayerStats_PlayerDetail_Handler(): Receiving player stats failed: ", ftos(status), "\n");
804 PlayerStats_PlayerDetail_Status = PS_D_STATUS_ERROR;
807 db_close(PS_D_IN_DB);
817 void PlayerInfo_AddPlayer(entity e)
819 if(playerinfo_db < 0)
823 key = sprintf("#%d:*", e.playerid); // TODO: use hashkey instead?
826 p = db_get(playerinfo_db, key);
831 db_put(playerinfo_db, key, playerinfo_last);
832 strunzone(playerinfo_last);
835 db_put(playerinfo_db, key, "#");
836 playerinfo_last = strzone(ftos(e.playerid));
837 print(" Added player ", ftos(e.playerid), " to playerinfo_db\n");//DEBUG//
841 void PlayerInfo_AddItem(entity e, string item_id, string val)
843 if(playerinfo_db < 0)
847 key = sprintf("*:%s", item_id);
850 p = db_get(playerinfo_db, key);
853 if(playerinfo_events_last)
855 db_put(playerinfo_db, key, playerinfo_events_last);
856 strunzone(playerinfo_events_last);
859 db_put(playerinfo_db, key, "#");
860 playerinfo_events_last = strzone(item_id);
863 key = sprintf("#%d:%s", e.playerid, item_id);
864 db_put(playerinfo_db, key, val);
865 print(" Added item ", key, "=", val, " to playerinfo_db\n");//DEBUG//
868 string PlayerInfo_GetItem(entity e, string item_id)
870 if(playerinfo_db < 0)
874 key = sprintf("#%d:%s", e.playerid, item_id);
875 return db_get(playerinfo_db, key);
878 string PlayerInfo_GetItemLocal(string item_id)
882 return PlayerInfo_GetItem(p, item_id);
885 void PlayerInfo_ready(entity fh, entity p, float status)
890 PlayerInfo_AddPlayer(p);
894 case URL_READY_CANWRITE:
895 print("-- Sending data to player stats server\n");
896 url_fputs(fh, "V 1\n");
898 url_fputs(fh, sprintf("R %s\n", WATERMARK));
901 url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
902 url_fputs(fh, sprintf("c %s\n", cvar_string("_menu_prvm_country"))); // country
903 url_fputs(fh, sprintf("g %s\n", cvar_string("_cl_gender"))); // gender
904 url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
905 url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
910 case URL_READY_CANREAD:
911 print("-- Got response from player stats server:\n");
912 string gametype = string_null;
913 while((s = url_fgets(fh)))
917 string key = "", value = "", data = "";
919 n = tokenizebyseparator(s, " "); // key (value) data
940 PlayerInfo_AddItem(p, "_version", data);
942 PlayerInfo_AddItem(p, "_release", data);
944 PlayerInfo_AddItem(p, "_time", data);
946 PlayerInfo_AddItem(p, "_statsurl", data);
948 PlayerInfo_AddItem(p, "_hashkey", data);
950 PlayerInfo_AddItem(p, "_playernick", data);
952 PlayerInfo_AddItem(p, "_playerid", data);
955 else if (key == "e" && value != "")
958 PlayerInfo_AddItem(p, value, data);
960 PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data);
965 print("-- End of response.\n");
968 case URL_READY_CLOSED:
969 // url_fclose has finished
970 print("Player stats synchronized with server\n");
972 case URL_READY_ERROR:
974 print("Receiving player stats failed: ", ftos(status), "\n");
979 void PlayerInfo_Init()
981 playerinfo_db = db_create();
985 void PlayerInfo_Basic(entity p)
987 print("-- Getting basic PlayerInfo for player ",ftos(p.playerid)," (SVQC)\n");
989 if(playerinfo_db < 0)
993 uri = autocvar_g_playerinfo_uri;
994 if(uri != "" && p.crypto_idfp != "")
996 uri = strcat(uri, "/elo/", uri_escape(p.crypto_idfp));
997 print("Retrieving playerstats from URL: ", uri, "\n");
998 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);
1004 void PlayerInfo_Details()
1006 print("-- Getting detailed PlayerInfo for local player (MENUQC)\n");
1008 if(playerinfo_db < 0)
1012 uri = autocvar_g_playerinfo_uri; // FIXME
1013 if(uri != "" && crypto_getmyidstatus(0) > 0)
1015 //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
1016 uri = strcat(uri, "/player/me");
1017 print("Retrieving playerstats from URL: ", uri, "\n");
1018 url_single_fopen(uri, FILE_APPEND, PlayerInfo_ready, world);
1024 // FIXME - crypto_* builtin functions missing in CSQC (csprogsdefs.qh:885)
1025 void PlayerInfo_Details()
1027 print("-- Getting detailed PlayerInfo for local player (CSQC)\n");
1029 if(playerinfo_db < 0)
1033 uri = autocvar_g_playerinfo_uri; // FIXME
1034 if(uri != "" && crypto_getmyidstatus(0) > 0)
1036 uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
1037 print("Retrieving playerstats from URL: ", uri, "\n");
1038 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);