- case '+': /* modes */
- {
- char *p = parv[n];
- while (*(++p)) /* Run over all mode characters */
- {
- switch (*p) /* which mode ? */
- {
- /*
- * The following cases all do the following:
- * - In case wipeout needed, reset 'prev_mode' to indicate this
- * mode should not be cancelled.
- * - If wipeout or (not netride and the new mode is a change),
- * add it to bmodebuf and bparabuf for propagation.
- * - Else ignore it.
- * - Add it to modebuf and parabuf for propagation to the
- * clients when not netride and the new mode is a change.
- * Special cases:
- * - If a +s is received, cancel a +p and sent a -p to the
- * clients too (if +p was set).
- * - If a +p is received and +s is set, ignore the +p.
- */
- case 'i':
- {
- int tmp;
- prev_mode &= ~MODE_INVITEONLY;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_INVITEONLY)) || wipeout)
- {
- bmodebuf[mblen++] = 'i';
- current_mode->mode |= MODE_INVITEONLY;
- }
- if (!tmp)
- modebuf[mblen2++] = 'i';
- break;
- }
- case 'k':
- {
- int tmp;
- char *param = parv[++n];
- prev_mode &= ~MODE_KEY;
- if (!(tmp = netride || (*current_mode->key &&
- (!strcmp(current_mode->key, param) ||
- (!wipeout && strcmp(current_mode->key, param) < 0)))) ||
- wipeout)
- {
- bmodebuf[mblen++] = 'k';
- strcat(bparambuf, " ");
- strcat(bparambuf, param);
- ircd_strncpy(current_mode->key, param, KEYLEN);
- }
- if (!tmp && !wipeout)
- {
- modebuf[mblen2++] = 'k';
- parabuf[pblen2++] = ' ';
- strcpy(parabuf + pblen2, param);
- pblen2 += strlen(param);
- cnt++;
- }
- break;
- }
- case 'l':
- {
- int tmp;
- unsigned int param = atoi(parv[++n]);
- prev_mode &= ~MODE_LIMIT;
- if (!(tmp = netride || (current_mode->limit &&
- (current_mode->limit == param ||
- (!wipeout && current_mode->limit < param)))) || wipeout)
- {
- bmodebuf[mblen++] = 'l';
- sprintf_irc(bparambuf + strlen(bparambuf), " %d", param);
- current_mode->limit = param;
- }
- if (!tmp)
- {
- modebuf[mblen2++] = 'l';
- pblen2 = sprintf_irc(parabuf + pblen2, " %d", param) - parabuf;
- cnt++;
- }
- break;
- }
- case 'm':
- {
- int tmp;
- prev_mode &= ~MODE_MODERATED;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_MODERATED)) || wipeout)
- {
- bmodebuf[mblen++] = 'm';
- current_mode->mode |= MODE_MODERATED;
- }
- if (!tmp)
- modebuf[mblen2++] = 'm';
- break;
- }
- case 'n':
- {
- int tmp;
- prev_mode &= ~MODE_NOPRIVMSGS;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_NOPRIVMSGS)) || wipeout)
- {
- bmodebuf[mblen++] = 'n';
- current_mode->mode |= MODE_NOPRIVMSGS;
- }
- if (!tmp)
- modebuf[mblen2++] = 'n';
- break;
- }
- case 'p':
- {
- int tmp;
-
- /* Special case: */
- if (!netride && !wipeout && (current_mode->mode & MODE_SECRET))
- break;
-
- prev_mode &= ~MODE_PRIVATE;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_PRIVATE)) || wipeout)
- {
- bmodebuf[mblen++] = 'p';
- current_mode->mode |= MODE_PRIVATE;
- }
- if (!tmp)
- modebuf[mblen2++] = 'p';
- break;
- }
- case 's':
- {
- int tmp;
- prev_mode &= ~MODE_SECRET;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_SECRET)) || wipeout)
- {
- bmodebuf[mblen++] = 's';
- current_mode->mode |= MODE_SECRET;
- }
- if (!tmp)
- modebuf[mblen2++] = 's';
-
- /* Special case: */
- if (!netride && !wipeout && (current_mode->mode & MODE_PRIVATE))
- {
- int i;
- for (i = mblen2 - 1; i >= 0; --i)
- modebuf[i + 2] = modebuf[i];
- modebuf[0] = '-';
- modebuf[1] = 'p';
- mblen2 += 2;
- current_mode->mode &= ~MODE_PRIVATE;
- }
-
- break;
- }
- case 't':
- {
- int tmp;
- prev_mode &= ~MODE_TOPICLIMIT;
- if (!(tmp = netride ||
- (current_mode->mode & MODE_TOPICLIMIT)) || wipeout)
- {
- bmodebuf[mblen++] = 't';
- current_mode->mode |= MODE_TOPICLIMIT;
- }
- if (!tmp)
- modebuf[mblen2++] = 't';
- break;
- }
- }
- } /* <-- while over all modes */
-
- bmodebuf[mblen] = '\0';
- sendbuf[sblen] = '\0';
- if (mblen) /* Anything to send at all ? */
- {
- send_it = 1;
- strcpy(sendbuf + sblen, " +");
- sblen += 2;
- strcpy(sendbuf + sblen, bmodebuf);
- sblen += mblen;
- strcpy(sendbuf + sblen, bparambuf);
- sblen += strlen(bparambuf);
- }
- break; /* Done mode part */
- }
- case '%': /* bans */
- {
- char *pv, *p = 0, *ban;
- int first = 1;
- if (netride)
- break; /* Ignore bans */
- /* Run over all bans */
- for (pv = parv[n] + 1; (ban = ircd_strtok(&p, pv, " ")); pv = 0)
- {
- int ret;
- /*
- * The following part should do the following:
- * - If the new (un)ban is not a _change_ it is ignored.
- * - Else, add it to sendbuf for later use.
- * - If sendbuf is full, send it, and prepare a new
- * message in sendbuf.
- */
- ret = add_banid(sptr, chptr, ban, 1, add_banid_not_called);
- if (ret == 0)
- {
- add_banid_not_called = 0;
- /* Mark this new ban so we can send it to the clients later */
- chptr->banlist->flags |= CHFL_BURST_BAN;
- }
- if (ret != -1)
- /* A new ban was added or an existing one needs to be passed on.
- * Also add it to sendbuf: */
- add_token_to_sendbuf(ban, &sblen, &first, &send_it, '%', 0);
- }
- break; /* Done bans part */
- }
- default: /* nicks */
- {
- char *pv, *p = 0, *nick, *ptr;
- int first = 1;
- /* Default mode: */
- int default_mode = CHFL_DEOPPED;
- /* Run over all nicks */
- for (pv = parv[n]; (nick = ircd_strtok(&p, pv, ",")); pv = 0)
- {
- struct Client *acptr;
- if ((ptr = strchr(nick, ':'))) /* New default mode ? */
- {
- *ptr = '\0'; /* Fix 'nick' */
- acptr = findNUser(nick);
- if (!netride)
- {
- /* Calculate new mode change: */
- default_mode = CHFL_DEOPPED;
- while (*(++ptr))
- if (*ptr == 'o')
- {
- default_mode |= CHFL_CHANOP;
- default_mode &= ~CHFL_DEOPPED;
- }
- else if (*ptr == 'v')
- default_mode |= CHFL_VOICE;
- else
- break;
- }
- }
- else
- acptr = findNUser(nick);
- /*
- * Note that at this point we already received a 'NICK' for any
- * <nick> numeric that is joining (and possibly opped) here.
- * Therefore we consider the following situations:
- * - The <nick> numeric exists and is from the direction of cptr: ok
- * - The <nick> numeric does not exist:
- * Apparently this previous <nick> numeric was killed (upstream)
- * or it collided with an existing <nick> name.
- * - The <nick> numeric exists but is from another direction:
- * Apparently this previous <nick> numeric was killed,
- * and due to a reroute it signed on via another link (probably
- * a nick [numeric] collision).
- * Note that it can't be a QUIT or SQUIT, because a QUIT would
- * come from the same direction as the BURST (cptr) while an
- * upstream SQUIT removes the source (server) and we would thus
- * have this BURST ignored already.
- * This means that if we find the nick and it is from the correct
- * direction, it joins. If it doesn't exist or is from another
- * direction, we have to ignore it. If all nicks are ignored, we
- * remove the channel again when it is empty and don't propagate
- * the BURST message.
- */
- if (acptr && acptr->from == cptr)
- {
- /*
- * The following should do the following:
- * - Add it to sendbuf for later use.
- * - If sendbuf is full, send it, and prepare a new
- * message in sendbuf.
- */
- add_token_to_sendbuf(nick, &sblen, &first, &send_it, 0,
- default_mode);
- /* Let is take effect: (Note that in the case of a netride
- * 'default_mode' is always CHFL_DEOPPED here). */
- add_user_to_channel(chptr, acptr, default_mode | CHFL_BURST_JOINED);
- }
- } /* <-- Next nick */
- if (!chptr->members) /* All nicks collided and channel is empty ? */
- {
- sub1_from_channel(chptr);
- return 0; /* Forget about the (rest of the) message... */
- }
- break; /* Done nicks part */
- }
- } /* <-- Next parameter if any */
- if (!chptr->members) /* This message only contained bans (then the previous
- message only contained collided nicks, see above) */
- {
- sub1_from_channel(chptr);
- if (!add_banid_not_called)
- while (next_removed_overlapped_ban());
- return 0; /* Forget about the (rest of the) message... */
- }
-
- /* The last (possibly only) message is always send here */
- if (send_it) /* Anything (left) to send ? */
- {
- struct DLink *lp;
- struct Membership* member;
-
- /* send 'sendbuf' to all downlinks */
- for (lp = me.serv->down; lp; lp = lp->next)
- {
- if (lp->value.cptr == cptr)