]> jfr.im git - solanum.git/blobdiff - modules/core/m_mode.c
add help for `chm_regmsg`
[solanum.git] / modules / core / m_mode.c
index f4b837bc4d132486414cadf8f90aa588f9f0fdc8..b42875efabaa310711ca127daca16d335efbb31f 100644 (file)
@@ -20,8 +20,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id: m_mode.c 1006 2006-03-09 15:32:14Z nenolod $
  */
 
 #include "stdinc.h"
 #include "packet.h"
 #include "s_newconf.h"
 
-static int m_mode(struct Client *, struct Client *, int, const char **);
-static int ms_mode(struct Client *, struct Client *, int, const char **);
-static int ms_tmode(struct Client *, struct Client *, int, const char **);
-static int ms_mlock(struct Client *, struct Client *, int, const char **);
-static int ms_bmask(struct Client *, struct Client *, int, const char **);
+static const char mode_desc[] =
+       "Provides the MODE and MLOCK client and server commands, and TS6 server-to-server TMODE and BMASK commands";
+
+static void m_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_tmode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_mlock(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_bmask(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_ebmask(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message mode_msgtab = {
-       "MODE", 0, 0, 0, MFLG_SLOW,
+       "MODE", 0, 0, 0, 0,
        {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}}
 };
 struct Message tmode_msgtab = {
-       "TMODE", 0, 0, 0, MFLG_SLOW,
+       "TMODE", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore}
 };
 struct Message mlock_msgtab = {
-       "MLOCK", 0, 0, 0, MFLG_SLOW,
+       "MLOCK", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore}
 };
 struct Message bmask_msgtab = {
-       "BMASK", 0, 0, 0, MFLG_SLOW,
+       "BMASK", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore}
 };
+struct Message ebmask_msgtab = {
+       "EBMASK", 0, 0, 0, 0,
+       {mg_ignore, mg_ignore, mg_ignore, {ms_ebmask, 5}, mg_ignore, mg_ignore}
+};
 
-mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL };
+mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, &ebmask_msgtab, NULL };
 
-DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $");
+DECLARE_MODULE_AV2(mode, NULL, NULL, mode_clist, NULL, NULL, NULL, NULL, mode_desc);
 
 /*
  * m_mode - MODE command handler
  * parv[1] - channel
  */
-static int
-m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+m_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Channel *chptr = NULL;
        struct membership *msptr;
@@ -93,7 +99,7 @@ m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *p
                {
                        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
                                   me.name, source_p->name, "MODE");
-                       return 0;
+                       return;
                }
        }
 
@@ -102,13 +108,13 @@ m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *p
        {
                /* if here, it has to be a non-channel name */
                user_mode(client_p, source_p, parc, parv);
-               return 0;
+               return;
        }
 
        if(!check_channel_name(dest))
        {
                sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
-               return 0;
+               return;
        }
 
        chptr = find_channel(dest);
@@ -117,7 +123,7 @@ m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *p
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
                                   form_str(ERR_NOSUCHCHANNEL), parv[1]);
-               return 0;
+               return;
        }
 
        /* Now know the channel exists */
@@ -131,27 +137,18 @@ m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *p
                           operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p));
 
                sendto_one(source_p, form_str(RPL_CREATIONTIME),
-                          me.name, source_p->name, parv[1], chptr->channelts);
+                          me.name, source_p->name, parv[1], (long long)chptr->channelts);
        }
        else
        {
                msptr = find_channel_membership(chptr, source_p);
 
-               /* Finish the flood grace period... */
-               if(MyClient(source_p) && !IsFloodDone(source_p))
-               {
-                       if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
-                               flood_endgrace(source_p);
-               }
-
                set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n);
        }
-
-       return 0;
 }
 
-static int
-ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+ms_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Channel *chptr;
 
@@ -161,16 +158,14 @@ ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
                                   form_str(ERR_NOSUCHCHANNEL), parv[1]);
-               return 0;
+               return;
        }
 
        set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
-
-       return 0;
 }
 
-static int
-ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+ms_tmode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Channel *chptr = NULL;
        struct membership *msptr;
@@ -179,7 +174,7 @@ ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char
        if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
        {
                sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
-               return 0;
+               return;
        }
 
        chptr = find_channel(parv[2]);
@@ -188,12 +183,12 @@ ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
                                   form_str(ERR_NOSUCHCHANNEL), parv[2]);
