]> jfr.im git - solanum.git/blobdiff - ircd/chmode.c
m_cap: simplify cap_req, remove multiline
[solanum.git] / ircd / chmode.c
index 6ec2f497ac6ae3e66d2260fb90b81a4ec7e2750e..6416a8c9107476c068b853e4e3eec0543081cae0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  charybdis: A slightly useful ircd.
+ *  Solanum: a slightly advanced ircd
  *  chmode.c: channel mode management
  *
  * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
@@ -202,10 +202,10 @@ get_channel_access(struct Client *source_p, struct Channel *chptr, struct member
  * Checks if mlock and chanops permit a mode change.
  *
  * inputs      - client, channel, access level, errors pointer, mode char
- * outputs     - 0 on failure, 1 on success
+ * outputs     - false on failure, true on success
  * side effects - error message sent on failure
  */
-static int
+static bool
 allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel,
                int *errors, char c)
 {
@@ -220,7 +220,7 @@ allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel,
                                        c,
                                        chptr->mode_lock);
                *errors |= SM_ERR_MLOCK;
-               return 0;
+               return false;
        }
        if(alevel < CHFL_CHANOP)
        {
@@ -228,18 +228,18 @@ allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel,
                        sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
                                   me.name, source_p->name, chptr->chname);
                *errors |= SM_ERR_NOOPS;
-               return 0;
+               return false;
        }
-       return 1;
+       return true;
 }
 
 /* add_id()
  *
  * inputs      - client, channel, id to add, type, forward
- * outputs     - 0 on failure, 1 on success
+ * outputs     - false on failure, true on success
  * side effects - given id is added to the appropriate list
  */
-int
+bool
 add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
        rb_dlink_list * list, long mode_type)
 {
@@ -253,18 +253,18 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
         */
        if(MyClient(source_p))
        {
-               if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)(chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
+               if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)((chptr->mode.mode & MODE_EXLIMIT) ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
                {
                        sendto_one(source_p, form_str(ERR_BANLISTFULL),
                                   me.name, source_p->name, chptr->chname, realban);
-                       return 0;
+                       return false;
                }
 
                RB_DLINK_FOREACH(ptr, list->head)
                {
                        actualBan = ptr->data;
                        if(mask_match(actualBan->banstr, realban))
-                               return 0;
+                               return false;
                }
        }
        /* dont let remotes set duplicates */
@@ -274,7 +274,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
                {
                        actualBan = ptr->data;
                        if(!irccmp(actualBan->banstr, realban))
-                               return 0;
+                               return false;
                }
        }
 
@@ -291,9 +291,9 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
 
        /* invalidate the can_send() cache */
        if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
-               chptr->bants++;
+               chptr->bants = rb_current_time();
 
-       return 1;
+       return true;
 }
 
 /* del_id()
@@ -321,7 +321,7 @@ del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode
 
                        /* invalidate the can_send() cache */
                        if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
-                               chptr->bants++;
+                               chptr->bants = rb_current_time();
 
                        return banptr;
                }
@@ -486,31 +486,31 @@ pretty_mask(const char *idmask)
  * output      - true if forwarding should be allowed
  * side effects - numeric sent if not allowed
  */
