]> jfr.im git - solanum.git/blobdiff - modules/core/m_message.c
Merge pull request #334 from edk0/massnotice
[solanum.git] / modules / core / m_message.c
index 21d3578ec2c02f742b591a729fbfbb53f97323e5..3c31554a65d0f7658cd259d8f6953e845dc13775 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_message.c 3173 2007-01-31 23:57:18Z jilles $
  */
 
 #include "stdinc.h"
 #include "client.h"
 #include "ircd.h"
 #include "numeric.h"
-#include "common.h"
 #include "s_conf.h"
 #include "s_serv.h"
 #include "msg.h"
 #include "tgchange.h"
 #include "inline/stringops.h"
 
-static int m_message(enum message_type, struct Client *, struct Client *, int, const char **);
-static int m_privmsg(struct Client *, struct Client *, int, const char **);
-static int m_notice(struct Client *, struct Client *, int, const char **);
+static const char message_desc[] =
+       "Provides the PRIVMSG and NOTICE commands to send messages to users and channels";
+
+static void m_message(enum message_type, struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_privmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_notice(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 static void expire_tgchange(void *unused);
 static struct ev_entry *expire_tgchange_event;
@@ -68,17 +68,17 @@ moddeinit(void)
 }
 
 struct Message privmsg_msgtab = {
-       "PRIVMSG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
+       "PRIVMSG", 0, 0, 0, 0,
        {mg_unreg, {m_privmsg, 0}, {m_privmsg, 0}, mg_ignore, mg_ignore, {m_privmsg, 0}}
 };
 struct Message notice_msgtab = {
-       "NOTICE", 0, 0, 0, MFLG_SLOW,
+       "NOTICE", 0, 0, 0, 0,
        {mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}}
 };
 
 mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, NULL };
 
-DECLARE_MODULE_AV1(message, modinit, moddeinit, message_clist, NULL, NULL, "$Revision: 3173 $");
+DECLARE_MODULE_AV2(message, modinit, moddeinit, message_clist, NULL, NULL, NULL, NULL, message_desc);
 
 struct entity
 {
@@ -91,7 +91,7 @@ static int build_target_list(enum message_type msgtype,
                             struct Client *client_p,
                             struct Client *source_p, const char *nicks_channels, const char *text);
 
-static int flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p);
+static bool flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p);
 
 /* Fifteen seconds should be plenty for a client to reply a ctcp */
 #define LARGE_CTCP_TIME 15
