From 763e342c53a43af0bcfe990b4faa8271121d2a36 Mon Sep 17 00:00:00 2001 From: aurhat <6187373+aurhat@users.noreply.github.com> Date: Sun, 26 Dec 2021 23:13:39 +0100 Subject: [PATCH 1/2] Add compatibility with 1.3 --- source/src/cube.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/src/cube.h b/source/src/cube.h index 339f9a5b..86e31387 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -65,13 +65,13 @@ extern float waterlevel; #define AC_MASTER_URI "ms.cubers.net" // uncomment this line for production release -//#define PRODUCTION +#define PRODUCTION #ifdef PRODUCTION #define AC_VERSION 1300 #define AC_MASTER_PORT 28760 #else - #define AC_VERSION -(1300) + #define AC_VERSION -(1300) #define AC_MASTER_PORT 28758 #endif From 1525e22cb8c14f9af5255917c87a1d3198905c65 Mon Sep 17 00:00:00 2001 From: aurhat <6187373+aurhat@users.noreply.github.com> Date: Sun, 26 Dec 2021 22:55:31 +0100 Subject: [PATCH 2/2] fix afk kick --- source/src/protocol.cpp | 22 ++++++++++++++++++++++ source/src/protos.h | 1 + source/src/server.cpp | 19 ++++++++++++++++--- source/src/server.h | 10 ++-------- source/src/serverchecks.h | 8 ++++---- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 41a1fe6c..73f1db59 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -620,6 +620,28 @@ int msgsizelookup(int msg) return msg >= 0 && msg < SV_NUM ? sizetable[msg] : -1; } +static const int lastclactions[] = // actions for afk checking +{ + SV_TEXT, SV_TEAMTEXT, SV_TEXTME, SV_TEAMTEXTME, SV_TEXTPRIVATE, + SV_VOICECOM, SV_VOICECOMTEAM, + SV_SHOOT, SV_EXPLODE, SV_SUICIDE, SV_RELOAD, + SV_SPAWN, + SV_SENDMAP, SV_RECVMAP, SV_REMOVEMAP, + SV_WEAPCHANGE, SV_PRIMARYWEAP, + SV_SETADMIN, + SV_CALLVOTE, SV_VOTE, + SV_LISTDEMOS, SV_GETDEMO, + SV_SWITCHNAME, SV_SWITCHSKIN, SV_SWITCHTEAM, + SV_GETVITA +}; + +int lastclactionslookup(int msg) +{ + const int lastclactions_n = constarraysize(lastclactions); + loopi(lastclactions_n) if(lastclactions[i] == msg) return true; + return false; +} + const char *disc_reason(int reason) { static const char *prot[] = { "terminated by enet", "end of packet", "client num", "tag type", "duplicate connection", "overflow", "random", "voodoo", "sync", "auth failed" }, diff --git a/source/src/protos.h b/source/src/protos.h index 5e74ea6e..2fc2db3f 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -1089,6 +1089,7 @@ extern void filterlang(char *d, const char *s); extern void filtercountrycode(char *d, const char *s); // returns exactly two uppercase chars or "--" extern void trimtrailingwhitespace(char *s); extern int msgsizelookup(int msg); +extern int lastclactionslookup(int msg); extern const char *disc_reason(int reason); extern string mastername; extern int masterport; diff --git a/source/src/server.cpp b/source/src/server.cpp index 647af5cf..3e7af8d9 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2880,6 +2880,7 @@ void forcedeath(client *cl) { sdropflag(cl->clientnum); cl->state.state = CS_DEAD; + cl->state.lastdeath = sg->gamemillis; cl->state.respawn(); sendf(-1, 1, "rii", SV_FORCEDEATH, cl->clientnum); } @@ -3233,6 +3234,8 @@ void process(ENetPacket *packet, int sender, int chan) else protocoldebug(false); #endif + if(lastclactionslookup(type)) cl->state.lastclaction = sg->gamemillis; + switch(type) { case SV_TEAMTEXTME: @@ -3524,7 +3527,6 @@ void process(ENetPacket *packet, int sender, int chan) cl->state.lastspawn = -1; cl->state.spawn = sg->gamemillis; cl->autospawn = false; - cl->upspawnp = false; cl->state.state = CS_ALIVE; cl->state.gunselect = gunselect; QUEUE_BUF( @@ -3655,7 +3657,12 @@ void process(ENetPacket *packet, int sender, int chan) cl->f = ff & ((1 << FLAGBITS) - 1); if(cl->f & (1 << 10)) z = -z; cl->state.o.z = z/DMF; - if(cl->f & (1 << 9)) loopi(3) getint(p); + if(cl->f & (1 << 9)) + { + loopi(3) getint(p); + cl->state.lastclaction = sg->gamemillis; + } + if(((cl->f & 0x1f) / 9) == 2) cl->state.lastclaction = sg->gamemillis; // crouching if(!cl->isonrightmap) break; if(cl->type==ST_TCPIP && (cl->state.state==CS_ALIVE || cl->state.state==CS_EDITING)) @@ -3687,7 +3694,13 @@ void process(ENetPacket *packet, int sender, int chan) cl->yaw = (int)decodeyaw(q.getbits(YAWBITS)); cl->pitch = (int)decodepitch(q.getbits(PITCHBITS)); cl->f = q.getbits(FLAGBITS); - if(cl->f & (1 << 9)) q.getbits(4 + 4 + 4); + if(cl->f & (1 << 9)) + { + q.getbits(4 + 4 + 4); + cl->state.lastclaction = sg->gamemillis; + } + if(((cl->f & 0x1f) / 9) == 2) cl->state.lastclaction = sg->gamemillis; // crouching + int zfull = q.getbits(1); int s = q.rembits(); if(s < 3) s += 8; diff --git a/source/src/server.h b/source/src/server.h index 84928868..2acda630 100644 --- a/source/src/server.h +++ b/source/src/server.h @@ -111,7 +111,7 @@ struct clientstate : playerstate { vec o; int state; - int lastdeath, lastspawn, spawn, lifesequence; + int lastdeath, lastspawn, spawn, lifesequence, lastclaction; bool forced; int lastshot; projectilestate<8> grenades; @@ -141,6 +141,7 @@ struct clientstate : playerstate akimbomillis = 0; scoped = forced = false; flagscore = frags = teamkills = deaths = shotdamage = damage = events = lastdisc = reconnections = 0; + lastdeath = lastclaction = 0; respawn(); } @@ -148,7 +149,6 @@ struct clientstate : playerstate { playerstate::respawn(); o = vec(-1e10f, -1e10f, -1e10f); - lastdeath = 0; lastspawn = -1; spawn = 0; lastshot = 0; @@ -272,11 +272,8 @@ struct client // server side version of "dynent" type int spectcn; int mapcollisions, farpickups; enet_uint32 bottomRTT; - bool upspawnp; int lag; - vec spawnp; int nvotes; - int input, inputmillis; int ffire, wn, f, t, yaw, pitch; gameevent &addevent() @@ -304,9 +301,7 @@ struct client // server side version of "dynent" type lastevent = 0; at3_lastforce = 0; mapcollisions = farpickups = 0; - upspawnp = false; lag = 0; - spawnp = vec(-1e10f, -1e10f, -1e10f); ldt = spj = 0; ffire = 0; f = yaw = pitch = t = 0; @@ -337,7 +332,6 @@ struct client // server side version of "dynent" type mapchange(); freshgame = false; // don't spawn into running games mute = spam = lastvc = badspeech = badmillis = nvotes = 0; - input = inputmillis = 0; ispaused = 0; } diff --git a/source/src/serverchecks.h b/source/src/serverchecks.h index 8d83f3b7..6edfc808 100644 --- a/source/src/serverchecks.h +++ b/source/src/serverchecks.h @@ -38,10 +38,10 @@ void check_afk() loopv(clients) { client &c = *clients[i]; - if ( c.type != ST_TCPIP || c.connectmillis + 60 * 1000 > servmillis || - c.inputmillis + scl.afk_limit > servmillis || clienthasflag(c.clientnum) != -1 ) continue; - if ( ( c.state.state == CS_DEAD && !m_arena && c.state.lastdeath + 45 * 1000 < sg->gamemillis) || - ( c.state.state == CS_ALIVE && c.upspawnp ) /*|| + if ( c.type != ST_TCPIP || c.role > CR_DEFAULT || c.connectmillis + 60 * 1000 > servmillis || + clienthasflag(c.clientnum) != -1 ) continue; + if ( ( c.state.state == CS_DEAD && !m_arena && (c.state.lastdeath + scl.afk_limit) < sg->gamemillis) || + ( c.state.state == CS_ALIVE && c.state.lastclaction && (c.state.lastclaction + scl.afk_limit) < sg->gamemillis) /*|| ( c.state.state == CS_SPECTATE && totalclients >= scl.maxclients ) // only kick spectator if server is full - 2011oct16:flowtron: mmh, that seems reasonable enough .. still, kicking spectators for inactivity seems harsh! disabled ATM, kick them manually if you must. */ )