]> jfr.im git - irc/rizon/plexus4.git/commitdiff
sjoin: remove duplicated mode setting code
authorAdam <redacted>
Mon, 6 Jun 2022 21:54:45 +0000 (21:54 +0000)
committerAdam <redacted>
Mon, 6 Jun 2022 21:54:49 +0000 (21:54 +0000)
modules/core/m_sjoin.c

index 2bf4c92de93b9db65d2b55519cbe1c35024da03b..8c1ad4b221d5242788ea7322dbb3d58c52570d7b 100644 (file)
@@ -53,6 +53,7 @@ static void remove_our_modes(struct Channel *, struct Client *);
 static void remove_our_users(struct Channel *, struct Mode *);
 static void remove_a_mode(struct Channel *, struct Client *, int, char);
 static void remove_ban_list(struct Channel *, struct Client *, dlink_list *, char);
+static void set_local_channel_statusmode(struct Client *source_p, struct Channel *chptr, char mode, const char *param);
 
 
 /* ms_sjoin()
@@ -459,135 +460,18 @@ ms_sjoin(struct Client *client_p, struct Client *source_p,
 
 #ifdef CHANAQ
     if (fl & CHFL_OWNER)
-    {
-      *mbuf++ = 'q';
-      para[pargs++] = target_p->name;
-
-      if(pargs >= MAXMODEPARAMS)
-      {
-        sptr = sendbuf;
-        *mbuf = '\0';
-        for(lcount = 0; lcount < MAXMODEPARAMS; lcount++)
-        {
-          slen = sprintf(sptr, " %s", para[lcount]);   /* see? */
-          sptr += slen;                                        /* ready for next */
-        }
-        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
-                            servername, chptr->chname, modebuf, sendbuf);
-        mbuf = modebuf;
-        *mbuf++ = '+';
-
-        sendbuf[0] = '\0';
-        pargs = 0;
-      }
-    }
+      set_local_channel_statusmode(source_p, chptr, 'q', target_p->name);
     if (fl & CHFL_PROTECTED)
-    {
-      *mbuf++ = 'a';
-      para[pargs++] = target_p->name;
-
-      if(pargs >= MAXMODEPARAMS)
-      {
-        sptr = sendbuf;
-        *mbuf = '\0';
-        for(lcount = 0; lcount < MAXMODEPARAMS; lcount++)
-        {
-          slen = sprintf(sptr, " %s", para[lcount]);   /* see? */
-          sptr += slen;                                        /* ready for next */
-        }
-        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
-                            servername, chptr->chname, modebuf, sendbuf);
-        mbuf = modebuf;
-        *mbuf++ = '+';
-
-        sendbuf[0] = '\0';
-        pargs = 0;
-      }
-    }
+      set_local_channel_statusmode(source_p, chptr, 'a', target_p->name);
 #endif
     if (fl & CHFL_CHANOP)
-    {
-      *mbuf++ = 'o';
-      para[pargs++] = target_p->name;
-
-      if (pargs >= MAXMODEPARAMS)
-      {
-        /*
-         * Ok, the code is now going to "walk" through
-         * sendbuf, filling in para strings. So, I will use sptr
-         * to point into the sendbuf.
-         * Notice, that ircsprintf() returns the number of chars
-         * successfully inserted into string.
-         * - Dianora
-         */
-
-        sptr = sendbuf;
-        *mbuf = '\0';
-
-        for(lcount = 0; lcount < MAXMODEPARAMS; lcount++)
-        {
-          slen = sprintf(sptr, " %s", para[lcount]);  /* see? */
-          sptr += slen;  /* ready for next */
-        }
-        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
-                            servername, chptr->chname, modebuf, sendbuf);
-        mbuf = modebuf;
-        *mbuf++ = '+';
-
-        sendbuf[0] = '\0';
-        pargs = 0;
-      }
-    }
+      set_local_channel_statusmode(source_p, chptr, 'o', target_p->name);
 #ifdef HALFOPS
     if (fl & CHFL_HALFOP)
-    {
-      *mbuf++ = 'h';
-      para[pargs++] = target_p->name;
-
-      if (pargs >= MAXMODEPARAMS)
-      {
-        sptr = sendbuf;
-        *mbuf = '\0';
-        for(lcount = 0; lcount < MAXMODEPARAMS; lcount++)
-        {
-          slen = sprintf(sptr, " %s", para[lcount]);
-          sptr += slen;
-        }
-        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
-                             servername, chptr->chname, modebuf, sendbuf);
-
-        mbuf = modebuf;
-        *mbuf++ = '+';
-
-        sendbuf[0] = '\0';
-        pargs = 0;
-      }
-    }
+      set_local_channel_statusmode(source_p, chptr, 'h', target_p->name);
 #endif
     if (fl & CHFL_VOICE)
-    {
-      *mbuf++ = 'v';
-      para[pargs++] = target_p->name;
-
-      if (pargs >= MAXMODEPARAMS)
-      {
-        sptr = sendbuf;
-        *mbuf = '\0';
-        for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
-        {
-          slen = sprintf(sptr, " %s", para[lcount]);
-          sptr += slen;
-        }
-        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
-                             servername, chptr->chname, modebuf, sendbuf);
-
-        mbuf = modebuf;
-        *mbuf++ = '+';
-
-        sendbuf[0] = '\0';
-        pargs = 0;
-      }
-    }
+      set_local_channel_statusmode(source_p, chptr, 'v', target_p->name);
 
   nextnick:
     if ((s = p) == NULL)
@@ -910,6 +794,33 @@ remove_ban_list(struct Channel *chptr, struct Client *source_p,
   sendto_server(source_p, NOCAPS, CAP_TS6, ":%s %s %s", source_p->name, lmodebuf, lparabuf);
 }
 
+static void
+set_local_channel_statusmode(struct Client *source_p, struct Channel *chptr, char mode, const char *param)
+{
+  *mbuf++ = mode;
+  para[pargs++] = param;
+
+  if (pargs >= MAXMODEPARAMS)
+  {
+    char *sptr = sendbuf;
+    *mbuf = '\0';
+
+    for(int lcount = 0; lcount < MAXMODEPARAMS; lcount++)
+    {
+      int slen = sprintf(sptr, " %s", para[lcount]);
+      sptr += slen;
+    }
+    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s%s",
+                        (ConfigServerHide.hide_servers || IsHidden(source_p)) ? me.name : source_p->name,
+                         chptr->chname, modebuf, sendbuf);
+    mbuf = modebuf;
+    *mbuf++ = '+';
+
+    sendbuf[0] = '\0';
+    pargs = 0;
+  }
+}
+
 static struct Message sjoin_msgtab =
 {
   .cmd = "SJOIN",