X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fplayerstats.qc;h=3533b4882e4b94264cb3dcf4a4c6b3fa1337f9e8;hb=7d4dafbc492a284a6f6ccfc36bb3a28df42e653c;hp=4a9dac388ed1b859c121fd879f1986d5a7e81f3b;hpb=41ebfacea1dcc35c5b8c7e2bce80c3b3b4dcd717;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/playerstats.qc b/qcsrc/server/playerstats.qc index 4a9dac388..3533b4882 100644 --- a/qcsrc/server/playerstats.qc +++ b/qcsrc/server/playerstats.qc @@ -4,7 +4,6 @@ string playerstats_last; string events_last; .float playerstats_addedglobalinfo; .string playerstats_id; -float playerstats_sendtry; void PlayerStats_Init() { @@ -17,7 +16,9 @@ void PlayerStats_Init() playerstats_db = db_create(); if(playerstats_db >= 0) playerstats_waitforme = FALSE; // must wait for it at match end - + + serverflags |= SERVERFLAG_PLAYERSTATS; + PlayerStats_AddEvent(PLAYERSTATS_ALIVETIME); PlayerStats_AddEvent(PLAYERSTATS_WINS); PlayerStats_AddEvent(PLAYERSTATS_MATCHES); @@ -55,17 +56,28 @@ void PlayerStats_Init() void PlayerStats_AddPlayer(entity e) { + string s; + if(playerstats_db < 0) return; if(e.playerstats_id) return; + s = string_null; if(e.crypto_idfp != "" && e.cvar_cl_allow_uidtracking == 1) - e.playerstats_id = strzone(e.crypto_idfp); + s = e.crypto_idfp; else if(clienttype(e) == CLIENTTYPE_BOT) - e.playerstats_id = strzone(sprintf("bot#%d", e.playerid)); - else - e.playerstats_id = strzone(sprintf("player#%d", e.playerid)); + s = sprintf("bot#%g#%s", skill, e.cleanname); + + if(!s || find(world, playerstats_id, s)) // already have one of the ID - next one can't be tracked then! + { + if(clienttype(e) == CLIENTTYPE_BOT) + s = sprintf("bot#%d", e.playerid); + else + s = sprintf("player#%d", e.playerid); + } + + e.playerstats_id = strzone(s); string key; key = sprintf("%s:*", e.playerstats_id); @@ -167,13 +179,16 @@ void PlayerStats_TeamScore(float t, string event_id, float value) // TODO: doesn R: release information on the server T: time at which the game ended G: game type + O: mod name (icon request) as in server browser M: map name + I: match ID (see "matchid" in g_world.qc S: "hostname" of the server C: number of "unpure" cvar changes - W: winning team ID + U: UDP port number of the server + D: duration of the match P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!) n: nickname of the player (optional) - t: team ID + t: team ID e: followed by an event name, a space, and the event count/score event names can be: alivetime: total playing time of the player @@ -184,12 +199,12 @@ void PlayerStats_TeamScore(float t, string event_id, float value) // TODO: doesn total-: total score of that scoreboard item scoreboard-: end-of-game score of that scoreboard item (can differ in non-team games) achievement-: achievement counters - rank : rank of player - acc--hit: total damage dealt - acc--fired: total damage that all fired projectiles *could* have dealt - acc--cnt-hit: amount of shots that actually hit - acc--cnt-fired: amount of fired shots - acc--frags: amount of frags dealt by weapon + rank : rank of player + acc--hit: total damage dealt + acc--fired: total damage that all fired projectiles *could* have dealt + acc--cnt-hit: amount of shots that actually hit + acc--cnt-fired: amount of fired shots + acc--frags: amount of frags dealt by weapon */ void PlayerStats_ready(entity fh, entity pass, float status) @@ -198,7 +213,6 @@ void PlayerStats_ready(entity fh, entity pass, float status) string e, en; string nn, tt; string s; - float n; switch(status) { @@ -209,10 +223,13 @@ void PlayerStats_ready(entity fh, entity pass, float status) #endif url_fputs(fh, sprintf("T %s.%06d\n", strftime(FALSE, "%s"), floor(random() * 1000000))); url_fputs(fh, sprintf("G %s\n", GetGametype())); + url_fputs(fh, sprintf("O %s\n", modname)); url_fputs(fh, sprintf("M %s\n", GetMapname())); url_fputs(fh, sprintf("I %s\n", matchid)); url_fputs(fh, sprintf("S %s\n", cvar_string("hostname"))); url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count)); + url_fputs(fh, sprintf("U %d\n", cvar("port"))); + url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime))); for(p = playerstats_last; (pn = db_get(playerstats_db, sprintf("%s:*", p))) != ""; p = pn) { url_fputs(fh, sprintf("P %s\n", p)); @@ -236,7 +253,7 @@ void PlayerStats_ready(entity fh, entity pass, float status) } } url_fputs(fh, "\n"); - url_fclose(fh, PlayerStats_ready, world); + url_fclose(fh); break; case URL_READY_CANREAD: // url_fclose is processing, we got a response for writing the data @@ -245,7 +262,7 @@ void PlayerStats_ready(entity fh, entity pass, float status) while((s = url_fgets(fh))) print(" ", s, "\n"); print("End of response.\n"); - url_fclose(fh, PlayerStats_ready, world); + url_fclose(fh); break; case URL_READY_CLOSED: // url_fclose has finished @@ -257,15 +274,6 @@ void PlayerStats_ready(entity fh, entity pass, float status) case URL_READY_ERROR: default: print("Player stats writing failed: ", ftos(status), "\n"); - ++playerstats_sendtry; - n = tokenize_console(autocvar_g_playerstats_uri); - if(playerstats_sendtry < n) - { - print("Trying next URL...\n"); - url_fopen(argv(playerstats_sendtry), FILE_APPEND, PlayerStats_ready, world); - return; - } - print("Failed permanently.\n"); playerstats_waitforme = TRUE; if(playerstats_db >= 0) { @@ -279,17 +287,16 @@ void PlayerStats_ready(entity fh, entity pass, float status) //#NO AUTOCVARS START void PlayerStats_Shutdown() { - float n; + string uri; if(playerstats_db < 0) return; - playerstats_sendtry = 0; - n = tokenize_console(autocvar_g_playerstats_uri); - if(n > 0) + uri = autocvar_g_playerstats_uri; + if(uri != "") { playerstats_waitforme = FALSE; - url_fopen(argv(0), FILE_APPEND, PlayerStats_ready, world); + url_multi_fopen(uri, FILE_APPEND, PlayerStats_ready, world); } else { @@ -355,11 +362,21 @@ void PlayerStats_AddGlobalInfo(entity p) void PlayerStats_EndMatch(float finished) { entity p, winner; - winner = PlayerScore_Sort(score_dummyfield); - FOR_EACH_PLAYER(p) // spectators intentionally not included + winner = PlayerScore_Sort(score_dummyfield); + FOR_EACH_CLIENT(p) // spectators intentionally not included { - PlayerScore_PlayerStats(p); PlayerStats_Accuracy(p); + if(g_arena || g_lms || g_ca) + { + if(p.alivetime <= 0) + continue; + } + else + { + if(p.classname != "player") + continue; + } + PlayerScore_PlayerStats(p); PlayerStats_Event(p, PLAYERSTATS_SCOREBOARD_VALID, 1); if(finished) {