]> jfr.im git - solanum.git/blobdiff - modules/core/m_mode.c
ircd: send tags on every message
[solanum.git] / modules / core / m_mode.c
index 25b251c5c7f5327c4b4b275e39b2b71b399ea77a..61f0ee3b35915cd4f4abca49cf1733474d4356aa 100644 (file)
  *  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 "tools.h"
-#include "balloc.h"
 #include "channel.h"
 #include "client.h"
 #include "hash.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "s_user.h"
 #include "s_conf.h"
 #include "s_serv.h"
-#include "s_log.h"
+#include "logger.h"
 #include "send.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
 #include "packet.h"
-#include "sprintf_irc.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_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 **);
 
 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, 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}
 };
 
-mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &bmask_msgtab, NULL };
+mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_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[0] - sender
  * 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;
@@ -92,7 +94,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;
                }
        }
 
@@ -101,13 +103,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);
@@ -116,7 +118,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 */
@@ -136,24 +138,19 @@ m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *p
        {
                msptr = find_channel_membership(chptr, source_p);
 
-               if(is_deop(msptr))
-                       return 0;
-
                /* Finish the flood grace period... */
                if(MyClient(source_p) && !IsFloodDone(source_p))
                {
-                       if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
+                       if(!((parc == 3) && (parv[2][0] == 'b' || parv[2][0] == 'q') && (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;
 
@@ -163,16 +160,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;
@@ -181,7 +176,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]);
@@ -190,12 +185,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,24 +200,76 @@ ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char
        {
                msptr = find_channel_membership(chptr, source_p);
 
-               /* this can still happen on a mixed ts network. */
-               if(is_deop(msptr))
-                       return 0;
-
                set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
        }
+}
+
+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;
+
+       /* Now, try to find the channel in question */
+       if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
+       {
+               sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
+               return;
+       }
+
+       chptr = find_channel(parv[2]);
+
+       if(chptr == NULL)
+       {
+               sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
+                                  form_str(ERR_NOSUCHCHANNEL), parv[2]);
+               return;
+       }
 
-       return 0;
+       /* TS is higher, drop it. */
+       if(atol(parv[1]) > chptr->channelts)
+               return;
+
+       if(IsServer(source_p))
+               set_channel_mlock(client_p, source_p, chptr, parv[3], true);
 }
 
-static int
-ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+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;
+
+       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 void
+ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        static char modebuf[BUFSIZE];
        static char parabuf[BUFSIZE];
        struct Channel *chptr;
-       dlink_list *banlist;
-       const char *s;
+       rb_dlink_list *banlist;
+       char *s, *forward;
        char *t;
        char *mbuf;
        char *pbuf;
@@ -237,14 +284,14 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
        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])
        {
@@ -276,7 +323,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';
@@ -287,7 +334,7 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
                fakesource_p = &me;
        else
                fakesource_p = source_p;
-       mlen = ircsprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
+       mlen = sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
        mbuf = modebuf + mlen;
        pbuf = parabuf;
 
@@ -317,7 +364,18 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
                if(tlen > MODEBUFLEN)
                        break;
 
-               if(add_id(fakesource_p, chptr, s, banlist, mode_type))
+               if((forward = strchr(s+1, '$')) != NULL)
+               {
+                       *forward++ = '\0';
+                       if(*forward == '\0')
+                               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))
                {
                        /* this new one wont fit.. */
                        if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
@@ -325,17 +383,18 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
                        {
                                *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);
+                               sendto_channel_local(fakesource_p, mems, chptr, "%s %s", modebuf, parabuf);
 
                                mbuf = modebuf + mlen;
                                pbuf = parabuf;
                                plen = modecount = 0;
                        }
 
+                       if (forward != NULL)
+                               forward[-1] = '$';
+
                        *mbuf++ = parv[3][0];
-                       arglen = ircsprintf(pbuf, "%s ", s);
+                       arglen = sprintf(pbuf, "%s ", s);
                        pbuf += arglen;
                        plen += arglen;
                        modecount++;
@@ -360,12 +419,9 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
        {
                *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);
+               sendto_channel_local(fakesource_p, mems, chptr, "%s %s", modebuf, parabuf);
        }
 
        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;
 }
-