-               return 0;
+               return;
        }
 
        /* TS is higher, drop it. */
        if(atol(parv[1]) > chptr->channelts)
-               return 0;
+               return;
 
        if(IsServer(source_p))
        {
@@ -205,12 +200,10 @@ ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char
 
                set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
        }
-
-       return 0;
 }
 
-static int
-ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Channel *chptr = NULL;
 
@@ -218,7 +211,7 @@ ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char
        if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
        {
                sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
-               return 0;
+               return;
        }
 
        chptr = find_channel(parv[2]);
@@ -227,30 +220,60 @@ ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
                                   form_str(ERR_NOSUCHCHANNEL), parv[2]);
-               return 0;
+               return;
        }
 
        /* TS is higher, drop it. */
        if(atol(parv[1]) > chptr->channelts)
-               return 0;
+               return;
 
        if(IsServer(source_p))
-               set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE);
+               set_channel_mlock(client_p, source_p, chptr, parv[3], true);
+}
+
+static void
+possibly_remove_lower_forward(struct Client *fakesource_p, int mems,
+               struct Channel *chptr, rb_dlink_list *banlist, int mchar,
+               const char *mask, const char *forward)
+{
+       struct Ban *actualBan;
+       rb_dlink_node *ptr;
 
-       return 0;
+       RB_DLINK_FOREACH(ptr, banlist->head)
+       {
+               actualBan = ptr->data;
+               if(!irccmp(actualBan->banstr, mask) &&
+                               (actualBan->forward == NULL ||
+                                irccmp(actualBan->forward, forward) < 0))
+               {
+                       sendto_channel_local(fakesource_p, mems, chptr, ":%s MODE %s -%c %s%s%s",
+                                       fakesource_p->name,
+                                       chptr->chname,
+                                       mchar,
+                                       actualBan->banstr,
+                                       actualBan->forward ? "$" : "",
+                                       actualBan->forward ? actualBan->forward : "");
+                       rb_dlinkDelete(&actualBan->node, banlist);
+                       free_ban(actualBan);
+                       return;
+               }
+       }
 }
 
