]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/playerstats.qc
Add comments for later reference
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / playerstats.qc
1 #ifdef SVQC
2 float PS_PM_IN_DB;   // playerstats_prematch_in_db      // db for info COLLECTED at the beginning of a match
3 float PS_GR_OUT_DB;  // playerstats_gamereport_out_db   // db of info SENT at the end of a match
4 float PS_GR_IN_DB;   // playerstats_gamereport_in_db    // db for info COLLECTED at the end of a match
5 float PS_B_IN_DB;    // playerstats_playerbasic_in_db   // db for info COLLECTED for basic player info (ELO)
6 // http://stats.xonotic.org/player/GgXRw6piDtFIbMArMuiAi8JG4tiin8VLjZgsKB60Uds=/elo.txt
7 #endif
8
9 #ifdef MENUQC
10 float PS_D_IN_DB; // playerstats_playerdetail_in_db  // db for info COLLECTED for detailed player profile display
11 // http://stats.xonotic.org/player/me
12 #endif
13
14 #ifdef SVQC
15 string PS_PM_IN_EVL;   // playerstats_prematch_in_events_last
16 string PS_GR_OUT_TL;   // playerstats_gamereport_out_teams_last
17 string PS_GR_OUT_PL;   // playerstats_gamereport_out_players_las
18 string PS_GR_OUT_EVL;  // playerstats_gamereport_out_events_last
19 string PS_GR_IN_PL;    // playerstats_gamereport_in_players_last
20 string PS_GR_IN_EVL;   // playerstats_gamereport_in_events_last
21 string PS_B_IN_PL;     // playerstats_playerbasic_in_players_las
22 string PS_B_IN_EVL;    // playerstats_playerbasic_in_events_last
23 #endif
24
25 #ifdef MENUQC
26 string PS_D_IN_EVL; // playerstats_playerdetail_in_events_last
27 #endif
28
29 #ifdef SVQC
30 void PlayerStats_Prematch(void)
31 {
32         //foobar
33 }
34
35 .string playerstats_id;
36
37 void PlayerStats_GameReport_AddPlayer(entity e)
38 {
39         string s;
40
41         if(PS_GR_OUT_DB < 0) { return; }
42         if(e.playerstats_id) { return; }
43
44         s = string_null;
45         if(e.crypto_idfp != "" && e.cvar_cl_allow_uidtracking == 1)
46                 { s = e.crypto_idfp; }
47         else if(IS_BOT_CLIENT(e))
48                 { s = sprintf("bot#%g#%s", skill, e.cleanname); }
49
50         if((s == "") || find(world, playerstats_id, s)) // already have one of the ID - next one can't be tracked then!
51         {
52                 if(IS_BOT_CLIENT(e))
53                         { s = sprintf("bot#%d", e.playerid); }
54                 else
55                         { s = sprintf("player#%d", e.playerid); }
56         }
57
58         e.playerstats_id = strzone(s);
59
60         string key = sprintf("%s:*", e.playerstats_id);
61         string p = db_get(PS_GR_OUT_DB, key);
62         
63         if(p == "")
64         {
65                 if(PS_GR_OUT_PL)
66                 {
67                         db_put(PS_GR_OUT_DB, key, PS_GR_OUT_PL);
68                         strunzone(PS_GR_OUT_PL);
69                 }
70                 else { db_put(PS_GR_OUT_DB, key, "#"); }
71                 PS_GR_OUT_PL = strzone(e.playerstats_id);
72         }
73 }
74
75 void PlayerStats_GameReport_AddTeam(float t)
76 {
77         if(PS_GR_OUT_DB < 0) { return; }
78
79         string key = sprintf("%d", t);
80         string p = db_get(PS_GR_OUT_DB, key);
81         
82         if(p == "")
83         {
84                 if(PS_GR_OUT_TL)
85                 {
86                         db_put(PS_GR_OUT_DB, key, PS_GR_OUT_TL);
87                         strunzone(PS_GR_OUT_TL);
88                 }
89                 else { db_put(PS_GR_OUT_DB, key, "#"); }
90                 PS_GR_OUT_TL = strzone(key);
91         }
92 }
93
94 void PlayerStats_GameReport_AddEvent(string event_id)
95 {
96         if(PS_GR_OUT_DB < 0) { return; }
97
98         string key = sprintf("*:%s", event_id);
99         string p = db_get(PS_GR_OUT_DB, key);
100         
101         if(p == "")
102         {
103                 if(PS_GR_OUT_EVL)
104                 {
105                         db_put(PS_GR_OUT_DB, key, PS_GR_OUT_EVL);
106                         strunzone(PS_GR_OUT_EVL);
107                 }
108                 else { db_put(PS_GR_OUT_DB, key, "#"); }
109                 PS_GR_OUT_EVL = strzone(event_id);
110         }
111 }
112 #define PS_GR_P_ADDVAL(ent,eventid,val) PlayerStats_GameReport_Event(ent.playerstats_id, eventid, val)
113 #define PS_GR_T_ADDVAL(team,eventid,val) PlayerStats_GameReport_Event(sprintf("team#%d", team), eventid, val)
114 // referred to by PS_GR_P_ADDVAL and PS_GR_T_ADDVAL
115 float PlayerStats_GameReport_Event(string prefix, string event_id, float value)
116 {
117         if((prefix == "") || PS_GR_OUT_DB < 0) { return 0; }
118
119         string key = sprintf("%s:%s", prefix, event_id);
120         float val = stof(db_get(PS_GR_OUT_DB, key));
121         val += value;
122         db_put(PS_GR_OUT_DB, key, ftos(val));
123         return val;
124 }
125
126 void PlayerStats_GameReport_Accuracy(entity p)
127 {
128     entity w;
129     float i;
130
131         #define PAC p.accuracy
132     for(i = WEP_FIRST; i <= WEP_LAST; ++i)
133     {
134         w = get_weaponinfo(i);
135         PS_GR_P_ADDVAL(p, strcat("acc-", w.netname, "-hit"), PAC.(accuracy_hit[i-1]));
136         PS_GR_P_ADDVAL(p, strcat("acc-", w.netname, "-fired"), PAC.(accuracy_fired[i-1]));
137         PS_GR_P_ADDVAL(p, strcat("acc-", w.netname, "-cnt-hit"), PAC.(accuracy_cnt_hit[i-1]));
138         PS_GR_P_ADDVAL(p, strcat("acc-", w.netname, "-cnt-fired"), PAC.(accuracy_cnt_fired[i-1]));
139         PS_GR_P_ADDVAL(p, strcat("acc-", w.netname, "-frags"), PAC.(accuracy_frags[i-1]));
140     }
141     #undef PAC
142 }
143
144 void PlayerStats_GameReport_AddGlobalInfo(entity p)
145 {
146         if((p.playerstats_id == "") || PS_GR_OUT_DB < 0) { return; }
147
148         // add global info!
149         if(p.alivetime)
150         {
151                 PS_GR_P_ADDVAL(p, PLAYERSTATS_ALIVETIME, time - p.alivetime);
152                 p.alivetime = 0;
153         }
154
155         db_put(PS_GR_OUT_DB, sprintf("%s:_playerid", p.playerstats_id), ftos(p.playerid));
156
157         if(p.cvar_cl_allow_uid2name == 1 || IS_BOT_CLIENT(p))
158                 db_put(PS_GR_OUT_DB, sprintf("%s:_netname", p.playerstats_id), p.netname);
159
160         if(teamplay)
161                 db_put(PS_GR_OUT_DB, sprintf("%s:_team", p.playerstats_id), ftos(p.team));
162
163         if(stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p.playerstats_id, PLAYERSTATS_ALIVETIME))) > 0)
164                 PS_GR_P_ADDVAL(p, PLAYERSTATS_JOINS, 1);
165
166         PlayerStats_Accuracy(p);
167
168         if(IS_REAL_CLIENT(p))
169         {
170                 if(p.latency_cnt)
171                 {
172                         float latency = (p.latency_sum / p.latency_cnt);
173                         if(latency) { PS_GR_P_ADDVAL(p, PLAYERSTATS_AVGLATENCY, latency); }
174                 }
175         }
176
177         strunzone(p.playerstats_id);
178         p.playerstats_id = string_null;
179 }
180
181 .float scoreboard_pos;
182 void PlayerStats_GameReport_EndMatch(float finished)
183 {
184         entity p;
185         PlayerScore_Sort(score_dummyfield, 0, 0, 0);
186         PlayerScore_Sort(scoreboard_pos, 1, 1, 1);
187         if(teamplay) { PlayerScore_TeamStats(); }
188         FOR_EACH_CLIENT(p)
189         {
190                 // add personal score rank
191                 PS_GR_P_ADDVAL(p, PLAYERSTATS_RANK, p.score_dummyfield);
192
193                 if(!p.scoreboard_pos) { continue; }
194
195                 // scoreboard is valid!
196                 PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
197
198                 // add scoreboard position
199                 PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
200
201                 // add scoreboard data
202                 PlayerScore_PlayerStats(p);
203
204                 // if the match ended normally, add winning info
205                 if(finished)
206                 {
207                         PS_GR_P_ADDVAL(p, PLAYERSTATS_WINS, p.winning);
208                         PS_GR_P_ADDVAL(p, PLAYERSTATS_MATCHES, 1);
209                 }
210         }
211 }
212
213 void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that scores are added properly
214 {
215         string uri;
216         PS_GR_OUT_DB = -1;
217         playerstats_waitforme = TRUE;
218         uri = autocvar_g_playerstats_uri;
219         if(uri == "")
220                 return;
221         PS_GR_OUT_DB = db_create();
222         if(PS_GR_OUT_DB >= 0)
223                 playerstats_waitforme = FALSE; // must wait for it at match end
224
225         serverflags |= SERVERFLAG_PLAYERSTATS;
226
227         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ALIVETIME);
228         PlayerStats_GameReport_AddEvent(PLAYERSTATS_AVGLATENCY);
229         PlayerStats_GameReport_AddEvent(PLAYERSTATS_WINS);
230         PlayerStats_GameReport_AddEvent(PLAYERSTATS_MATCHES);
231         PlayerStats_GameReport_AddEvent(PLAYERSTATS_JOINS);
232         PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_VALID);
233         PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_POS);
234         PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK);
235
236     // accuracy stats
237     entity w;
238     float i;
239     for(i = WEP_FIRST; i <= WEP_LAST; ++i)
240     {
241         w = get_weaponinfo(i);
242         PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-hit"));
243         PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-fired"));
244         PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-hit"));
245         PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-fired"));
246         PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-frags"));
247     }
248
249         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3);
250         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5);
251         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10);
252         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15);
253         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20);
254         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25);
255         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30);
256         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_BOTLIKE);
257         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD);
258         PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM);
259 }
260
261 void PlayerStats_GameReport_Shutdown()
262 {
263         string uri;
264
265         if(PS_GR_OUT_DB < 0) { return; }
266
267         uri = autocvar_g_playerstats_uri;
268         if(uri != "")
269         {
270                 playerstats_waitforme = FALSE;
271                 url_multi_fopen(uri, FILE_APPEND, PlayerStats_GameReport_Handler, world);
272         }
273         else
274         {
275                 playerstats_waitforme = TRUE;
276                 db_close(PS_GR_OUT_DB);
277                 PS_GR_OUT_DB = -1;
278         }
279 }
280
281 void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
282 {
283         string t, tn;
284         string p, pn;
285         string e, en;
286         string nn, tt;
287         string s;
288
289         switch(status)
290         {
291                 // ======================================
292                 // -- OUTGOING GAME REPORT INFORMATION --
293                 // ======================================
294                 /* SPECIFICATIONS:
295                  * V: format version (always a fixed number) - this MUST be the first line!
296                  * #: comment (MUST be ignored by any parser)
297                  * R: release information on the server
298                  * G: game type
299                  * O: mod name (icon request) as in server browser
300                  * M: map name
301                  * I: match ID (see "matchid" in g_world.qc)
302                  * S: "hostname" of the server
303                  * C: number of "unpure" cvar changes
304                  * U: UDP port number of the server
305                  * D: duration of the match
306                  * L: "ladder" in which the server is participating in
307                  * P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!)
308                  * Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!)
309                  * i: player index
310                  * n: nickname of the player (optional)
311                  * t: team ID
312                  * e: followed by an event name, a space, and the event count/score
313                  *  event names can be:
314                  *   alivetime: total playing time of the player
315                  *   avglatency: average network latency compounded throughout the match
316                  *   wins: number of games won (can only be set if matches is set)
317                  *   matches: number of matches played to the end (not aborted by map switch)
318                  *   joins: number of matches joined (always 1 unless player never played during the match)
319                  *   scoreboardvalid: set to 1 if the player was there at the end of the match
320                  *   total-<scoreboardname>: total score of that scoreboard item
321                  *   scoreboard-<scoreboardname>: end-of-game score of that scoreboard item (can differ in non-team games)
322                  *   achievement-<achievementname>: achievement counters (their "count" is usually 1 if nonzero at all)
323                  *   kills-<index>: number of kills against the indexed player
324                  *   rank <number>: rank of player
325                  *   acc-<weapon netname>-hit: total damage dealt
326                  *   acc-<weapon netname>-fired: total damage that all fired projectiles *could* have dealt
327                  *   acc-<weapon netname>-cnt-hit: amount of shots that actually hit
328                  *   acc-<weapon netname>-cnt-fired: amount of fired shots
329                  *   acc-<weapon netname>-frags: amount of frags dealt by weapon
330                  */
331                 case URL_READY_CANWRITE:
332                 {
333                         url_fputs(fh, "V 9\n");
334                         #ifdef WATERMARK
335                         url_fputs(fh, sprintf("R %s\n", WATERMARK));
336                         #endif
337                         url_fputs(fh, sprintf("G %s\n", GetGametype()));
338                         url_fputs(fh, sprintf("O %s\n", modname));
339                         url_fputs(fh, sprintf("M %s\n", GetMapname()));
340                         url_fputs(fh, sprintf("I %s\n", matchid));
341                         url_fputs(fh, sprintf("S %s\n", cvar_string("hostname")));
342                         url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count));
343                         url_fputs(fh, sprintf("U %d\n", cvar("port")));
344                         url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime)));
345                         url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_ladder));
346
347                         // TEAMS
348                         if(teamplay)
349                         {
350                                 for(t = PS_GR_OUT_TL; (tn = db_get(PS_GR_OUT_DB, sprintf("%d", stof(t)))) != ""; t = tn)
351                                 {
352                                         // start team section
353                                         url_fputs(fh, sprintf("Q team#%s\n", t));
354
355                                         // output team events // todo: does this do unnecessary loops? perhaps we should do a separate "team_events_last" tracker..."
356                                         for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
357                                         {
358                                                 float v = stof(db_get(PS_GR_OUT_DB, sprintf("team#%d:%s", stof(t), e)));
359                                                 if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
360                                         }
361                                 }
362                         }
363
364                         // PLAYERS
365                         for(p = PS_GR_OUT_PL; (pn = db_get(PS_GR_OUT_DB, sprintf("%s:*", p))) != ""; p = pn)
366                         {
367                                 // start player section
368                                 url_fputs(fh, sprintf("P %s\n", p));
369
370                                 // playerid/index (entity number for this server)
371                                 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_playerid", p));
372                                 if(nn != "") { url_fputs(fh, sprintf("i %s\n", nn)); }
373
374                                 // player name 
375                                 nn = db_get(PS_GR_OUT_DB, sprintf("%s:_netname", p));
376                                 if(nn != "") { url_fputs(fh, sprintf("n %s\n", nn)); }
377
378                                 // team identification number
379                                 if(teamplay)
380                                 {
381                                         tt = db_get(PS_GR_OUT_DB, sprintf("%s:_team", p));
382                                         url_fputs(fh, sprintf("t %s\n", tt));
383                                 }
384
385                                 // output player events
386                                 for(e = PS_GR_OUT_EVL; (en = db_get(PS_GR_OUT_DB, sprintf("*:%s", e))) != ""; e = en)
387                                 {
388                                         float v = stof(db_get(PS_GR_OUT_DB, sprintf("%s:%s", p, e)));
389                                         if(v != 0) { url_fputs(fh, sprintf("e %s %g\n", e, v)); }
390                                 }
391                         }
392                         url_fputs(fh, "\n");
393                         url_fclose(fh);
394                         break;
395                 }
396
397                 // ======================================
398                 // -- INCOMING GAME REPORT INFORMATION --
399                 // ======================================
400                 /* SPECIFICATIONS:
401                  * stuff
402                  */
403                 case URL_READY_CANREAD:
404                 {
405                         // url_fclose is processing, we got a response for writing the data
406                         // this must come from HTTP
407                         print("Got response from player stats server:\n");
408                         while((s = url_fgets(fh))) { print("  ", s, "\n"); }
409                         print("End of response.\n");
410                         url_fclose(fh);
411                         break;
412                 }
413                 
414                 case URL_READY_CLOSED:
415                 {
416                         // url_fclose has finished
417                         print("Player stats written\n");
418                         playerstats_waitforme = TRUE;
419                         db_close(PS_GR_OUT_DB);
420                         PS_GR_OUT_DB = -1;
421                         break;
422                 }
423                 
424                 case URL_READY_ERROR:
425                 default:
426                 {
427                         print("Player stats writing failed: ", ftos(status), "\n");
428                         playerstats_waitforme = TRUE;
429                         if(PS_GR_OUT_DB >= 0)
430                         {
431                                 db_close(PS_GR_OUT_DB);
432                                 PS_GR_OUT_DB = -1;
433                         }
434                         break;
435                 }
436         }
437 }
438 #endif // SVQC
439 /*
440 void PlayerInfo_AddPlayer(entity e)
441 {
442         if(playerinfo_db < 0)
443                 return;
444
445         string key;
446         key = sprintf("#%d:*", e.playerid); // TODO: use hashkey instead?
447
448         string p;
449         p = db_get(playerinfo_db, key);
450         if(p == "")
451         {
452                 if(playerinfo_last)
453                 {
454                         db_put(playerinfo_db, key, playerinfo_last);
455                         strunzone(playerinfo_last);
456                 }
457                 else
458                         db_put(playerinfo_db, key, "#");
459                 playerinfo_last = strzone(ftos(e.playerid));
460                 print("  Added player ", ftos(e.playerid), " to playerinfo_db\n");//DEBUG//
461         }
462 }
463
464 void PlayerInfo_AddItem(entity e, string item_id, string val)
465 {
466         if(playerinfo_db < 0)
467                 return;
468
469         string key;
470         key = sprintf("*:%s", item_id);
471
472         string p;
473         p = db_get(playerinfo_db, key);
474         if(p == "")
475         {
476                 if(playerinfo_events_last)
477                 {
478                         db_put(playerinfo_db, key, playerinfo_events_last);
479                         strunzone(playerinfo_events_last);
480                 }
481                 else
482                         db_put(playerinfo_db, key, "#");
483                 playerinfo_events_last = strzone(item_id);
484         }
485
486         key = sprintf("#%d:%s", e.playerid, item_id);
487         db_put(playerinfo_db, key, val);
488         print("  Added item ", key, "=", val, " to playerinfo_db\n");//DEBUG//
489 }
490
491 string PlayerInfo_GetItem(entity e, string item_id)
492 {
493         if(playerinfo_db < 0)
494                 return "";
495
496         string key;
497         key = sprintf("#%d:%s",  e.playerid, item_id);
498         return db_get(playerinfo_db, key);
499 }
500
501 string PlayerInfo_GetItemLocal(string item_id)
502 {
503         entity p = spawn();
504         p.playerid = 0;
505         return PlayerInfo_GetItem(p, item_id);
506 }
507
508 void PlayerInfo_ready(entity fh, entity p, float status)
509 {
510         float n;
511         string s;
512
513         PlayerInfo_AddPlayer(p);
514
515         switch(status)
516         {
517                 case URL_READY_CANWRITE:
518                         print("-- Sending data to player stats server\n");
519                         url_fputs(fh, "V 1\n");
520 #ifdef WATERMARK
521                         url_fputs(fh, sprintf("R %s\n", WATERMARK));
522 #endif
523 #ifdef MENUQC
524                         url_fputs(fh, sprintf("l %s\n", cvar_string("_menu_prvm_language"))); // language
525                         url_fputs(fh, sprintf("c %s\n", cvar_string("_menu_prvm_country"))); // country
526                         url_fputs(fh, sprintf("g %s\n", cvar_string("_menu_prvm_gender"))); // gender
527                         url_fputs(fh, sprintf("n %s\n", cvar_string("_cl_name"))); // name
528                         url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
529 #endif
530                         url_fputs(fh, "\n");
531                         url_fclose(fh);
532                         break;
533                 case URL_READY_CANREAD:
534                         print("-- Got response from player stats server:\n");
535                         string gametype = string_null;
536                         while((s = url_fgets(fh)))
537                         {
538                                 print("  ", s, "\n");
539
540                                 string key = "", value = "", data = "";
541
542                                 n = tokenizebyseparator(s, " "); // key (value) data
543                                 if (n == 1)
544                                         continue;
545                                 else if (n == 2)
546                                 {
547                                         key = argv(0);
548                                         data = argv(1);
549                                 }
550                                 else if (n >= 3)
551                                 {
552                                         key = argv(0);
553                                         value = argv(1);
554                                         data = argv(2);
555                                 }
556
557                                 if (data == "")
558                                         continue;
559
560                                 if (key == "#")
561                                         continue;
562                                 else if (key == "V")
563                                         PlayerInfo_AddItem(p, "_version", data);
564                                 else if (key == "R")
565                                         PlayerInfo_AddItem(p, "_release", data);
566                                 else if (key == "T")
567                                         PlayerInfo_AddItem(p, "_time", data);
568                                 else if (key == "S")
569                                         PlayerInfo_AddItem(p, "_statsurl", data);
570                                 else if (key == "P")
571                                         PlayerInfo_AddItem(p, "_hashkey", data);
572                                 else if (key == "n")
573                                         PlayerInfo_AddItem(p, "_playernick", data);
574                                 else if (key == "i")
575                                         PlayerInfo_AddItem(p, "_playerid", data);
576                                 else if (key == "G")
577                                         gametype = data;
578                                 else if (key == "e" && value != "")
579                                 {
580                                         if (gametype == "")
581                                                 PlayerInfo_AddItem(p, value, data);
582                                         else
583                                                 PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data);
584                                 }
585                                 else
586                                         continue;
587                         }
588                         print("-- End of response.\n");
589                         url_fclose(fh);
590                         break;
591                 case URL_READY_CLOSED:
592                         // url_fclose has finished
593                         print("Player stats synchronized with server\n");
594                         break;
595                 case URL_READY_ERROR:
596                 default:
597                         print("Receiving player stats failed: ", ftos(status), "\n");
598                         break;
599         }
600 }
601
602 void PlayerInfo_Init()
603 {
604         playerinfo_db = -1;
605         playerinfo_db = db_create();
606 }
607
608 #ifdef SVQC
609 void PlayerInfo_Basic(entity p)
610 {
611         print("-- Getting basic PlayerInfo for player ",ftos(p.playerid)," (SVQC)\n");
612
613         if(playerinfo_db < 0)
614                 return;
615
616         string uri;
617         uri = autocvar_g_playerinfo_uri;
618         if(uri != "" && p.crypto_idfp != "")
619         {
620                 uri = strcat(uri, "/elo/", uri_escape(p.crypto_idfp));
621                 print("Retrieving playerstats from URL: ", uri, "\n");
622                 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);
623         }
624 }
625 #endif
626
627 #ifdef MENUQC
628 void PlayerInfo_Details()
629 {
630         print("-- Getting detailed PlayerInfo for local player (MENUQC)\n");
631
632         if(playerinfo_db < 0)
633                 return;
634
635         string uri;
636         uri = autocvar_g_playerinfo_uri; // FIXME
637         if(uri != "" && crypto_getmyidstatus(0) > 0)
638         {
639                 //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
640                 uri = strcat(uri, "/player/me");
641                 print("Retrieving playerstats from URL: ", uri, "\n");
642                 url_single_fopen(uri, FILE_APPEND, PlayerInfo_ready, world);
643         }
644 }
645 #endif
646
647 #ifdef CSQC
648 /*
649  * FIXME - crypto_* builtin functions missing in CSQC (csprogsdefs.qc:885)
650 void PlayerInfo_Details()
651 {
652         print("-- Getting detailed PlayerInfo for local player (CSQC)\n");
653
654         if(playerinfo_db < 0)
655                 return;
656
657         string uri;
658         uri = autocvar_g_playerinfo_uri; // FIXME
659         if(uri != "" && crypto_getmyidstatus(0) > 0)
660         {
661                 uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
662                 print("Retrieving playerstats from URL: ", uri, "\n");
663                 url_single_fopen(uri, FILE_READ, PlayerInfo_ready, p);
664         }
665 }
666
667 #endif
668 */