]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Deprecate FOR_EACH_CLIENT and FOR_EACH_CLIENTSLOT
authorMario <mario@smbclan.net>
Thu, 31 Dec 2015 22:21:52 +0000 (08:21 +1000)
committerMario <mario@smbclan.net>
Thu, 31 Dec 2015 22:21:52 +0000 (08:21 +1000)
qcsrc/server/_all.qh
qcsrc/server/ipban.qc
qcsrc/server/scores.qc

index 2b67138bcbfafbfecc248badcf7cbe9a74a025d4..eb3a4845dc1d7dd63ad3fcac9aed9031b60ab63a 100644 (file)
@@ -20,8 +20,8 @@ const string STR_OBSERVER = "observer";
 #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
 #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
 
-#define FOR_EACH_CLIENTSLOT(v) for (v = world; (v = nextent(v)) && (etof(v) <= maxclients); )
-#define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if (IS_CLIENT(v))
+// NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, LAMBDA(yourcode));
+// NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, LAMBDA(yourcode));
 // NOTE: FOR_EACH_REALCLIENT deprecated! Use the following instead: FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(yourcode));
 
 // NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(yourcode));
@@ -29,17 +29,19 @@ const string STR_OBSERVER = "observer";
 // NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), LAMBDA(yourcode));
 // NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(yourcode));
 
-#define FOREACH_CLIENT(cond, body) \
+#define FOREACH_CLIENTSLOT(cond, body) \
        MACRO_BEGIN { \
                for(int _i = 1; _i <= maxclients; ++_i) \
                { \
                        const noref int i = _i; \
                        const noref entity it = ftoe(i); \
-                       if(it == NULL || !IS_CLIENT(it)) continue; \
+                       if(it == NULL || wasfreed(it)) continue; \
                        if(cond) { LAMBDA(body) } \
                } \
        } MACRO_END
 
+#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), body)
+
 // NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(yourcode));
 
 #include <common/effects/all.qh>
index 12d12bf542dc80c344f714bef13a5ef458d4f10e..deffa8e0386c470aba82d7c2bac2179b83e06bce 100644 (file)
@@ -466,16 +466,15 @@ bool Ban_MaybeEnforceBanOnce(entity client)
        return Ban_MaybeEnforceBan(client);
 }
 
-string Ban_Enforce(float i, string reason)
+string Ban_Enforce(float j, string reason)
 {
        string s;
-       entity e;
 
        // Enforce our new ban
        s = "";
-       FOR_EACH_CLIENTSLOT(e)
-               if (IS_REAL_CLIENT(e))
-               if(Ban_IsClientBanned(e, i))
+       FOREACH_CLIENTSLOT(IS_REAL_CLIENT(it),
+       {
+               if(Ban_IsClientBanned(it, j))
                {
                        if(reason != "")
                        {
@@ -483,11 +482,12 @@ string Ban_Enforce(float i, string reason)
                                        reason = strcat(reason, ": affects ");
                                else
                                        reason = strcat(reason, ", ");
-                               reason = strcat(reason, e.netname);
+                               reason = strcat(reason, it.netname);
                        }
-                       s = strcat(s, "^1NOTE:^7 banned client ", e.netaddress, "^7 has to go\n");
-                       dropclient(e);
+                       s = strcat(s, "^1NOTE:^7 banned client ", it.netaddress, "^7 has to go\n");
+                       dropclient(it);
                }
+       });
        bprint(s);
 
        return reason;
index 0df94e0555720d729d40123ab5f5a2e2f6e05e2a..e01a9904f5186c9aee8e4335914b107b9e42e77d 100644 (file)
@@ -285,32 +285,32 @@ float PlayerScore_Clear(entity player)
 
 void Score_ClearAll()
 {
-       entity p, sk;
-       float i, t;
-       FOR_EACH_CLIENTSLOT(p)
+       entity sk;
+       float t;
+       FOREACH_CLIENTSLOT(true,
        {
-               sk = p.scorekeeper;
+               sk = it.scorekeeper;
                if(!sk)
                        continue;
-               for(i = 0; i < MAX_SCORE; ++i)
+               for(int j = 0; j < MAX_SCORE; ++j)
                {
-                       if(sk.(scores[i]) != 0)
-                               if(scores_label[i] != "")
-                                       sk.SendFlags |= pow(2, i);
-                       sk.(scores[i]) = 0;
+                       if(sk.(scores[j]) != 0)
+                               if(scores_label[j] != "")
+                                       sk.SendFlags |= pow(2, j);
+                       sk.(scores[j]) = 0;
                }
-       }
+       });
        for(t = 0; t < 16; ++t)
        {
                sk = teamscorekeepers[t];
                if(!sk)
                        continue;
-               for(i = 0; i < MAX_TEAMSCORE; ++i)
+               for(int j = 0; j < MAX_TEAMSCORE; ++j)
                {
-                       if(sk.(teamscores[i]) != 0)
-                               if(teamscores_label[i] != "")
-                                       sk.SendFlags |= pow(2, i);
-                       sk.(teamscores[i]) = 0;
+                       if(sk.(teamscores[j]) != 0)
+                               if(teamscores_label[j] != "")
+                                       sk.SendFlags |= pow(2, j);
+                       sk.(teamscores[j]) = 0;
                }
        }
 }
@@ -706,15 +706,15 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat
 
        FOREACH_CLIENT(true, LAMBDA(it.(field) = 0));
 
-       FOR_EACH_CLIENT(p) if(p.scorekeeper)
+       FOREACH_CLIENT(it.scorekeeper,
        {
                if(nospectators)
-                       if(p.frags == FRAGS_SPECTATOR)
+                       if(it.frags == FRAGS_SPECTATOR)
                                continue;
 
-               p.chain = plist;
-               plist = p;
-       }
+               it.chain = plist;
+               plist = it;
+       });
        // Now plist points to the whole list.
 
        pfirst = plast = world;