Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_clearmode.c
index 53cbc12c21f234ff8806cadd040be71421f2ef81..cbd961f88ce6629e0b81b649d0e71776c12e6055 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "client.h"
 #include "channel.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_features.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "send.h"
+#include "support.h"
 
 #include <assert.h>
 
@@ -156,23 +153,22 @@ do_clearmode(struct Client *cptr, struct Client *sptr, struct Channel *chptr,
                MODEBUF_DEST_OPMODE  | /* Treat it like an OPMODE */
                MODEBUF_DEST_HACK4));  /* Generate a HACK(4) notice */
 
-  modebuf_mode(&mbuf, MODE_DEL | del_mode); /* Mark modes for deletion */
+  modebuf_mode(&mbuf, MODE_DEL | (del_mode & chptr->mode.mode));
   chptr->mode.mode &= ~del_mode; /* and of course actually delete them */
 
   /* If we're removing invite, remove all the invites */
   if (del_mode & MODE_INVITEONLY)
-    while ((link = chptr->invites))
-      del_invite(link->value.cptr, chptr);
+    mode_invite_clear(chptr);
 
   /*
    * If we're removing the key, note that; note that we can't clear
    * the key until after modebuf_* are done with it
    */
-  if (del_mode & MODE_KEY)
-    modebuf_mode_string(&mbuf, MODE_DEL | MODE_KEY, chptr->mode.key);
+  if (del_mode & MODE_KEY && *chptr->mode.key)
+    modebuf_mode_string(&mbuf, MODE_DEL | MODE_KEY, chptr->mode.key, 0);
 
   /* If we're removing the limit, note that and clear the limit */
-  if (del_mode & MODE_LIMIT) {
+  if (del_mode & MODE_LIMIT && chptr->mode.limit) {
     modebuf_mode_uint(&mbuf, MODE_DEL | MODE_LIMIT, chptr->mode.limit);
     chptr->mode.limit = 0; /* not referenced, so safe */
   }
@@ -181,9 +177,19 @@ do_clearmode(struct Client *cptr, struct Client *sptr, struct Channel *chptr,
    * Go through and mark the bans for deletion; note that we can't
    * free them until after modebuf_* are done with them
    */
-  if (del_mode & MODE_BAN)
-    for (link = chptr->banlist; link; link = link->next)
-      modebuf_mode_string(&mbuf, MODE_DEL | MODE_BAN, link->value.ban.banstr);
+  if (del_mode & MODE_BAN) {
+    for (link = chptr->banlist; link; link = next) {
+      next = link->next;
+
+      modebuf_mode_string(&mbuf, MODE_DEL | MODE_BAN, /* delete ban */
+                         link->value.ban.banstr, 1);
+
+      MyFree(link->value.ban.who); /* free up who string */
+      free_link(link); /* and of course the link itself */
+    }
+
+    chptr->banlist = 0;
+  }
 
   /* Deal with users on the channel */
   if (del_mode & (MODE_BAN | MODE_CHANOP | MODE_VOICE))
@@ -214,23 +220,6 @@ do_clearmode(struct Client *cptr, struct Client *sptr, struct Channel *chptr,
   if (del_mode & MODE_KEY)
     chptr->mode.key[0] = '\0';
 
-  /* and free the bans */
-  if (del_mode & MODE_BAN) {
-    for (link = chptr->banlist; link; link = next) {
-      next = link->next;
-
-      MyFree(link->value.ban.banstr);
-      MyFree(link->value.ban.who);
-      free_link(link);
-    }
-
-    chptr->banlist = 0;
-  }
-
-  /* Don't propagate CLEARMODE if it's a local channel */
-  if (IsLocalChannel(chptr->chname))
-    return 0;
-
   /* Ok, build control string again */
   for (flag_p = flags; flag_p[0]; flag_p += 2)
     if (del_mode & flag_p[0])
@@ -238,13 +227,14 @@ do_clearmode(struct Client *cptr, struct Client *sptr, struct Channel *chptr,
 
   control_buf[control_buf_i] = '\0';
 
+  /* Log it... */
+  log_write(LS_OPERMODE, L_INFO, LOG_NOSNOTICE, "%#C CLEARMODE %H %s", sptr,
+           chptr, control_buf);
+
   /* Then send it */
-  if (IsServer(sptr))
-    sendto_serv_butone(cptr, "%s " TOK_CLEARMODE " %s %s", NumServ(sptr),
-                      chptr->chname, control_buf);
-  else
-    sendto_serv_butone(cptr, "%s%s " TOK_CLEARMODE " %s %s", NumNick(sptr),
-                      chptr->chname, control_buf);
+  if (!IsLocalChannel(chptr->chname))
+    sendcmdto_serv_butone(sptr, CMD_CLEARMODE, cptr, "%H %s", chptr,
+                         control_buf);
 
   return 0;
 }
@@ -264,12 +254,14 @@ ms_clearmode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   if (parc < 3)
     return need_more_params(sptr, "CLEARMODE");
 
-  if (!IsPrivileged(sptr))
-    return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+  if (!IsPrivileged(sptr)) {
+    protocol_violation(sptr,"No priviledges on source for CLEARMODE, desync?");
+    return send_reply(sptr, ERR_NOPRIVILEGES);
+  }
 
   if (!IsChannelName(parv[1]) || IsLocalChannel(parv[1]) ||
       !(chptr = FindChannel(parv[1])))
-    return send_error_to_client(sptr, ERR_NOSUCHCHANNEL, parv[1]);
+    return send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
 
   return do_clearmode(cptr, sptr, chptr, parv[2]);
 }
@@ -287,17 +279,23 @@ mo_clearmode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Channel *chptr;
   char *control = "ovpsmikbl"; /* default control string */
 
+  if (!feature_bool(FEAT_CONFIG_OPERCMDS))
+    return send_reply(sptr, ERR_DISABLED, "CLEARMODE");
+
   if (parc < 2)
     return need_more_params(sptr, "CLEARMODE");
 
   if (parc > 2)
     control = parv[2];
 
-  if (!IsOper(sptr) && !IsLocalChannel(parv[1]))
-    return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+  clean_channelname(parv[1]);
+
+  if (!HasPriv(sptr,
+              IsLocalChannel(parv[1]) ? PRIV_LOCAL_OPMODE : PRIV_OPMODE))
+    return send_reply(sptr, ERR_NOPRIVILEGES);
 
-  if (!IsChannelName(parv[1]) || !(chptr = FindChannel(parv[1])))
-    return send_error_to_client(sptr, ERR_NOSUCHCHANNEL, parv[1]);
+  if (('#' != *parv[1] && '&' != *parv[1]) || !(chptr = FindChannel(parv[1])))
+    return send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
 
   return do_clearmode(cptr, sptr, chptr, control);
 }