]> jfr.im git - solanum.git/blobdiff - modules/core/m_message.c
Stop using chm_nosuch as a sentinel value (#53)
[solanum.git] / modules / core / m_message.c
index 227745d6b7e0c9fbe14f5fab399c31dff73cffba..8f9c7aa46a43d570eb068d0e65a1f93f6d662fa8 100644 (file)
@@ -49,6 +49,9 @@ static const char message_desc[] =
 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 m_echo(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+
+static void echo_msg(struct Client *, struct Client *, enum message_type, const char *);
 
 static void expire_tgchange(void *unused);
 static struct ev_entry *expire_tgchange_event;
@@ -75,8 +78,12 @@ struct Message notice_msgtab = {
        "NOTICE", 0, 0, 0, 0,
        {mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}}
 };
+struct Message echo_msgtab = {
+       "ECHO", 0, 0, 0, 0,
+       {mg_unreg, mg_ignore, {m_echo, 3}, mg_ignore, mg_ignore, mg_ignore}
+};
 
-mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, NULL };
+mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, &echo_msgtab, NULL };
 
 DECLARE_MODULE_AV2(message, modinit, moddeinit, message_clist, NULL, NULL, NULL, NULL, message_desc);
 
@@ -229,6 +236,26 @@ m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,
        }
 }
 
+static void
+m_echo(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
+               int parc, const char *parv[])
+{
+       struct Client *target_p = find_person(parv[2]);
+       enum message_type msgtype;
+
+       if (target_p == NULL)
+               return;
+
+       switch (parv[1][0])
+       {
+       case 'P': msgtype = MESSAGE_TYPE_PRIVMSG; break;
+       case 'N': msgtype = MESSAGE_TYPE_NOTICE; break;
+       default: return;
+       }
+
+       echo_msg(source_p, target_p, msgtype, parv[3]);
+}
+
 /*
  * build_target_list
  *
@@ -513,7 +540,7 @@ msg_channel(enum message_type msgtype,
        if((result = can_send(chptr, source_p, NULL)))
        {
                if(result != CAN_SEND_OPV && MyClient(source_p) &&
-                  !IsOper(source_p) &&
+                  !IsOperGeneral(source_p) &&
                   !add_channel_target(source_p, chptr))
                {
                        sendto_one(source_p, form_str(ERR_TARGCHANGE),
@@ -531,7 +558,7 @@ msg_channel(enum message_type msgtype,
                        (!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
                         IsMember(source_p, chptr)))
        {
-               if(MyClient(source_p) && !IsOper(source_p) &&
+               if(MyClient(source_p) && !IsOperGeneral(source_p) &&
                   !add_channel_target(source_p, chptr))
                {
                        sendto_one(source_p, form_str(ERR_TARGCHANGE),
@@ -698,6 +725,30 @@ expire_tgchange(void *unused)
        }
 }
 
+static void
+echo_msg(struct Client *source_p, struct Client *target_p,
+               enum message_type msgtype, const char *text)
+{
+       if (MyClient(target_p))
+       {
+               if (!IsCapable(target_p, CLICAP_ECHO_MESSAGE))
+                       return;
+
+               sendto_one(target_p, ":%s!%s@%s %s %s :%s",
+                               target_p->name, target_p->username, target_p->host,
+                               cmdname[msgtype],
+                               source_p->name,
+                               text);
+               return;
+       }
+
+       sendto_one(target_p, ":%s ECHO %c %s :%s",
+               use_id(source_p),
+               msgtype == MESSAGE_TYPE_PRIVMSG ? 'P' : 'N',
+               use_id(target_p),
+               text);
+}
+
 /*
  * msg_client
  *
@@ -724,7 +775,7 @@ msg_client(enum message_type msgtype,
                        source_p->localClient->last = rb_current_time();
 
                /* auto cprivmsg/cnotice */
-               do_floodcount = !IsOper(source_p) &&
+               do_floodcount = !IsOperGeneral(source_p) &&
                        !find_allowing_channel(source_p, target_p);
 
                /* target change stuff, dont limit ctcp replies as that
@@ -749,9 +800,6 @@ 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)
        {
@@ -765,22 +813,22 @@ msg_client(enum message_type msgtype,
                sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
                                   target_p->name, target_p->user->away);
 
-       if(MyClient(target_p))
-       {
-               hdata.msgtype = msgtype;
-               hdata.source_p = source_p;
-               hdata.target_p = target_p;
-               hdata.text = text;
-               hdata.approved = 0;
+       hdata.msgtype = msgtype;
+       hdata.source_p = source_p;
+       hdata.target_p = target_p;
+       hdata.text = text;
+       hdata.approved = 0;
 
-               call_hook(h_privmsg_user, &hdata);
+       call_hook(h_privmsg_user, &hdata);
 
-               /* buffer location may have changed. */
-               text = hdata.text;
+       /* buffer location may have changed. */
+       text = hdata.text;
 
-               if (hdata.approved != 0)
-                       return;
+       if (hdata.approved != 0)
+               return;
 
+       if(MyClient(target_p))
+       {
                if (EmptyString(text))
                {
                        /* could be empty after colour stripping and
@@ -792,6 +840,7 @@ msg_client(enum message_type msgtype,
 
                add_reply_target(target_p, source_p);
                sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text);
+               echo_msg(target_p, source_p, msgtype, text);
        }
        else
                sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text);
@@ -957,6 +1006,14 @@ handle_special(enum message_type msgtype, struct Client *client_p,
                        return;
                }
 
+               if(MyClient(source_p))
+               {
+                       sendto_realops_snomask(SNO_GENERAL, L_ALL | L_NETWIDE, "%s sent mass-%s to %s: %s",
+                                       get_oper_name(source_p),
+                                       msgtype == MESSAGE_TYPE_PRIVMSG ? "privmsg" : "notice",
+                                       nick, text);
+               }
+
                sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p,
                                    nick + 1,
                                    (*nick == '#') ? MATCH_HOST : MATCH_SERVER,