Author: Ghostwolf <foxxe@wtfs.net>
[ircu2.10.12-pk.git] / ircd / m_mode.c
index 9e93a007514ffd89d93bc25225f947c206b2044f..f32ea255a328c27b72d799563a9590ff59c5caa9 100644 (file)
@@ -79,6 +79,8 @@
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
+#include "config.h"
+
 #include "handlers.h"
 #include "channel.h"
 #include "client.h"
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef CONFIG_NEW_MODE
 int
 m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 {
@@ -111,10 +112,11 @@ m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
   clean_channelname(parv[1]);
 
-  if (('#' != *parv[1] && '&' != *parv[1]) || !(chptr = FindChannel(parv[1])))
+  if (('#' != *parv[1] && '&' != *parv[1] && '+' != *parv[1]) || 
+      !(chptr = FindChannel(parv[1])))
     return set_user_mode(cptr, sptr, parc, parv);
 
-  sptr->flags &= ~FLAGS_TS8;
+  cli_flags(sptr) &= ~FLAGS_TS8;
 
   if (parc < 3) {
     char modebuf[MODEBUFLEN];
@@ -122,17 +124,14 @@ m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
     *modebuf = *parabuf = '\0';
     modebuf[1] = '\0';
-    channel_modes(sptr, modebuf, parabuf, chptr);
-    sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-              chptr->chname, modebuf, parabuf);
-    sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
-              chptr->chname, chptr->creationtime);
+    channel_modes(sptr, modebuf, parabuf, sizeof(parabuf), chptr);
+    send_reply(sptr, RPL_CHANNELMODEIS, chptr->chname, modebuf, parabuf);
+    send_reply(sptr, RPL_CREATIONTIME, chptr->chname, chptr->creationtime);
     return 0;
   }
 
   if (!(member = find_member_link(chptr, sptr)) || !IsChanOp(member)) {
-#ifdef OPER_MODE_LCHAN
-    if (IsOperOnLocalChannel(sptr, chptr->chname)) {
+    if (IsLocalChannel(chptr->chname) && HasPriv(sptr, PRIV_MODE_LCHAN)) {
       modebuf_init(&mbuf, sptr, cptr, chptr,
                   (MODEBUF_DEST_CHANNEL | /* Send mode to channel */
                    MODEBUF_DEST_HACK4));  /* Send HACK(4) notice */
@@ -141,7 +140,6 @@ m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
                  MODE_PARSE_FORCE)); /* Force it to take */
       return modebuf_flush(&mbuf);
     } else
-#endif
       mode_parse(0, cptr, sptr, chptr, parc - 2, parv + 2,
                 (member ? MODE_PARSE_NOTOPER : MODE_PARSE_NOTMEMBER));
     return 0;
@@ -167,13 +165,13 @@ ms_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   if (IsLocalChannel(parv[1]))
     return 0;
 
-  if ('#' != *parv[1] || !(chptr = FindChannel(parv[1])))
+  if (('#' != *parv[1] && '+' != *parv[1])|| !(chptr = FindChannel(parv[1])))
     return set_user_mode(cptr, sptr, parc, parv);
 
