From 23f6ab3616da6c14b4ca506227dd296df299e035 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Thu, 24 Nov 2022 00:59:28 +1000 Subject: [PATCH] Refactor Nagger_SendEntity and Net_Handle_ENT_CLIENT_NAGGER This will no longer network ready status outside of warmup_stage in the case that some clients manage to have ready status then. This change is made possible by the removal of sv_ready_restart in https://gitlab.com/xonotic/xonotic-data.pk3dir/-/merge_requests/940 It also simplifies the code and no longer networks the ready status of some SVQC entities that are not clients in the case that maxclients is not a multiple of 8. --- qcsrc/client/main.qc | 20 +++++--------------- qcsrc/server/command/vote.qc | 36 +++++++++++++++++------------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index a5cc47e0a1..689618fd11 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -709,7 +709,6 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew) { make_pure(this); - int i, j, b, f; int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS @@ -736,20 +735,11 @@ NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew) strcpy(vote_called_vote, ReadString()); } - if(nags & 1) - { - for(j = 0; j < maxclients; ++j) - if(playerslots[j]) - playerslots[j].ready = true; - for(i = 1; i <= maxclients; i += 8) - { - f = ReadByte(); - for(j = i-1, b = BIT(0); b < BIT(8); b <<= 1, ++j) - if (!(f & b)) - if(playerslots[j]) - playerslots[j].ready = false; - } - } + if(nags & BIT(0)) + for(int i = 0; i < maxclients;) + for(int f = ReadByte(), b = 0; b < 8 && i < maxclients; ++b, ++i) + if(playerslots[i]) + playerslots[i].ready = f & BIT(b); return = true; diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 01c699a0c0..23656d2f75 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -35,8 +35,7 @@ // Nagger for players to know status of voting bool Nagger_SendEntity(entity this, entity to, float sendflags) { - int nags, i, f, b; - entity e; + int nags = 0; WriteHeader(MSG_ENTITY, ENT_CLIENT_NAGGER); // bits: @@ -49,25 +48,23 @@ bool Nagger_SendEntity(entity this, entity to, float sendflags) // 64 = vote counts // 128 = vote string - nags = 0; - if (readycount) + if (warmup_stage) { - nags |= BIT(0); - if (to.ready == 0) nags |= BIT(1); + if (readycount) + { + nags |= BIT(0); + if (!to.ready) nags |= BIT(1); + } + nags |= BIT(4); } + if (vote_called) { nags |= BIT(2); if (to.vote_selection == 0) nags |= BIT(3); + nags |= sendflags & BIT(6); + nags |= sendflags & BIT(7); } - if (warmup_stage) nags |= BIT(4); - - if (sendflags & BIT(6)) nags |= BIT(6); - - if (sendflags & BIT(7)) nags |= BIT(7); - - if (!(nags & 4)) // no vote called? send no string - nags &= ~(BIT(6) | BIT(7)); WriteByte(MSG_ENTITY, nags); @@ -81,13 +78,14 @@ bool Nagger_SendEntity(entity this, entity to, float sendflags) if (nags & BIT(7)) WriteString(MSG_ENTITY, vote_called_display); - if (nags & 1) + if (nags & BIT(0)) { - for (i = 1; i <= maxclients; i += 8) + for (int i = 1; i <= maxclients;) { - for (f = 0, e = edict_num(i), b = BIT(0); b < BIT(8); b <<= 1, e = nextent(e)) - if (e.ready) - f |= b; + int f = 0; + for (int b = 0; b < 8 && i <= maxclients; ++b, ++i) + if (edict_num(i).ready) + f |= BIT(b); WriteByte(MSG_ENTITY, f); } } -- 2.39.2