]> jfr.im git - solanum.git/blobdiff - modules/core/m_part.c
ircd: send tags on every message
[solanum.git] / modules / core / m_part.c
index d31da2f5c6474d0b82933b928342980811f311b7..6a778b28ae685bd93c69c18ed50bd096286b89b1 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_part.c 98 2005-09-11 03:37:47Z nenolod $
  */
 
 #include "stdinc.h"
-#include "tools.h"
 #include "channel.h"
 #include "client.h"
-#include "common.h"
 #include "hash.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "send.h"
 #include "modules.h"
 #include "s_conf.h"
 #include "packet.h"
+#include "inline/stringops.h"
+#include "hook.h"
+
+static const char part_desc[] = "Provides the PART command to leave a channel";
 
-static int m_part(struct Client *, struct Client *, int, const char **);
+static void m_part(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message part_msgtab = {
-       "PART", 0, 0, 0, MFLG_SLOW,
+       "PART", 0, 0, 0, 0,
        {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}}
 };
 
 mapi_clist_av1 part_clist[] = { &part_msgtab, NULL };
 
-DECLARE_MODULE_AV1(part, NULL, NULL, part_clist, NULL, NULL, "$Revision: 98 $");
+DECLARE_MODULE_AV2(part, NULL, NULL, part_clist, NULL, NULL, NULL, NULL, part_desc);
 
 static void part_one_client(struct Client *client_p,
-                           struct Client *source_p, char *name, char *reason);
+                           struct Client *source_p, char *name,
+                           const char *reason);
+static bool can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr);
+static bool do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason);
 
 
 /*
 ** m_part
-**      parv[0] = sender prefix
 **      parv[1] = channel
 **      parv[2] = reason
 */
-static int
-m_part(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+m_part(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        char *p, *name;
        char reason[REASONLEN + 1];
@@ -72,22 +74,19 @@ m_part(struct Client *client_p, struct Client *source_p, int parc, const char *p
        reason[0] = '\0';
 
        if(parc > 2)
-               strlcpy(reason, parv[2], sizeof(reason));
+               rb_strlcpy(reason, parv[2], sizeof(reason));
 
-       name = strtoken(&p, s, ",");
+       name = rb_strtok_r(s, ",", &p);
 
        /* Finish the flood grace period... */
        if(MyClient(source_p) && !IsFloodDone(source_p))
                flood_endgrace(source_p);
 
-       strip_colour(reason);
-
        while(name)
        {
                part_one_client(client_p, source_p, name, reason);
-               name = strtoken(&p, NULL, ",");
+               name = rb_strtok_r(NULL, ",", &p);
        }
-       return 0;
 }
 
 /*
@@ -97,10 +96,10 @@ m_part(struct Client *client_p, struct Client *source_p, int parc, const char *p
  *             - pointer to source client to remove
  *             - char pointer of name of channel to remove from
  * output      - none
- * side effects        - remove ONE client given the channel name 
+ * side effects        - remove ONE client given the channel name
  */
 static void
-part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason)
+part_one_client(struct Client *client_p, struct Client *source_p, char *name, const char *reason)
 {
        struct Channel *chptr;
        struct membership *msptr;
@@ -125,16 +124,16 @@ part_one_client(struct Client *client_p, struct Client *source_p, char *name, ch
         *  Remove user from the old channel (if any)
         *  only allow /part reasons in -m chans
         */
-       if(reason[0] && (is_chanop(msptr) || !MyConnect(source_p) ||
-                        ((can_send(chptr, source_p, msptr) > 0 &&
-                          (source_p->localClient->firsttime +
-                           ConfigFileEntry.anti_spam_exit_message_time) < CurrentTime))))
+       if(!EmptyString(reason) &&
+               (!MyConnect(source_p) ||
+                (can_send_part(source_p, chptr, msptr) && do_message_hook(source_p, chptr, &reason))
+               )
+         )
        {
+
                sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
                              ":%s PART %s :%s", use_id(source_p), chptr->chname, reason);
-               sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
-                             ":%s PART %s :%s", source_p->name, chptr->chname, reason);
-               sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
+               sendto_channel_local(source_p, ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
                                     source_p->name, source_p->username,
                                     source_p->host, chptr->chname, reason);
        }
@@ -142,11 +141,65 @@ part_one_client(struct Client *client_p, struct Client *source_p, char *name, ch
        {
                sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
                              ":%s PART %s", use_id(source_p), chptr->chname);
-               sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
-                             ":%s PART %s", source_p->name, chptr->chname);
-               sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",
+               sendto_channel_local(source_p, ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",
                                     source_p->name, source_p->username,
                                     source_p->host, chptr->chname);
        }
        remove_user_from_channel(msptr);
 }
+
+/*
+ * can_send_part - whether a part message can be sent.
+ *
+ * inputs:
+ *    - client parting
+ *    - channel being parted
+ *    - membership pointer
+ * outputs:
+ *    - true if message allowed
+ *    - false if message denied
+ * side effects:
+ *    - none.
+ */
+static bool
+can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr)
+{
+       if (!can_send(chptr, source_p, msptr))
+               return false;
+       /* Allow chanops to bypass anti_spam_exit_message_time for part messages. */
+       if (is_chanop(msptr))
+               return true;
+       return (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time();
+}
+
+/*
+ * do_message_hook - execute the message hook on a part message reason.
+ *
+ * inputs:
+ *    - client parting
+ *    - channel being parted
+ *    - pointer to reason
+ * outputs:
+ *    - true if message is allowed
+ *    - false if message is denied or message is now empty
+ * side effects:
+ *    - reason may be modified.
+ */
+static bool
+do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason)
+{
+       hook_data_privmsg_channel hdata;
+
+       hdata.msgtype = MESSAGE_TYPE_PART;
+       hdata.source_p = source_p;
+       hdata.chptr = chptr;
+       hdata.text = *reason;
+       hdata.approved = 0;
+
+       call_hook(h_privmsg_channel, &hdata);
+
+       /* The reason may have been changed by a hook... */
+       *reason = hdata.text;
+
+       return (hdata.approved == 0 && !EmptyString(*reason));
+}