-static int
-ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+do_bmask(bool extended, struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       static char modebuf[BUFSIZE];
+       static char output[BUFSIZE];
        static char parabuf[BUFSIZE];
+       static char degrade[BUFSIZE];
+       static char squitreason[120];
        struct Channel *chptr;
+       struct Ban *banptr;
        rb_dlink_list *banlist;
-       char *s, *forward;
-       char *t;
-       char *mbuf;
-       char *pbuf;
+       char *s, *mask, *forward, *who;
+       char *output_ptr;
+       char *param_ptr;
+       char *degrade_ptr;
        long mode_type;
        int mlen;
        int plen = 0;
@@ -259,17 +282,18 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
        int modecount = 0;
        int needcap = NOCAPS;
        int mems;
+       time_t when = (long)rb_current_time();
        struct Client *fakesource_p;
 
        if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
-               return 0;
+               return;
 
        if((chptr = find_channel(parv[2])) == NULL)
-               return 0;
+               return;
 
        /* TS is higher, drop it. */
        if(atol(parv[1]) > chptr->channelts)
-               return 0;
+               return;
 
        switch (parv[3][0])
        {
@@ -301,7 +325,7 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
 
                /* maybe we should just blindly propagate this? */
        default:
-               return 0;
+               return;
        }
 
        parabuf[0] = '\0';
@@ -312,29 +336,29 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
                fakesource_p = &me;
        else
                fakesource_p = source_p;
-       mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
-       mbuf = modebuf + mlen;
-       pbuf = parabuf;
+       who = fakesource_p->name;
+
+       mlen = sprintf(output, ":%s MODE %s +", fakesource_p->name, chptr->chname);
+       output_ptr = output + mlen;
+       param_ptr = parabuf;
+       degrade_ptr = degrade;
 
        while(*s == ' ')
                s++;
 
-       /* next char isnt a space, point t to the next one */
-       if((t = strchr(s, ' ')) != NULL)
-       {
-               *t++ = '\0';
-
-               /* double spaces will break the parser */
-               while(*t == ' ')
-                       t++;
-       }
+       s = strtok(s, " ");
 
-       /* couldve skipped spaces and got nothing.. */
        while(!EmptyString(s))
        {
-               /* ban with a leading ':' -- this will break the protocol */
                if(*s == ':')
-                       goto nextban;
+               {
+                       /* ban with a leading ':' -- this will break the protocol */
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
+                               "Link %s dropped, invalid BMASK mask (%s)", source_p->name, s);
+                       snprintf(squitreason, sizeof squitreason, "Invalid BMASK mask (%s)", s);
+                       exit_client(client_p, client_p, client_p, squitreason);
+                       return;
+               }
 
                tlen = strlen(s);
 
@@ -346,58 +370,90 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
                {
                        *forward++ = '\0';
                        if(*forward == '\0')
-                               forward = NULL;
+                               tlen--, forward = NULL;
+                       else
+                               possibly_remove_lower_forward(fakesource_p,
+                                               mems, chptr, banlist,
+                                               parv[3][0], s, forward);
                }
 
-               if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type))
+               mask = s;
+               if (extended) {
+                       when = atol(strtok(NULL, " "));
+                       who = strtok(NULL, " ");
+                       if (who == NULL)
+                       {
+                               /* EBMASK params don't divide by 3, so we have an incomplete chunk */
+                               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
+                                       "Link %s dropped, invalid EBMASK chunk", source_p->name);
+                               snprintf(squitreason, sizeof squitreason, "Invalid EBMASK chunk");
+                               exit_client(client_p, client_p, client_p, squitreason);
+                               return;
+                       }
+
+                       arglen = sprintf(degrade_ptr, "%s ", mask);
+                       degrade_ptr += arglen;
+               }
+
+               if((banptr = add_id(fakesource_p, chptr, mask, forward, banlist, mode_type)) != NULL)
                {
+                       banptr->when = when;
+                       rb_free(banptr->who);
+                       banptr->who = rb_strdup(who);
+
                        /* this new one wont fit.. */
                        if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
                           modecount >= MAXMODEPARAMS)
                        {
-                               *mbuf = '\0';
-                               *(pbuf - 1) = '\0';
-                               sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
-                               sendto_server(client_p, chptr, needcap, CAP_TS6,
-                                             "%s %s", modebuf, parabuf);
-
-                               mbuf = modebuf + mlen;
-                               pbuf = parabuf;
+                               *output_ptr = '\0';
+                               *(param_ptr - 1) = '\0';
+                               sendto_channel_local(fakesource_p, mems, chptr, "%s %s", output, parabuf);
+
+                               output_ptr = output + mlen;
+                               param_ptr = parabuf;
                                plen = modecount = 0;
                        }
 
-                       *mbuf++ = parv[3][0];
-                       arglen = rb_sprintf(pbuf, "%s ", s);
-                       pbuf += arglen;
+                       if (forward != NULL)
+                               forward[-1] = '$';
+
+                       *output_ptr++ = parv[3][0];
+                       arglen = sprintf(param_ptr, "%s ", mask);
+                       param_ptr += arglen;
                        plen += arglen;
                        modecount++;
                }
 
-             nextban:
-               s = t;
-
-               if(s != NULL)
-               {
-                       if((t = strchr(s, ' ')) != NULL)
-                       {
-                               *t++ = '\0';
-
-                               while(*t == ' ')
-                                       t++;
-                       }
-               }
+               s = strtok(NULL, " ");
        }
 
        if(modecount)
        {
-               *mbuf = '\0';
-               *(pbuf - 1) = '\0';
-               sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
-               sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf);
+               *output_ptr = '\0';
+               *(param_ptr - 1) = '\0';
+               sendto_channel_local(fakesource_p, mems, chptr, "%s %s", output, parabuf);
+       }
+
+       if (extended) {
+               *(degrade_ptr - 1) = '\0';
+               sendto_server(client_p, chptr, CAP_EBMASK | CAP_TS6 | needcap, NOCAPS, ":%s EBMASK %ld %s %s :%s",
+                             source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
+               sendto_server(client_p, chptr, CAP_TS6 | needcap, CAP_EBMASK, ":%s BMASK %ld %s %s :%s",
+                             source_p->id, (long) chptr->channelts, chptr->chname, parv[3], degrade);
        }
+       else
+               sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
+                             source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
+}
 
-       sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
-                     source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
-       return 0;
+static void
+ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+{
+       do_bmask(false, msgbuf_p, client_p, source_p, parc, parv);
+}
+static void
+ms_ebmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+{
+       do_bmask(true, msgbuf_p, client_p, source_p, parc, parv);
 }