From f8962b6c4703e1d86ca63238f6b32de83222e6c8 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Thu, 26 Jan 2023 07:07:53 +0000 Subject: [PATCH] Rework where connection_started is set to make sure its always set. Fixes https://github.com/fte-team/fteqw/issues/164 --- engine/server/pr_cmds.c | 1 + engine/server/pr_q1qvm.c | 1 + engine/server/sv_main.c | 9 ++++++++- engine/server/sv_user.c | 19 ++++--------------- plugins/quake3/svq3_game.c | 2 ++ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 4008594e6..4d252881f 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -4180,6 +4180,7 @@ static void QCBUILTIN PF_spawnclient (pubprogfuncs_t *prinst, struct globalvars_ svs.clients[i].userid = ++nextuserid; svs.clients[i].protocol = SCP_BAD; //marker for bots svs.clients[i].state = cs_spawned; + svs.clients[i].connection_started = realtime; svs.clients[i].spawned = true; sv.spawned_client_slots++; svs.clients[i].netchan.message.allowoverflow = true; diff --git a/engine/server/pr_q1qvm.c b/engine/server/pr_q1qvm.c index 70c6c46cf..d48be2ff1 100755 --- a/engine/server/pr_q1qvm.c +++ b/engine/server/pr_q1qvm.c @@ -1668,6 +1668,7 @@ static qintptr_t QVM_Add_Bot (void *offset, quintptr_t mask, const qintptr_t *ar cl->userid = ++nextuserid; cl->protocol = SCP_BAD; //marker for bots cl->state = cs_spawned; + cl->connection_started = realtime; cl->spawned = true; sv.spawned_client_slots++; cl->netchan.message.allowoverflow = true; diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 9e0584bf9..de95c5685 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -1018,6 +1018,7 @@ void SV_FullClientUpdate (client_t *client, client_t *to) if (ISQWCLIENT(to)) { + float onservertime; unsigned int pext = to->fteprotocolextensions; int ping = SV_CalcPing (client, false); if (ping > 0xffff) @@ -1041,10 +1042,13 @@ void SV_FullClientUpdate (client_t *client, client_t *to) MSG_WriteByte(buf, client->lossage); ClientReliable_FinishWrite(to); + onservertime = realtime - client->connection_started; + if (onservertime > sv.time) + onservertime = sv.time; buf = ClientReliable_StartWrite(to, 6); MSG_WriteByte(buf, svc_updateentertime); MSG_WriteByte(buf, i); - MSG_WriteFloat(buf, realtime - client->connection_started); + MSG_WriteFloat(buf, onservertime); ClientReliable_FinishWrite(to); InfoBuf_ToString(&client->userinfo, info, (pext&PEXT_BIGUSERINFOS)?BASIC_INFO_STRING:sizeof(info), basicuserinfos, privateuserinfos, (pext&PEXT_BIGUSERINFOS)?NULL:basicuserinfos, &to->infosync, &client->userinfo); @@ -2546,6 +2550,7 @@ client_t *SV_AddSplit(client_t *controller, char *info, int id) if (cl->spectator) InfoBuf_SetValueForStarKey (&cl->userinfo, "*spectator", va("%i", cl->spectator)); cl->state = controller->state; + cl->connection_started = realtime; // host_client = NULL; // sv_player = NULL; @@ -3076,6 +3081,7 @@ void SV_DoDirectConnect(svconnectinfo_t *fte_restrict info) #endif newcl->state = cs_connected; + newcl->connection_started = realtime; #ifdef Q3SERVER newcl->gamestatesequence = -1; @@ -5273,6 +5279,7 @@ void SV_Impulse_f (void) pr_global_struct->time = sv.world.physicstime; svs.clients[i].state = cs_connected; + svs.clients[i].connection_started = realtime; SV_SetUpClientEdict(&svs.clients[i], svs.clients[i].edict); diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index 1927bfad0..df9f702a7 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -375,7 +375,6 @@ void SV_New_f (void) ClientReliableWrite_Byte (host_client, playernum); split->state = cs_connected; - split->connection_started = realtime; #ifdef SVRANKING split->stats_started = realtime; #endif @@ -412,7 +411,6 @@ void SV_New_f (void) playernum |= 128; split->state = cs_connected; - split->connection_started = realtime; #ifdef SVRANKING split->stats_started = realtime; #endif @@ -5459,7 +5457,6 @@ void SV_SetUpClientEdict (client_t *cl, edict_t *ent) ent->v->movetype = MOVETYPE_NOCLIP; ent->v->frags = 0; - cl->connection_started = realtime; } //dynamically add/remove a splitscreen client @@ -5949,18 +5946,7 @@ static void SVNQ_Spawn_f (void) host_client->maxspeed = ent->xv->maxspeed; } else - { - ED_Clear(svprogfuncs, ent); - ED_Spawned(ent, false); - - ent->v->colormap = NUM_FOR_EDICT(svprogfuncs, ent); - ent->v->team = 0; // FIXME - svprogfuncs->SetStringField(svprogfuncs, ent, &ent->v->netname, host_client->name, true); - - host_client->entgravity = ent->xv->gravity = 1.0; - host_client->entgravity*=sv_gravity.value; - host_client->maxspeed = ent->xv->maxspeed = sv_maxspeed.value; - } + SV_SetUpClientEdict(host_client, ent); // // force stats to be updated @@ -6221,6 +6207,8 @@ static void SVNQ_Status_f(void) int hours, mins, secs; if (!cl->state) continue; + if (i >= host_client->max_net_clients) + break; //don't send more than it expects. the ping parsers will give up and get spammy (sucks). secs = realtime - cl->connection_started; mins = secs/60; secs -= mins*60; @@ -6418,6 +6406,7 @@ ucmd_t ucmds[] = {"sayone", SV_SayOne_f}, {"say", SV_Say_f}, {"say_team", SV_Say_Team_f}, + {"status", SVNQ_Status_f}, #ifdef SVRANKING {"topten", Rank_ListTop10_f}, #endif diff --git a/plugins/quake3/svq3_game.c b/plugins/quake3/svq3_game.c index 6ff3df493..4e4cf2f8c 100644 --- a/plugins/quake3/svq3_game.c +++ b/plugins/quake3/svq3_game.c @@ -3409,6 +3409,7 @@ void SVQ3_DirectConnect(netadr_t *from, sizebuf_t *msg) //Actually connect the c cl->protocol = SCP_QUAKE3; cl->state = cs_connected; + cl->connection_started = realtime; cl->name = cl->namebuf; cl->team = cl->teambuf; worldfuncs->ExtractFromUserinfo(cl, true); @@ -3434,6 +3435,7 @@ static int SVQ3_AddBot(void) return -1; //failure, no slots cl->protocol = SCP_BAD; + cl->connection_started = realtime; cl->state = cs_connected; cl->name = cl->namebuf; cl->team = cl->teambuf;