@@ -105,7 +105,7 @@ static int flood_attack_client(enum message_type msgtype, struct Client *source_
 static struct entity targets[512];
 static int ntargets = 0;
 
-static int duplicate_ptr(void *);
+static bool duplicate_ptr(void *);
 
 static void msg_channel(enum message_type msgtype,
                        struct Client *client_p,
@@ -151,16 +151,16 @@ const char *cmdname[MESSAGE_TYPE_COUNT] = {
        [MESSAGE_TYPE_NOTICE] = "NOTICE",
 };
 
-static int
-m_privmsg(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+m_privmsg(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       return m_message(MESSAGE_TYPE_PRIVMSG, client_p, source_p, parc, parv);
+       m_message(MESSAGE_TYPE_PRIVMSG, msgbuf_p, client_p, source_p, parc, parv);
 }
 
-static int
-m_notice(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+m_notice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       return m_message(MESSAGE_TYPE_NOTICE, client_p, source_p, parc, parv);
+       m_message(MESSAGE_TYPE_NOTICE, msgbuf_p, client_p, source_p, parc, parv);
 }
 
 /*
@@ -169,8 +169,8 @@ m_notice(struct Client *client_p, struct Client *source_p, int parc, const char
  *             - pointer to source_p
  *             - pointer to channel
  */
-static int
-m_message(enum message_type msgtype,
+static void
+m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,
          struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        int i;
@@ -180,14 +180,14 @@ m_message(enum message_type msgtype,
                if(msgtype != MESSAGE_TYPE_NOTICE)
                        sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name,
                                   source_p->name, cmdname[msgtype]);
-               return 0;
+               return;
        }
 
        if(parc < 3 || EmptyString(parv[2]))
        {
                if(msgtype != MESSAGE_TYPE_NOTICE)
                        sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
-               return 0;
+               return;
        }
 
        /* Finish the flood grace period if theyre not messaging themselves
@@ -198,7 +198,7 @@ m_message(enum message_type msgtype,
 
        if(build_target_list(msgtype, client_p, source_p, parv[1], parv[2]) < 0)
        {
-               return 0;
+               return;
        }
 
        for(i = 0; i < ntargets; i++)
@@ -227,8 +227,6 @@ m_message(enum message_type msgtype,
                        break;
                }
        }
-
-       return 0;
 }
 
 /*
@@ -246,7 +244,6 @@ m_message(enum message_type msgtype,
  *               all the classic old bizzare oper privmsg tricks
  *               are parsed and sent as is, if prefixed with $
  *               to disambiguate.
- *
  */
 
 static int
@@ -364,7 +361,7 @@ build_target_list(enum message_type msgtype, struct Client *client_p,
                                                   get_id(&me, source_p),
                                                   get_id(source_p, source_p),
                                                   with_prefix);
-                                       return (-1);
+                                       continue;
                                }
 
                                if(!duplicate_ptr(chptr))
@@ -447,18 +444,18 @@ build_target_list(enum message_type msgtype, struct Client *client_p,
  * inputs      - pointer to check
  *             - pointer to table of entities
  *             - number of valid entities so far
- * output      - YES if duplicate pointer in table, NO if not.
+ * output      - true if duplicate pointer in table, false if not.
  *               note, this does the canonize using pointers
  * side effects        - NONE
  */
-static int
+static bool
 duplicate_ptr(void *ptr)
 {
        int i;
        for(i = 0; i < ntargets; i++)
                if(targets[i].ptr == ptr)
-                       return YES;
-       return NO;
+                       return true;
+       return false;
 }
 
 /*
@@ -479,7 +476,6 @@ msg_channel(enum message_type msgtype,
            const char *text)
 {
        int result;
-       char text2[BUFSIZE];
        hook_data_privmsg_channel hdata;
 
        if(MyClient(source_p))
@@ -489,21 +485,6 @@ msg_channel(enum message_type msgtype,
                        source_p->localClient->last = rb_current_time();
        }
 
-       if(chptr->mode.mode & MODE_NOCOLOR)
-       {
-               rb_strlcpy(text2, text, BUFSIZE);
-               strip_colour(text2);
-               text = text2;
-               if (EmptyString(text))
-               {
-                       /* could be empty after colour stripping and
-                        * that would cause problems later */
-                       if(msgtype != MESSAGE_TYPE_NOTICE)
-                               sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
-                       return;
-               }
-       }
-
        hdata.msgtype = msgtype;
        hdata.source_p = source_p;
        hdata.chptr = chptr;
@@ -518,6 +499,16 @@ msg_channel(enum message_type msgtype,
        if (hdata.approved != 0)
                return;
 
+       /* hook may have reduced the string to nothing. */
+       if (EmptyString(text))
+       {
+               /* could be empty after colour stripping and
+                * that would cause problems later */
+               if(msgtype != MESSAGE_TYPE_NOTICE)
+                       sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
+               return;
+       }
+
        /* chanops and voiced can flood their own channel with impunity */
        if((result = can_send(chptr, source_p, NULL)))
        {
@@ -532,18 +523,6 @@ msg_channel(enum message_type msgtype,
                if(result == CAN_SEND_OPV ||
                   !flood_attack_channel(msgtype, source_p, chptr, chptr->chname))
                {
-                       if (msgtype != MESSAGE_TYPE_NOTICE && *text == '\001' &&
-                                       strncasecmp(text + 1, "ACTION ", 7))
-                       {
-                               if (chptr->mode.mode & MODE_NOCTCP)
-                               {
-                                       sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
-                                                          form_str(ERR_CANNOTSENDTOCHAN), chptr->chname);
-                                       return;
-                               }
-                               else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2))
-                                       source_p->large_ctcp_sent = rb_current_time();
-                       }
                        sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr,
                                             "%s %s :%s", cmdname[msgtype], chptr->chname, text);
                }
