]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Refactor Nagger_SendEntity and Net_Handle_ENT_CLIENT_NAGGER
authorbones_was_here <bones_was_here@xonotic.au>
Wed, 23 Nov 2022 14:59:28 +0000 (00:59 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Fri, 6 Jan 2023 07:16:33 +0000 (17:16 +1000)
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
qcsrc/server/command/vote.qc

index a5cc47e0a142a4f882f0270f6a61df80797bbdc2..689618fd116712f79ca9bc09191949d7a190e479 100644 (file)
@@ -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;
 
index 01c699a0c00f461568afdd5a917da8acddb0e2fe..23656d2f756716f5a9fcd87ee168bfa031864b8b 100644 (file)
@@ -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);
                }
        }