From 58f5f9656952d5e3a0092deb2f768c7ac73b40fc Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 1 Jan 2016 08:21:52 +1000 Subject: [PATCH] Deprecate FOR_EACH_CLIENT and FOR_EACH_CLIENTSLOT --- qcsrc/server/_all.qh | 10 ++++++---- qcsrc/server/ipban.qc | 16 ++++++++-------- qcsrc/server/scores.qc | 40 ++++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index 2b67138bc..eb3a4845d 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -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 diff --git a/qcsrc/server/ipban.qc b/qcsrc/server/ipban.qc index 12d12bf54..deffa8e03 100644 --- a/qcsrc/server/ipban.qc +++ b/qcsrc/server/ipban.qc @@ -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; diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 0df94e055..e01a9904f 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -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; -- 2.39.2