@@ -589,24 +568,8 @@ msg_channel_opmod(enum message_type msgtype,
                  struct Client *client_p, struct Client *source_p,
                  struct Channel *chptr, const char *text)
 {
-       char text2[BUFSIZE];
        hook_data_privmsg_channel hdata;
 
-       if(chptr->mode.mode & MODE_NOCOLOR)
-       {
-               rb_strlcpy(text2, text, BUFSIZE);
-               strip_colour(text2);
-               text = text2;
-               if (EmptyString(text))
-               {
-                       /* could be empty after colour stripping and
-                        * that would cause problems later */
-                       if(msgtype != MESSAGE_TYPE_NOTICE)
-                               sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
-                       return;
-               }
-       }
-
        hdata.msgtype = msgtype;
        hdata.source_p = source_p;
        hdata.chptr = chptr;
@@ -621,6 +584,16 @@ msg_channel_opmod(enum message_type msgtype,
        if (hdata.approved != 0)
                return;
 
+       /* hook may have reduced the string to nothing. */
+       if (EmptyString(text))
+       {
+               /* could be empty after colour stripping and
+                * that would cause problems later */
+               if(msgtype != MESSAGE_TYPE_NOTICE)
+                       sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
+               return;
+       }
+
        if(chptr->mode.mode & MODE_OPMODERATE &&
                        (!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
                         IsMember(source_p, chptr)))
@@ -642,7 +615,7 @@ msg_channel_opmod(enum message_type msgtype,
 /*
  * msg_channel_flags
  *
- * inputs      - flag 0 if PRIVMSG 1 if NOTICE. RFC 
+ * inputs      - flag 0 if PRIVMSG 1 if NOTICE. RFC
  *               say NOTICE must not auto reply
  *             - pointer to client_p
  *             - pointer to source_p
@@ -656,7 +629,6 @@ static void
 msg_channel_flags(enum message_type msgtype, struct Client *client_p,
                  struct Client *source_p, struct Channel *chptr, int flags, const char *text)
 {
-       char text2[BUFSIZE];
        int type;
        char c;
        hook_data_privmsg_channel hdata;
@@ -679,21 +651,6 @@ msg_channel_flags(enum message_type msgtype, struct Client *client_p,
                        source_p->localClient->last = rb_current_time();
        }
 
-       if(chptr->mode.mode & MODE_NOCOLOR)
-       {
-               rb_strlcpy(text2, text, BUFSIZE);
-               strip_colour(text2);
-               text = text2;
-               if (EmptyString(text))
-               {
-                       /* could be empty after colour stripping and
-                        * that would cause problems later */
-                       if(msgtype != MESSAGE_TYPE_NOTICE)
-                               sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
-                       return;
-               }
-       }
-
        hdata.msgtype = msgtype;
        hdata.source_p = source_p;
        hdata.chptr = chptr;
@@ -708,23 +665,13 @@ msg_channel_flags(enum message_type msgtype, struct Client *client_p,
        if (hdata.approved != 0)
                return;
 
-       if (msgtype != MESSAGE_TYPE_NOTICE && *text == '\001' &&
-                       strncasecmp(text + 1, "ACTION ", 7))
+       if (EmptyString(text))
        {
-               if (chptr->mode.mode & MODE_NOCTCP)
-               {
-                       sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
-                                          form_str(ERR_CANNOTSENDTOCHAN), chptr->chname);
-                       return;
-               }
-               else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2))
-               {
-                       /* This overestimates the number of users the CTCP
-                        * is being sent to, so large_ctcp_sent might be
-                        * set inappropriately. This should not be a problem.
-                        */
-                       source_p->large_ctcp_sent = rb_current_time();
-               }
+               /* could be empty after colour stripping and
+                * that would cause problems later */
+               if(msgtype != MESSAGE_TYPE_NOTICE)
+                       sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
+               return;
        }
 
        sendto_channel_flags(client_p, type, source_p, chptr, "%s %c%s :%s",
@@ -754,7 +701,7 @@ expire_tgchange(void *unused)
 /*
  * msg_client
  *
- * inputs      - flag 0 if PRIVMSG 1 if NOTICE. RFC 
+ * inputs      - flag 0 if PRIVMSG 1 if NOTICE. RFC
  *               say NOTICE must not auto reply
  *             - pointer to source_p source (struct Client *)
  *             - pointer to target_p target (struct Client *)
@@ -777,12 +724,14 @@ msg_client(enum message_type msgtype,
                 * as a way to taunt users, e.g. harass them and hide behind +g
                 * as a way of griefing.  --nenolod
                 */
-               if(msgtype != MESSAGE_TYPE_NOTICE && IsSetCallerId(source_p) &&
+               if(msgtype != MESSAGE_TYPE_NOTICE &&
+                               (IsSetCallerId(source_p) ||
+                                (IsSetRegOnlyMsg(source_p) && !target_p->user->suser[0])) &&
                                !accept_message(target_p, source_p) &&
                                !IsOper(target_p))
                {
                        if(rb_dlink_list_length(&source_p->localClient->allow_list) <
-                                       ConfigFileEntry.max_accept)
+                                       (unsigned long)ConfigFileEntry.max_accept)
                        {
                                rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
                                rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
@@ -796,7 +745,7 @@ msg_client(enum message_type msgtype,
                        }
                }
 
-               /* reset idle time for message only if its not to self 
+               /* reset idle time for message only if its not to self
                 * and its not a notice */
                if(msgtype != MESSAGE_TYPE_NOTICE)
                        source_p->localClient->last = rb_current_time();
@@ -827,6 +776,9 @@ msg_client(enum message_type msgtype,
                if (do_floodcount &&
                                flood_attack_client(msgtype, source_p, target_p))
                        return;
+
+               if (IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p != source_p)
+                       sendto_anywhere_echo(target_p, source_p, cmdname[msgtype], ":%s", text);
        }
        else if(source_p->from == target_p->from)
        {
@@ -856,6 +808,15 @@ msg_client(enum message_type msgtype,
                if (hdata.approved != 0)
                        return;
 
+               if (EmptyString(text))
+               {
+                       /* could be empty after colour stripping and
+                        * that would cause problems later */
+                       if(msgtype != MESSAGE_TYPE_NOTICE)
+                               sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
+                       return;
+               }
+
                /* XXX Controversial? allow opers always to send through a +g */
                if(!IsServer(source_p) && (IsSetCallerId(target_p) ||
                                        (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])))
@@ -918,13 +879,13 @@ msg_client(enum message_type msgtype,
 /*
  * flood_attack_client
  * inputs       - flag 0 if PRIVMSG 1 if NOTICE. RFC
- *                say NOTICE must not auto reply
- *              - pointer to source Client 
+ *                says NOTICE must not auto reply
+ *              - pointer to source Client
  *             - pointer to target Client
- * output      - 1 if target is under flood attack
+ * output      - true if target is under flood attack
  * side effects        - check for flood attack on target target_p
  */
-static int
+static bool
 flood_attack_client(enum message_type msgtype, struct Client *source_p, struct Client *target_p)
 {
        int delta;
@@ -966,13 +927,13 @@ flood_attack_client(enum message_type msgtype, struct Client *source_p, struct C
                                sendto_one(source_p,
                                           ":%s NOTICE %s :*** Message to %s throttled due to flooding",
                                           me.name, source_p->name, target_p->name);
-                       return 1;
+                       return true;
                }
                else
                        target_p->received_number_of_privmsgs++;
        }
 
-       return 0;
+       return false;
 }
 
 /*
@@ -997,7 +958,6 @@ handle_special(enum message_type msgtype, struct Client *client_p,
 {
        struct Client *target_p;
        char *server;
-       char *s;
 
        /* user[%host]@server addressed?
         * NOTE: users can send to user@server, but not user%host@server
@@ -1074,22 +1034,6 @@ handle_special(enum message_type msgtype, struct Client *client_p,
                        return;
                }
 
-               if((s = strrchr(nick, '.')) == NULL)
-               {
-                       sendto_one_numeric(source_p, ERR_NOTOPLEVEL,
-                                          form_str(ERR_NOTOPLEVEL), nick);
-                       return;
-               }
-               while(*++s)
-                       if(*s == '.' || *s == '*' || *s == '?')
-                               break;
-               if(*s == '*' || *s == '?')
-               {
-                       sendto_one_numeric(source_p, ERR_WILDTOPLEVEL,
-                                          form_str(ERR_WILDTOPLEVEL), nick);
-                       return;
-               }
-
                sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p,
                                    nick + 1,
                                    (*nick == '#') ? MATCH_HOST : MATCH_SERVER,