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