-static int
+static bool
 check_forward(struct Client *source_p, struct Channel *chptr,
                const char *forward)
 {
-       struct Channel *targptr;
+       struct Channel *targptr = NULL;
        struct membership *msptr;
 
        if(!check_channel_name(forward) ||
                        (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
        {
                sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
-               return 0;
+               return false;
        }
        /* don't forward to inconsistent target -- jilles */
        if(chptr->chname[0] == '#' && forward[0] == '&')
        {
                sendto_one_numeric(source_p, ERR_BADCHANNAME,
                                   form_str(ERR_BADCHANNAME), forward);
-               return 0;
+               return false;
        }
        if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
                                   form_str(ERR_NOSUCHCHANNEL), forward);
-               return 0;
+               return false;
        }
        if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
        {
@@ -519,10 +519,10 @@ check_forward(struct Client *source_p, struct Channel *chptr,
                {
                        sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
                                   me.name, source_p->name, targptr->chname);
-                       return 0;
+                       return false;
                }
        }
-       return 1;
+       return true;
 }
 
 /* fix_key()
@@ -535,9 +535,9 @@ check_forward(struct Client *source_p, struct Channel *chptr,
 static char *
 fix_key(char *arg)
 {
-       u_char *s, *t, c;
+       unsigned char *s, *t, c;
 
-       for(s = t = (u_char *) arg; (c = *s); s++)
+       for(s = t = (unsigned char *) arg; (c = *s); s++)
        {
                c &= 0x7f;
                if(c != ':' && c != ',' && c > ' ')
@@ -558,9 +558,9 @@ fix_key(char *arg)
 static char *
 fix_key_remote(char *arg)
 {
-       u_char *s, *t, c;
+       unsigned char *s, *t, c;
 
-       for(s = t = (u_char *) arg; (c = *s); s++)
+       for(s = t = (unsigned char *) arg; (c = *s); s++)
        {
                c &= 0x7f;
                if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
@@ -660,7 +660,7 @@ chm_hidden(struct Client *source_p, struct Channel *chptr,
          int alevel, int parc, int *parn,
          const char **parv, int *errors, int dir, char c, long mode_type)
 {
-       if(!IsOper(source_p) && !IsServer(source_p))
+       if(MyClient(source_p) && !IsOperGeneral(source_p))
        {
                if(!(*errors & SM_ERR_NOPRIVS))
                        sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
@@ -707,25 +707,22 @@ chm_staff(struct Client *source_p, struct Channel *chptr,
          int alevel, int parc, int *parn,
          const char **parv, int *errors, int dir, char c, long mode_type)
 {
-       if(!IsOper(source_p) && !IsServer(source_p))
+       if(MyClient(source_p) && !IsOper(source_p))
        {
                if(!(*errors & SM_ERR_NOPRIVS))
                        sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
                *errors |= SM_ERR_NOPRIVS;
                return;
        }
-       if(MyClient(source_p) && !IsOperResv(source_p))
+       if(MyClient(source_p) && !HasPrivilege(source_p, "oper:cmodes"))
        {
                if(!(*errors & SM_ERR_NOPRIVS))
                        sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
-                                       source_p->name, "resv");
+                                       source_p->name, "cmodes");
                *errors |= SM_ERR_NOPRIVS;
                return;
        }
 
-       if(!allow_mode_change(source_p, chptr, CHFL_CHANOP, errors, c))
-               return;
-
        if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
                return;
 
@@ -822,7 +819,6 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        default:
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
                return;
-               break;
        }
 
        if(dir == 0 || parc <= *parn)
@@ -1270,7 +1266,7 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
        if(!allow_mode_change(source_p, chptr, alevel, errors, c))
                return;
 #else
-       if(!IsOper(source_p) && !IsServer(source_p))
+       if(!IsOperGeneral(source_p) && !IsServer(source_p))
        {
                if(!(*errors & SM_ERR_NOPRIVS))
                        sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
@@ -1746,7 +1742,13 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
 
        for(j = 0; j < 3; j++)
        {
-               flags = flags_list[j];
+               int send_flags = flags = flags_list[j];
+               const char *priv = NULL;
+               if (flags == ONLY_OPERS)
+               {
+                       send_flags = ALL_MEMBERS;
+                       priv = "auspex:cmodes";
+               }
                cur_len = mlen;
                mbuf = modebuf + mlen;
                pbuf = parabuf;
@@ -1779,8 +1781,8 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
                                *mbuf = '\0';
 
                                if(cur_len > mlen)
-                                       sendto_channel_local(flags, chptr, "%s %s", modebuf,
-                                                            parabuf);
+                                       sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p,
+                                                       send_flags, priv, chptr, "%s %s", modebuf, parabuf);
                                else
                                        continue;
 
@@ -1816,7 +1818,8 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
 
                *mbuf = '\0';
                if(cur_len > mlen)
-                       sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
+                       sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p,
+                               send_flags, priv, chptr, "%s %s", modebuf, parabuf);
        }
 
        /* only propagate modes originating locally, or if we're hubbing */