From 33bffb336f83dc2bb3e4046d2d0bffdc86ad7cb9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 24 Nov 2012 21:19:32 +0000 Subject: [PATCH] - Use lists instead of looping on LastSlot in a few places. --- src/s_conf.c | 9 +-------- src/s_misc.c | 22 +++++++--------------- src/s_serv.c | 16 +++++----------- src/s_user.c | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/s_conf.c b/src/s_conf.c index 4f8a2fad4..4473f194b 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -1825,14 +1825,7 @@ ConfigItem_log *ca = MyMallocEx(sizeof(ConfigItem_log)); int isanyserverlinked(void) { -int i; -aClient *acptr; - - for (i = LastSlot; i >= 0; i--) - if ((acptr = local[i]) && (acptr != &me) && IsServer(acptr)) - return 1; - - return 0; + return !list_empty(&server_list); } void applymeblock(void) diff --git a/src/s_misc.c b/src/s_misc.c index a619d7c42..46b85c144 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -678,12 +678,12 @@ static void exit_one_client(aClient *cptr, aClient *sptr, aClient *from, char *c ** need to send different names to different servers ** (domain name matching) */ - for (i = 0; i <= LastSlot; i++) + list_for_each_entry(acptr, &server_list, special_node) { - if (!(acptr = local[i]) || !IsServer(acptr) || acptr == cptr || IsMe(acptr) - || (DontSendQuit(acptr) && split)) + if (acptr == cptr || IsMe(acptr) || (DontSendQuit(acptr) && split)) continue; + /* ** SQUIT going "upstream". This is the remote ** squit still hunting for the target. Use prefixed @@ -791,20 +791,12 @@ static void exit_one_client(aClient *cptr, aClient *sptr, aClient *from, char *c void checklist(void) { - aClient *acptr; - int i, j; - if (!(bootopt & BOOT_AUTODIE)) return; - for (j = i = 0; i <= LastSlot; i++) - if (!(acptr = local[i])) - continue; - else if (IsClient(acptr)) - j++; - if (!j) - { - exit(0); - } + + if (!list_empty(&lclient_list)) + exit (0); + return; } diff --git a/src/s_serv.c b/src/s_serv.c index c0d2731f0..6d9f5c1f5 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -871,11 +871,9 @@ char *reason = parv[1]; } } sendto_ops("Server is Restarting by request of %s", parv[0]); - - for (i = 0; i <= LastSlot; i++) + + list_for_each_entry(acptr, &lclient_list, lclient_node) { - if (!(acptr = local[i])) - continue; if (IsClient(acptr)) sendto_one(acptr, ":%s %s %s :Server Restarting. %s", @@ -1221,10 +1219,8 @@ CMD_FUNC(m_die) /* Let the +s know what is going on */ sendto_ops("Server Terminating by request of %s", parv[0]); - for (i = 0; i <= LastSlot; i++) + list_for_each_entry(acptr, &lclient_list, lclient_node) { - if (!(acptr = local[i])) - continue; if (IsClient(acptr)) sendto_one(acptr, ":%s %s %s :Server Terminating. %s", @@ -1233,6 +1229,7 @@ CMD_FUNC(m_die) sendto_one(acptr, ":%s ERROR :Terminated by %s", me.name, get_client_name(sptr, TRUE)); } + (void)s_die(); return 0; } @@ -1245,12 +1242,9 @@ CMD_FUNC(m_die) int localdie(void) { aClient *acptr; - int i; - for (i = 0; i <= LastSlot; i++) + list_for_each_entry(acptr, &lclient_list, lclient_node) { - if (!(acptr = local[i])) - continue; if (IsClient(acptr)) sendto_one(acptr, ":%s %s %s :Server Terminated by local console", diff --git a/src/s_user.c b/src/s_user.c index 962af2448..a5a4f178e 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -740,14 +740,14 @@ void send_umode(aClient *cptr, aClient *sptr, long old, long sendmask, char *umo */ void send_umode_out(aClient *cptr, aClient *sptr, long old) { - int i; aClient *acptr; send_umode(NULL, sptr, old, SEND_UMODES, buf); - for (i = LastSlot; i >= 0; i--) - if ((acptr = local[i]) && IsServer(acptr) && - (acptr != cptr) && (acptr != sptr) && *buf) { + list_for_each_entry(acptr, &server_list, special_node) + { + if ((acptr != cptr) && (acptr != sptr) && *buf) + { if (!SupportUMODE2(acptr)) { sendto_one(acptr, ":%s MODE %s :%s", @@ -761,28 +761,28 @@ void send_umode_out(aClient *cptr, aClient *sptr, long old) buf); } } + } + if (cptr && MyClient(cptr)) send_umode(cptr, sptr, old, ALL_UMODES, buf); - } void send_umode_out_nickv2(aClient *cptr, aClient *sptr, long old) { - int i; aClient *acptr; send_umode(NULL, sptr, old, SEND_UMODES, buf); - for (i = LastSlot; i >= 0; i--) - if ((acptr = local[i]) && IsServer(acptr) - && !SupportNICKv2(acptr) && (acptr != cptr) + list_for_each_entry(acptr, &server_list, special_node) + { + if (!SupportNICKv2(acptr) && (acptr != cptr) && (acptr != sptr) && *buf) sendto_one(acptr, ":%s MODE %s :%s", sptr->name, sptr->name, buf); + } if (cptr && MyClient(cptr)) send_umode(cptr, sptr, old, ALL_UMODES, buf); - }