From 55e6cf302f828c77d863951194415e3b5f18949f Mon Sep 17 00:00:00 2001 From: RonaldReagan Date: Tue, 11 May 2021 20:26:01 -0600 Subject: [PATCH] #263 Expose vita data to server admins (protocol bump) --- source/src/clientgame.cpp | 7 +++++++ source/src/clients2c.cpp | 33 +++++++++++++++++++++++++++++++++ source/src/protocol.cpp | 1 + source/src/protocol.h | 3 ++- source/src/server.cpp | 19 ++++++++++++++++++- 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 026f7d89..39d96418 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1642,6 +1642,13 @@ void whois(int *cn) } COMMAND(whois, "i"); +void getvita(int *cn) +{ + addmsg(SV_GETVITA, "ri", *cn); +} +COMMAND(getvita, "i"); + + void findcn(char *name) { loopv(players) if(players[i] && !strcmp(name, players[i]->name)) diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 0438c347..6282bd28 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -1354,6 +1354,39 @@ void parsemessages(int cn, playerent *d, ucharbuf &p, bool demo = false) getip4(p); p.get((uchar*)text, 64); break; + + case SV_VITADATA: { // Server sending vita data of a client. Possibly expose this to cubescript in the future + uchar pubkey[32]; + char pubkeyhex[68]; + string privatecomment; + string publiccomment; + int vs[VS_NUM]; + + int targetcn = getint(p); + playerent *target = getclient(targetcn); + + if (target && p.get(pubkey, 32) == 32) { + getstring(text, p); + filtertext(privatecomment, text, FTXT__VITACOMMENT); + getstring(text, p); + filtertext(publiccomment, text, FTXT__VITACOMMENT); + + loopi(VS_NUM) vs[i] = getint(p); + + bin2hex(pubkeyhex, pubkey, 32); + + conoutf("\f0Vita Info for \f5%s \f0(\f5%d\f0) \f2pubkey: \f1%s", target->name, targetcn, pubkeyhex); + if(privatecomment[0]) conoutf("\f0Private Comment: \f1%s", privatecomment); + if(publiccomment[0]) conoutf("\f0Public Comment: \f1%s", publiccomment); + + string msg = "\f0Flags:"; + for (int i = 0; i < VS_NUM; i++) { + concatformatstring(msg, " \f2%s=\f1%d", vskeywords[i], vs[i]); + } + conoutf("%s", msg); + } + break; + } default: neterr("type"); diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index cc3a6b9d..fc0ec990 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -605,6 +605,7 @@ static const int msgsizes[] = // size inclusive message token, 0 f SV_EXTENSION, 0, SV_MAPIDENT, 3, SV_DEMOCHECKSUM, 0, SV_DEMOSIGNATURE, 0, SV_PAUSEMODE, 1, + SV_GETVITA, 2, SV_VITADATA, 0, -1 }; diff --git a/source/src/protocol.h b/source/src/protocol.h index a3094818..7e9ea1f7 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -7,7 +7,7 @@ #define CUBE_SERVINFO_PORT(serverport) (serverport+1) #define CUBE_SERVINFO_TO_SERV_PORT(servinfoport) (servinfoport-1) #define CLIENTIPCENSOR 12 // blank out the last 12 bits of client's IPs before telling them to others (compromise between "16" from AC 0.9x and "8" from AC 1.1) -#define PROTOCOL_VERSION 1203 // bump when protocol changes (use negative numbers for mods!) +#define PROTOCOL_VERSION 1204 // bump when protocol changes (use negative numbers for mods!) #define DEMO_VERSION 2 // bump when demo format changes #define DEMO_MAGIC "ASSAULTCUBE_DEMO" #define DEMO_MINTIME 10000 // don't keep demo recordings with less than 10 seconds @@ -50,6 +50,7 @@ enum SV_EXTENSION, SV_MAPIDENT, SV_DEMOCHECKSUM, SV_DEMOSIGNATURE, SV_PAUSEMODE, + SV_GETVITA, SV_VITADATA, SV_NUM }; diff --git a/source/src/server.cpp b/source/src/server.cpp index 681dd54c..25580a2d 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2648,7 +2648,6 @@ void callvotepacket (int cn, voteinfo *v = curvote) sendpacket(cn, 1, q.finalize()); } -// TODO: use AUTH code void changeclientrole(int client, int role, char *pwd, bool force) { pwddetail pd; @@ -4031,6 +4030,24 @@ void process(ENetPacket *packet, int sender, int chan) case SV_PAUSEMODE: break; + + case SV_GETVITA: + { + int targetcn = getint(p); + + // If the client is admin or could be admin through vita + if ((cl->role >= CR_ADMIN || cl->checkvitadate(VS_ADMIN) || cl->checkvitadate(VS_OWNER)) + && valid_client(targetcn)) { + client *target = clients[targetcn]; + + if (target->vita) { + sendf(sender, 1, "riimssv", SV_VITADATA, targetcn, 32, target->pubkey.u, + target->vita->privatecomment, target->vita->publiccomment, + VS_NUM, target->vita->vs); + } + } + break; + } case SV_EXTENSION: {