]> jfr.im git - solanum.git/blobdiff - src/chmode.c
Port ircd-seven banfowards to charybdis.
[solanum.git] / src / chmode.c
index a268fdc5d8593b16e0bbec6f1ddfab916a7b095e..38ff8d883629c1a8636ebddc3a0286a3174ba97d 100644 (file)
@@ -65,6 +65,7 @@ static int mode_count;
 static int mode_limit;
 static int mode_limit_simple;
 static int mask_pos;
+static int removed_mask_pos;
 
 char cflagsbuf[256];
 char cflagsmyinfo[256];
@@ -103,14 +104,6 @@ construct_cflags_strings(void)
                 
                switch (chmode_flags[i])
                {
-                   case MODE_EXLIMIT:
-                   case MODE_DISFORWARD:
-                       if(ConfigChannel.use_forward)
-                       {
-                           *ptr++ = (char) i;
-                       }
-                       
-                       break;
                    case MODE_REGONLY:
                        if(rb_dlink_list_length(&service_list))
                        {
@@ -210,12 +203,12 @@ get_channel_access(struct Client *source_p, struct membership *msptr)
 
 /* add_id()
  *
- * inputs      - client, channel, id to add, type
+ * inputs      - client, channel, id to add, type, forward
  * outputs     - 0 on failure, 1 on success
  * side effects - given id is added to the appropriate list
  */
 int
-add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
+add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
        rb_dlink_list * list, long mode_type)
 {
        struct Ban *actualBan;
@@ -259,7 +252,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
        else
                rb_strlcpy(who, source_p->name, sizeof(who));
 
-       actualBan = allocate_ban(realban, who);
+       actualBan = allocate_ban(realban, who, forward);
        actualBan->when = rb_current_time();
 
        rb_dlinkAdd(actualBan, &actualBan->node, list);
@@ -274,17 +267,17 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
 /* del_id()
  *
  * inputs      - channel, id to remove, type
- * outputs     - 0 on failure, 1 on success
- * side effects - given id is removed from the appropriate list
+ * outputs     - pointer to ban that was removed, if any
+ * side effects - given id is removed from the appropriate list and returned
  */
-int
+struct Ban *
 del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type)
 {
        rb_dlink_node *ptr;
        struct Ban *banptr;
 
        if(EmptyString(banid))
-               return 0;
+               return NULL;
 
        RB_DLINK_FOREACH(ptr, list->head)
        {
@@ -299,11 +292,11 @@ del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode
                        if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
                                chptr->bants++;
 
-                       return 1;
+                       return banptr;
                }
        }
 
-       return 0;
+       return NULL;
 }
 
 /* check_string()
@@ -347,10 +340,11 @@ pretty_mask(const char *idmask)
 {
        static char mask_buf[BUFSIZE];
        int old_mask_pos;
-       char *nick, *user, *host;
+       char *nick, *user, *host, *forward = NULL;
        char splat[] = "*";
-       char *t, *at, *ex;
-       char ne = 0, ue = 0, he = 0;    /* save values at nick[NICKLEN], et all */
+       char *t, *at, *ex, *ex2;
+       char ne = 0, ue = 0, he = 0, fe = 0;    /* save values at nick[NICKLEN], et all */
+       char e2 = 0;                            /* save value that delimits forward channel */
        char *mask;
 
        mask = LOCAL_COPY(idmask);
@@ -376,7 +370,7 @@ pretty_mask(const char *idmask)
                return mask_buf + old_mask_pos;
        }
 
-       at = ex = NULL;
+       at = ex = ex2 = NULL;
        if((t = strchr(mask, '@')) != NULL)
        {
                at = t;
@@ -398,6 +392,15 @@ pretty_mask(const char *idmask)
                        if(*mask != '\0')
                                user = mask;
                }
+
+               if((t = strchr(host, '!')) != NULL || (t = strchr(host, '$')) != NULL)
+               {
+                       ex2 = t;
+                       e2 = *t;
+                       *t++= '\0';
+                       if (*t != '\0')
+                               forward = t;
+               }
        }
        else if((t = strchr(mask, '!')) != NULL)
        {
@@ -408,7 +411,7 @@ pretty_mask(const char *idmask)
                if(*t != '\0')
                        user = t;
        }
-       else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL || strchr(mask, '/') != NULL)
+       else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
        {
                if(*mask != '\0')
                        host = mask;
@@ -435,20 +438,32 @@ pretty_mask(const char *idmask)
                he = host[HOSTLEN];
                host[HOSTLEN] = '\0';
        }
+       if(forward && strlen(forward) > CHANNELLEN)
+       {
+               fe = forward[CHANNELLEN];
+               forward[CHANNELLEN] = '\0';
+       }
 
-       mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
+       if (forward)
+               mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s$%s", nick, user, host, forward) + 1;
+       else
+               mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
 
        /* restore mask, since we may need to use it again later */
        if(at)
                *at = '@';
        if(ex)
                *ex = '!';
