From 8b013d3ca13b022f553ef3b60c22f8a2047c7615 Mon Sep 17 00:00:00 2001 From: Jan Behrens Date: Sat, 3 Aug 2013 21:49:44 +0200 Subject: [PATCH] moving playerstats code from server to common --- qcsrc/{server => common}/playerstats.qc | 119 ++++++++++++++++++++++-- qcsrc/{server => common}/playerstats.qh | 11 +++ qcsrc/menu/progs.src | 2 + qcsrc/server/defs.qh | 17 +++- qcsrc/server/miscfunctions.qc | 16 ++-- qcsrc/server/progs.src | 6 +- 6 files changed, 149 insertions(+), 22 deletions(-) rename qcsrc/{server => common}/playerstats.qc (78%) rename qcsrc/{server => common}/playerstats.qh (93%) diff --git a/qcsrc/server/playerstats.qc b/qcsrc/common/playerstats.qc similarity index 78% rename from qcsrc/server/playerstats.qc rename to qcsrc/common/playerstats.qc index 354b521e8..b6f795ed8 100644 --- a/qcsrc/server/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -1,3 +1,5 @@ +#ifdef SVQC + float playerstats_db; string teamstats_last; string playerstats_last; @@ -17,7 +19,7 @@ void PlayerStats_Init() // initiated before InitGameplayMode so that scores are if(playerstats_db >= 0) playerstats_waitforme = FALSE; // must wait for it at match end - serverflags |= SERVERFLAG_PLAYERSTATS; + serverflags |= SERVERFLAG_PLAYERSTATS; PlayerStats_AddEvent(PLAYERSTATS_ALIVETIME); PlayerStats_AddEvent(PLAYERSTATS_AVGLATENCY); @@ -83,7 +85,7 @@ void PlayerStats_AddPlayer(entity e) string key; key = sprintf("%s:*", e.playerstats_id); - + string p; p = db_get(playerstats_db, key); if(p == "") @@ -106,7 +108,7 @@ void PlayerStats_AddTeam(float t) string key; key = sprintf("%d", t); - + string p; p = db_get(playerstats_db, key); if(p == "") @@ -126,10 +128,10 @@ void PlayerStats_AddEvent(string event_id) { if(playerstats_db < 0) return; - + string key; key = sprintf("*:%s", event_id); - + string p; p = db_get(playerstats_db, key); if(p == "") @@ -149,7 +151,7 @@ float PlayerStats_Event(entity e, string event_id, float value) { if((e.playerstats_id == "") || playerstats_db < 0) return 0; - + string key; float val; key = sprintf("%s:%s", e.playerstats_id, event_id); @@ -194,7 +196,7 @@ float PlayerStats_TeamScore(float t, string event_id, float value) 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!) - Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!) + Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!) n: nickname of the player (optional) t: team ID i: player index @@ -430,3 +432,106 @@ void PlayerStats_EndMatch(float finished) } } } + + +//// WIP -zykure + +/* + format spec: + + A collection of lines of the format SPACE NEWLINE, where + is always a single character. + + The following keys are defined: + + V: format version (always a fixed number) - this MUST be the first line! + #: comment (MUST be ignored by any parser) + 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 + 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!) + Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!) + n: nickname of the player (optional) + t: team ID + i: player index + e: followed by an event name, a space, and the event count/score + event names can be: + alivetime: total playing time of the player + avglatency: average network latency compounded throughout the match + wins: number of games won (can only be set if matches is set) + matches: number of matches played to the end (not aborted by map switch) + joins: number of matches joined (always 1 unless player never played during the match) + scoreboardvalid: set to 1 if the player was there at the end of the match + 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 (their "count" is usually 1 if nonzero at all) + kills-: number of kills against the indexed player + 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 + + Response format (not used yet): see https://gist.github.com/4284222 +*/ +/* +void PlayerStatsEntity_ready(entity fh, entity player_stats, float status) +{ + string s; + string key, value; + + switch(status) + { + case URL_READY_CANREAD: + print("Got response from player stats server:\n"); + while((s = url_fgets(fh))) + { + print(" ", s, "\n"); + + key = substring(s, 0, 1); + value = substring(s, 2, -1); + if (key == "#") + continue; + else if (key == "V") + // version + continue; + else if (key == "P") + player_stats.playerid = stof(value); + else if (key == "n") + player_stats.playernick = value; + } + print("End of response.\n"); + url_fclose(fh); + break; + case URL_READY_CLOSED: + // url_fclose has finished + print("Player stats received from server\n"); + break; + case URL_READY_ERROR: + default: + print("Receiving player stats failed: ", ftos(status), "\n"); + break; + } +} + +void PlayerStats_GetPlayerInfo(entity p) +{ + string uri; + + uri = autocvar_g_playerstats_uri; + if(uri != "") + { + url_single_fopen(strcat(uri, "/"), FILE_READ, PlayerStatsEntity_ready, p.player_stats); + } +} +*/ + +#endif // SVQC diff --git a/qcsrc/server/playerstats.qh b/qcsrc/common/playerstats.qh similarity index 93% rename from qcsrc/server/playerstats.qh rename to qcsrc/common/playerstats.qh index ab28b3a55..1cc088545 100644 --- a/qcsrc/server/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -1,3 +1,5 @@ +#ifdef SVQC + // time the player was alive and kicking string PLAYERSTATS_ALIVETIME = "alivetime"; string PLAYERSTATS_AVGLATENCY = "avglatency"; @@ -46,8 +48,17 @@ float PlayerStats_TeamScore(float t, string event_id, float value); // call at game over void PlayerStats_Shutdown(); // send stats to the server +void PlayerStats_Accuracy(entity p); + // call this whenever a player leaves void PlayerStats_AddGlobalInfo(entity p); // call this at the end of the match void PlayerStats_EndMatch(float finished); + + +//// WIP -zykure + +//void PlayerStats_GetPlayerInfo(entity p); + +#endif //SVQC diff --git a/qcsrc/menu/progs.src b/qcsrc/menu/progs.src index 3036278c1..b6ea698cd 100644 --- a/qcsrc/menu/progs.src +++ b/qcsrc/menu/progs.src @@ -11,6 +11,7 @@ config.qh ../warpzonelib/mathlib.qh ../common/util.qh ../common/test.qh +../common/playerstats.qh oo/base.h @@ -39,6 +40,7 @@ oo/implementation.h ../common/util.qc ../common/test.qc +../common/playerstats.qc ../common/command/markup.qc ../common/command/rpn.qc ../common/command/generic.qc diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 7d3585725..f694b7d1f 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -55,7 +55,7 @@ float team1_score, team2_score, team3_score, team4_score; float maxclients; // flag set on worldspawn so that the code knows if it is dedicated or not -float server_is_dedicated; +float server_is_dedicated; // Fields @@ -473,7 +473,7 @@ void target_voicescript_clear(entity pl); .float target_random; .float trigger_reverse; -// Nexball +// Nexball .entity ballcarried; // Also used for keepaway .float metertime; float g_nexball_meter_period; @@ -514,8 +514,8 @@ string matchid; .float last_pickup; -.float hit_time; -.float typehit_time; +.float hit_time; +.float typehit_time; .float stat_leadlimit; @@ -614,3 +614,12 @@ string modname; #define MISSILE_IS_CONFUSABLE(m) ((m.missile_flags & MIF_GUIDED_CONFUSABLE) ? TRUE : FALSE) #define MISSILE_IS_GUIDED(m) ((m.missile_flags & MIF_GUIDED_ALL) ? TRUE : FALSE) #define MISSILE_IS_TRACKING(m) ((m.missile_flags & MIF_GUIDED_TRACKING) ? TRUE : FALSE) + + +//// + +.entity player_stats; +//.float playerid; +.string playernick; +.float elos; +.float ranks; diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index df0903213..af8067ca0 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -647,16 +647,16 @@ float want_weapon(string cvarprefix, entity weaponinfo, float allguns) d = 0; // weapon is set a few lines later else d = (i == WEP_LASER || i == WEP_SHOTGUN); - + if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook d |= (i == WEP_HOOK); if(weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED) // never default mutator blocked guns d = 0; var float t = cvar(strcat(cvarprefix, weaponinfo.netname)); - + //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n")); - + // bit order in t: // 1: want or not // 2: is default? @@ -907,7 +907,7 @@ void readlevelcvars(void) // load mutators #define CHECK_MUTATOR_ADD(mut_cvar,mut_name,dependence) \ { if(cvar(mut_cvar) && dependence) { MUTATOR_ADD(mut_name); } } - + CHECK_MUTATOR_ADD("g_dodging", mutator_dodging, 1); CHECK_MUTATOR_ADD("g_spawn_near_teammate", mutator_spawn_near_teammate, 1); CHECK_MUTATOR_ADD("g_physical_items", mutator_physical_items, 1); @@ -920,9 +920,9 @@ void readlevelcvars(void) CHECK_MUTATOR_ADD("g_vampire", mutator_vampire, !cvar("g_minstagib")); CHECK_MUTATOR_ADD("g_superspectate", mutator_superspec, 1); CHECK_MUTATOR_ADD("g_sandbox", sandbox, 1); - + #undef CHECK_MUTATOR_ADD - + if(cvar("sv_allow_fullbright")) serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT; @@ -941,7 +941,7 @@ void readlevelcvars(void) g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref"); g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow"); g_bugrigs_steer = cvar("g_bugrigs_steer"); - + g_minstagib = cvar("g_minstagib"); sv_clones = cvar("sv_clones"); @@ -1816,7 +1816,7 @@ string uid2name(string myuid) { db_put(ServerProgsDB, strcat("uid2name", myuid), ""); } } - + if(s == "") s = "^1Unregistered Player"; return s; diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index 367e8609d..2997bd251 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -43,7 +43,7 @@ mutators/gamemode_ctf.qh mutators/gamemode_domination.qh mutators/gamemode_keyhunt.qh // TODO fix this mutators/gamemode_keepaway.qh -mutators/gamemode_nexball.qh +mutators/gamemode_nexball.qh mutators/gamemode_lms.qh mutators/mutator_dodging.qh @@ -72,7 +72,7 @@ csqceffects.qc anticheat.qh cheats.qh -playerstats.qh +../common/playerstats.qh portals.qh @@ -219,7 +219,7 @@ playerdemo.qc anticheat.qc cheats.qc -playerstats.qc +../common/playerstats.qc round_handler.qc -- 2.39.2