-  sptr->flags &= ~FLAGS_TS8;
+  cli_flags(sptr) &= ~FLAGS_TS8;
 
   if (IsServer(sptr)) {
-    if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
+    if (find_conf_byhost(cli_confs(cptr), cli_name(sptr), CONF_UWORLD))
       modebuf_init(&mbuf, sptr, cptr, chptr,
                   (MODEBUF_DEST_CHANNEL | /* Send mode to clients */
                    MODEBUF_DEST_SERVER  | /* Send mode to servers */
@@ -211,328 +209,3 @@ ms_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
   return modebuf_flush(&mbuf);
 }
-#else /* CONFIG_NEW_MODE */
-/*
- * m_mode - generic message handler
- */
-int m_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
-{
-  int             badop;
-  int             sendts;
-  struct Channel* chptr = 0;
-  char modebuf[MODEBUFLEN];
-  char parabuf[MODEBUFLEN];
-  char nparabuf[MODEBUFLEN];
-
-
-  if (parc < 2)
-    return need_more_params(sptr, "MODE");
-
-  /*
-   * if local user, cleanup channel name, don't allow local channel operations
-   * for remote clients
-   */
-  if (MyUser(sptr))
-    clean_channelname(parv[1]);
-  else if (IsLocalChannel(parv[1]))
-    return 0;
-
-  /* 
-   * try to find the channel
-   */
-  if ('#' == *parv[1] || '&' == *parv[1])
-    chptr = FindChannel(parv[1]);
-  if (!chptr)
-    return set_user_mode(cptr, sptr, parc, parv);
-
-  sptr->flags &= ~FLAGS_TS8;
-  /*
-   * sending an error wasnt good, lets just send an empty mode reply..  poptix
-   */
-  if (IsModelessChannel(chptr->chname)) {
-    if (IsUser(sptr))
-      sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-                 chptr->chname, "+nt", "");
-    return 0;
-  }
-
-  if (parc < 3) {
-    /*
-     * no parameters, send channel modes
-     */
-    *modebuf = *parabuf = '\0';
-    modebuf[1] = '\0';
-    channel_modes(sptr, modebuf, parabuf, chptr);
-    sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-               chptr->chname, modebuf, parabuf);
-    sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
-               chptr->chname, chptr->creationtime);
-    return 0;
-  }
-
-  LocalChanOperMode = 0;
-
-  if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
-                          modebuf, parabuf, nparabuf, &badop))) {
-    sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
-        ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
-    return 0;
-  }
-
-  if (badop >= 2)
-    send_hack_notice(cptr, sptr, parc, parv, badop, 1);
-
-  if (strlen(modebuf) > 1 || sendts > 0) {
-    if (badop != 2 && strlen(modebuf) > 1) {
-#ifdef OPER_MODE_LCHAN
-      if (LocalChanOperMode) {
-        sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
-                               me.name, chptr->chname, modebuf, parabuf);
-        sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
-                       sptr->name, chptr->chname, modebuf, parabuf);
-      }
-      else
-#endif
-      sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
-          parv[0], chptr->chname, modebuf, parabuf);
-    }
-    if (IsLocalChannel(chptr->chname))
-      return 0;
-    /* We send a creationtime of 0, to mark it as a hack --Run */
-    if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
-      if (*modebuf == '\0')
-        strcpy(modebuf, "+");
-      if (badop != 2) {
-        sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
-            NumServ(sptr), chptr->chname, modebuf, nparabuf,
-            (badop == 4) ? (time_t) 0 : chptr->creationtime);
-      }
-    }
-    else {
-      if (IsServer(sptr))
-         sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
-           NumServ(sptr), chptr->chname, modebuf, nparabuf);
-      else
-         sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
-           NumNick(sptr), chptr->chname, modebuf, nparabuf);
-    }
-  }
-  return 0;
-}
-
-/*
- * ms_mode - server message handler
- */
-int ms_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
-{
-  int             badop;
-  int             sendts;
-  struct Channel* chptr = 0;
-  char modebuf[MODEBUFLEN];
-  char parabuf[MODEBUFLEN];
-  char nparabuf[MODEBUFLEN];
-
-  if (parc < 2)
-    return need_more_params(sptr, "MODE");
-
-  /*
-   * if local user, cleanup channel name, don't allow local channel operations
-   * for remote clients
-   */
-  if (MyUser(sptr))
-    clean_channelname(parv[1]);
-  else if (IsLocalChannel(parv[1]))
-    return 0;
-
-  /* 
-   * try to find the channel
-   */
-  if ('#' == *parv[1] || '&' == *parv[1])
-    chptr = FindChannel(parv[1]);
-  if (!chptr)
-    return set_user_mode(cptr, sptr, parc, parv);
-
-  sptr->flags &= ~FLAGS_TS8;
-  /*
-   * sending an error wasnt good, lets just send an empty mode reply..  poptix
-   */
-  if (IsModelessChannel(chptr->chname)) {
-    if (IsUser(sptr))
-      sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-                 chptr->chname, "+nt", "");
-    return 0;
-  }
-
-  if (parc < 3) {
-    /*
-     * no parameters, send channel modes
-     */
-    *modebuf = *parabuf = '\0';
-    modebuf[1] = '\0';
-    channel_modes(sptr, modebuf, parabuf, chptr);
-    sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-               chptr->chname, modebuf, parabuf);
-    sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
-               chptr->chname, chptr->creationtime);
-    return 0;
-  }
-
-  LocalChanOperMode = 0;
-
-  if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
-                          modebuf, parabuf, nparabuf, &badop))) {
-    sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
-        ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
-    return 0;
-  }
-
-  if (badop >= 2)
-    send_hack_notice(cptr, sptr, parc, parv, badop, 1);
-
-  if (strlen(modebuf) > 1 || sendts > 0) {
-    if (badop != 2 && strlen(modebuf) > 1) {
-#ifdef OPER_MODE_LCHAN
-      if (LocalChanOperMode) {
-        sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
-                               me.name, chptr->chname, modebuf, parabuf);
-        sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
-                       me.name, chptr->chname, modebuf, parabuf);
-      }
-      else
-#endif
-      sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
-          parv[0], chptr->chname, modebuf, parabuf);
-    }
-    if (IsLocalChannel(chptr->chname))
-      return 0;
-    /* We send a creationtime of 0, to mark it as a hack --Run */
-    if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
-      if (*modebuf == '\0')
-        strcpy(modebuf, "+");
-      if (badop != 2) {
-        sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
-            NumServ(sptr), chptr->chname, modebuf, nparabuf,
-            (badop == 4) ? (time_t) 0 : chptr->creationtime);
-      }
-    }
-    else {
-      if (IsServer(sptr))
-         sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
-           NumServ(sptr), chptr->chname, modebuf, nparabuf);
-      else
-         sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
-           NumNick(sptr), chptr->chname, modebuf, nparabuf);
-    }
-  }
-  return 0;
-}
-#endif /* CONFIG_NEW_MODE */
-
-#if 0
-/*
- * m_mode
- * parv[0] - sender
- * parv[1] - channel
- */
-int m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
-  int             badop;
-  int             sendts;
-  struct Channel* chptr = 0;
-
-  if (parc < 2)
-    return need_more_params(sptr, "MODE");
-
-  /*
-   * if local user, cleanup channel name, don't allow local channel operations
-   * for remote clients
-   */
-  if (MyUser(sptr))
-    clean_channelname(parv[1]);
-  else if (IsLocalChannel(parv[1]))
-    return 0;
-
-  /* 
-   * try to find the channel
-   */
-  if ('#' == *parv[1] || '&' == *parv[1])
-    chptr = FindChannel(parv[1]);
-  if (!chptr)
-    return set_user_mode(cptr, sptr, parc, parv);
-
-  sptr->flags &= ~FLAGS_TS8;
-  /*
-   * sending an error wasnt good, lets just send an empty mode reply..  poptix
-   */
-  if (IsModelessChannel(chptr->chname)) {
-    if (IsUser(sptr))
-      sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-                 chptr->chname, "+nt", "");
-    return 0;
-  }
-
-  if (parc < 3) {
-    /*
-     * no parameters, send channel modes
-     */
-    *modebuf = *parabuf = '\0';
-    modebuf[1] = '\0';
-    channel_modes(sptr, modebuf, parabuf, chptr);
-    sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
-               chptr->chname, modebuf, parabuf);
-    sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
-               chptr->chname, chptr->creationtime);
-    return 0;
-  }
-
-  LocalChanOperMode = 0;
-
-  if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
-                          modebuf, parabuf, nparabuf, &badop))) {
-    sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
-        ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
-    return 0;
-  }
-
-  if (badop >= 2)
-    send_hack_notice(cptr, sptr, parc, parv, badop, 1);
-
-  if (strlen(modebuf) > 1 || sendts > 0) {
-    if (badop != 2 && strlen(modebuf) > 1) {
-#ifdef OPER_MODE_LCHAN
-      if (LocalChanOperMode) {
-        sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
-                               me.name, chptr->chname, modebuf, parabuf);
-        sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
-                       me.name, chptr->chname, modebuf, parabuf);
-      }
-      else
-#endif
-      sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
-          parv[0], chptr->chname, modebuf, parabuf);
-    }
-    if (IsLocalChannel(chptr->chname))
-      return 0;
-    /* We send a creationtime of 0, to mark it as a hack --Run */
-    if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
-      if (*modebuf == '\0')
-        strcpy(modebuf, "+");
-      if (badop != 2) {
-        sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
-            NumServ(sptr), chptr->chname, modebuf, nparabuf,
-            (badop == 4) ? (time_t) 0 : chptr->creationtime);
-      }
-    }
-    else {
-      if (IsServer(sptr))
-         sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
-           NumServ(sptr), chptr->chname, modebuf, nparabuf);
-      else
-         sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
-           NumNick(sptr), chptr->chname, modebuf, nparabuf);
-    }
-  }
-  return 0;
-}
-
-#endif /* 0 */