+       if(ex2)
+               *ex2 = e2;
        if(ne)
                nick[NICKLEN - 1] = ne;
        if(ue)
                user[USERLEN] = ue;
        if(he)
                host[HOSTLEN] = he;
+       if(fe)
+               forward[CHANNELLEN] = fe;
 
        return mask_buf + old_mask_pos;
 }
@@ -534,11 +549,6 @@ chm_simple(struct Client *source_p, struct Channel *chptr,
        /* setting + */
        if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
        {
-               /* if +f is disabled, ignore an attempt to set +QF locally */
-               if(!ConfigChannel.use_forward && MyClient(source_p) &&
-                  (c == 'Q' || c == 'F'))
-                       return;
-
                chptr->mode.mode |= mode_type;
 
                mode_changes[mode_count].letter = c;
@@ -653,8 +663,7 @@ chm_ban(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)
 {
-       const char *mask;
-       const char *raw_mask;
+       char *mask, *raw_mask, *forward;
        rb_dlink_list *list;
        rb_dlink_node *ptr;
        struct Ban *banptr;
@@ -745,10 +754,16 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
 
                RB_DLINK_FOREACH(ptr, list->head)
                {
+                       char buf[BANLEN];
                        banptr = ptr->data;
+                       if(banptr->forward)
+                               rb_snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward);
+                       else
+                               rb_strlcpy(buf, banptr->banstr, sizeof(buf));
+
                        sendto_one(source_p, form_str(rpl_list),
                                   me.name, source_p->name, chptr->chname,
-                                  banptr->banstr, banptr->who, banptr->when);
+                                  buf, banptr->who, banptr->when);
                }
                sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname);
                return;
@@ -783,6 +798,17 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        else
                mask = pretty_mask(raw_mask);
 
+       /* Look for a $ after the first character.
+        * As the first character, it marks an extban; afterwards
+        * it delimits a forward channel.
+        */
+       if ((forward = strchr(mask+1, '$')) != NULL)
+       {
+               *forward++ = '\0';
+               if (*forward == '\0')
+                       forward = NULL;
+       }
+
        /* we'd have problems parsing this, hyb6 does it too
         * also make sure it will always fit on a line with channel
         * name etc.
@@ -803,9 +829,12 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
                /* dont allow local clients to overflow the banlist, dont
                 * let remote servers set duplicate bans
                 */
-               if(!add_id(source_p, chptr, mask, list, mode_type))
+               if(!add_id(source_p, chptr, mask, forward, list, mode_type))
                        return;
 
+               if(forward)
+                       forward[-1]= '$';
+
                mode_changes[mode_count].letter = c;
                mode_changes[mode_count].dir = MODE_ADD;
                mode_changes[mode_count].caps = caps;
@@ -816,20 +845,33 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        }
        else if(dir == MODE_DEL)
        {
-               if(del_id(chptr, mask, list, mode_type) == 0)
+               struct Ban *removed;
+               static char buf[BANLEN * MAXMODEPARAMS];
+               int old_removed_mask_pos = removed_mask_pos;
+               if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
                {
                        /* mask isn't a valid ban, check raw_mask */
-                       if(del_id(chptr, raw_mask, list, mode_type))
+                       if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL)
                                mask = raw_mask;
                }
 
+               if(removed && removed->forward)
+                       removed_mask_pos += rb_snprintf(buf, sizeof(buf), "%s$%s", removed->banstr, removed->forward);
+               else
+                       removed_mask_pos += rb_strlcpy(buf, mask, sizeof(buf));
+               if(removed)
+               {
+                       free_ban(removed);
+                       removed = NULL;
+               }
+
                mode_changes[mode_count].letter = c;
                mode_changes[mode_count].dir = MODE_DEL;
                mode_changes[mode_count].caps = caps;
                mode_changes[mode_count].nocaps = 0;
                mode_changes[mode_count].mems = mems;
                mode_changes[mode_count].id = NULL;
-               mode_changes[mode_count++].arg = mask;
+               mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
        }
 }
 
@@ -1131,11 +1173,6 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
        struct membership *msptr;
        const char *forward;
 
-       /* if +f is disabled, ignore local attempts to set it */
-       if(!ConfigChannel.use_forward && MyClient(source_p) &&
-          (dir == MODE_ADD) && (parc > *parn))
-               return;
-
        if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
        {
                if (!(*errors & SM_ERR_RPL_F))
@@ -1214,7 +1251,7 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
                mode_changes[mode_count].dir = MODE_ADD;
                mode_changes[mode_count].caps = 0;
                mode_changes[mode_count].nocaps = 0;
-               mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
+               mode_changes[mode_count].mems = ALL_MEMBERS;
                mode_changes[mode_count].id = NULL;
                mode_changes[mode_count++].arg = forward;
        }
@@ -1614,6 +1651,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
        struct Client *fakesource_p;
 
        mask_pos = 0;
+       removed_mask_pos = 0;
        mode_count = 0;
        mode_limit = 0;
        mode_limit_simple = 0;