Skip to content

Instantly share code, notes, and snippets.

@sauerbraten
Last active February 28, 2019 16:16
Show Gist options
  • Save sauerbraten/7b38525d3660d3d246e23e6a90e60a37 to your computer and use it in GitHub Desktop.
Save sauerbraten/7b38525d3660d3d246e23e6a90e60a37 to your computer and use it in GitHub Desktop.
patch for vanilla to report stats of gauthed users at intermission (use with https://github.com/sauerbraten/maitred as master)
Index: src/fpsgame/server.cpp
===================================================================
--- src/fpsgame/server.cpp (revision 5401)
+++ src/fpsgame/server.cpp (working copy)
@@ -2116,6 +2116,42 @@
}
}
+ void reportstats()
+ {
+ string msg = "";
+ loopv(clients)
+ {
+ clientinfo *ci = clients[i];
+ if (!ci->authreq || !ci->authname[0] || ci->authdesc[0]) continue;
+ ci->state.timeplayed += lastmillis - ci->state.lasttimeplayed;
+ ci->state.lasttimeplayed = lastmillis;
+ if (ci->state.timeplayed < gamelimit/2) continue;
+ concformatstring(msg, " %u %s %d %d %d %d %d", ci->authreq, ci->authname, ci->state.frags, ci->state.deaths, ci->state.damage, ci->state.shotdamage, ci->state.flags);
+ }
+ requestmasterf("stats %d %s%s\n", gamemode, smapname, msg);
+ }
+
+ void notifystatssaved(uint authreq)
+ {
+ loopv(clients)
+ {
+ clientinfo *ci = clients[i];
+ if (ci->authreq != authreq) continue;
+ sendf(ci->clientnum, 1, "ris", N_SERVMSG, "your game statistics were reported to the masterserver");
+ }
+ }
+
+ void notifystatsfailed(uint authreq, string error)
+ {
+ loopv(clients)
+ {
+ clientinfo *ci = clients[i];
+ if (ci->authreq != authreq) continue;
+ defformatstring(msg, "reporting your game statistics failed: %s", error);
+ sendf(ci->clientnum, 1, "ris", N_SERVMSG, msg);
+ }
+ }
+
void checkintermission()
{
if(gamemillis >= gamelimit && !interm)
@@ -2124,6 +2160,7 @@
if(smode) smode->intermission();
changegamespeed(100);
interm = gamemillis + 10000;
+ reportstats();
}
}
@@ -2649,7 +2686,7 @@
{
clientinfo *ci = findauth(id);
if(!ci) return;
- ci->cleanauth(ci->connectauth!=0);
+ if (ci->authdesc[0]) ci->cleanauth(ci->connectauth);
if(ci->connectauth) connected(ci);
if(ci->authkickvictim >= 0)
{
@@ -2762,6 +2799,10 @@
gbans.clear();
else if(sscanf(cmd, "addgban %100s", val) == 1)
gbans.add(val);
+ else if(sscanf(cmd, "succstats %u", &id) == 1)
+ notifystatssaved(id);
+ else if(sscanf(cmd, "failstats %u %100s", &id, val) == 2)
+ notifystatsfailed(id, val);
}
void receivefile(int sender, uchar *data, int len)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment