*
* $Id$
*/
+#include "config.h"
+
#include "channel.h"
#include "client.h"
-#include "gline.h" /* bad_channel */
#include "hash.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_chattr.h"
+#include "ircd_defs.h"
+#include "ircd_features.h"
+#include "ircd_log.h"
+#include "ircd_policy.h"
#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "match.h"
#include "msg.h"
+#include "msgq.h"
#include "numeric.h"
#include "numnicks.h"
#include "querycmds.h"
struct Channel* GlobalChannelList = 0;
+static unsigned int membershipAllocCount;
+static struct Membership* membershipFreeList;
+
static struct SLink *next_overlapped_ban(void);
static int del_banid(struct Channel *, char *, int);
void del_invite(struct Client *, struct Channel *);
assert(0 != chptr);
/* Servers don't have member links */
- if (IsServer(cptr))
+ if (IsServer(cptr)||IsMe(cptr))
return 0;
/* +k users are typically on a LOT of channels. So we iterate over who
assert(m->channel == chptr);
if (m->user == cptr)
return m;
- m=m->next_member;
+ m = m->next_member;
}
}
/* Users on the other hand aren't allowed on more than 15 channels. 50%
* and 99% are on 10 or less.
*/
else {
- m = cptr->user->channel;
+ m = (cli_user(cptr))->channel;
while (m) {
assert(m->user == cptr);
if (m->channel == chptr)
return m;
- m=m->next_channel;
+ m = m->next_channel;
}
}
return 0;
if (who)
return who;
- if (!(who = get_history(user, KILLCHASETIMELIMIT))) {
- sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, sptr->name, user);
+ if (!(who = get_history(user, feature_int(FEAT_KILLCHASETIMELIMIT)))) {
+ send_reply(sptr, ERR_NOSUCHNICK, user);
return 0;
}
if (chasing)
return ipbuf;
}
-#if 0
-static int DoesOp(const char* modebuf)
-{
- assert(0 != modebuf);
- while (*modebuf) {
- if (*modebuf == 'o' || *modebuf == 'v')
- return 1;
- ++modebuf;
- }
- return 0;
-}
-
-/*
- * This function should be removed when all servers are 2.10
- */
-static void sendmodeto_one(struct Client* cptr, const char* from,
- const char* name, const char* mode,
- const char* param, time_t creationtime)
-{
- if (IsServer(cptr) && DoesOp(mode) && creationtime)
- sendto_one(cptr, ":%s MODE %s %s %s " TIME_T_FMT,
- from, name, mode, param, creationtime);
- else
- sendto_one(cptr, ":%s MODE %s %s %s", from, name, mode, param);
-}
-#endif /* 0 */
-
/*
* Subtract one user from channel i (and free channel
* block, if channel became empty).
int i;
for (i = 0; i <= HighestFd; i++)
{
- struct Client *acptr;
- if ((acptr = LocalClientArray[i]) && acptr->listing &&
- acptr->listing->chptr == chptr)
+ struct Client *acptr = 0;
+ if ((acptr = LocalClientArray[i]) && cli_listing(acptr) &&
+ (cli_listing(acptr))->chptr == chptr)
{
list_next_channels(acptr, 1);
break; /* Only one client can list a channel */
banp = &(*banp)->next;
}
}
- if (MyUser(cptr) && !removed_bans && (len > MAXBANLENGTH || (cnt >= MAXBANS)))
+ if (MyUser(cptr) && !removed_bans &&
+ (len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXBANS)) ||
+ (cnt >= feature_int(FEAT_MAXBANS))))
{
- sendto_one(cptr, err_str(ERR_BANLISTFULL), me.name, cptr->name,
- chptr->chname, banid);
+ send_reply(cptr, ERR_BANLISTFULL, chptr->chname, banid);
return -1;
}
if (change)
assert(0 != ban->value.ban.banstr);
strcpy(ban->value.ban.banstr, banid);
- ban->value.ban.who = (char*) MyMalloc(strlen(cptr->name) + 1);
+#ifdef HEAD_IN_SAND_BANWHO
+ if (IsServer(cptr))
+ DupString(ban->value.ban.who, cli_name(&me));
+ else
+#endif
+ DupString(ban->value.ban.who, cli_name(cptr));
assert(0 != ban->value.ban.who);
- strcpy(ban->value.ban.who, cptr->name);
ban->value.ban.when = TStime();
ban->flags = CHFL_BAN; /* This bit is never used I think... */
if (member && IsBanValid(member))
return IsBanned(member);
- s = make_nick_user_host(cptr->name, cptr->user->username, cptr->user->host);
+ s = make_nick_user_host(cli_name(cptr), (cli_user(cptr))->username,
+ (cli_user(cptr))->host);
for (tmp = chptr->banlist; tmp; tmp = tmp->next) {
if ((tmp->flags & CHFL_BAN_IPMASK)) {
if (!ip_s)
- ip_s = make_nick_user_ip(cptr->name, cptr->user->username, cptr->ip);
+ ip_s = make_nick_user_ip(cli_name(cptr), (cli_user(cptr))->username,
+ cli_ip(cptr));
if (match(tmp->value.ban.banstr, ip_s) == 0)
break;
}
assert(0 != chptr);
assert(0 != who);
- if (who->user) {
- struct Membership* member =
- (struct Membership*) MyMalloc(sizeof(struct Membership));
+ if (cli_user(who)) {
+
+ struct Membership* member = membershipFreeList;
+ if (member)
+ membershipFreeList = member->next_member;
+ else {
+ member = (struct Membership*) MyMalloc(sizeof(struct Membership));
+ ++membershipAllocCount;
+ }
+
assert(0 != member);
member->user = who;
member->channel = chptr;
member->prev_member = 0;
chptr->members = member;
- member->next_channel = who->user->channel;
+ member->next_channel = (cli_user(who))->channel;
if (member->next_channel)
member->next_channel->prev_channel = member;
member->prev_channel = 0;
- who->user->channel = member;
+ (cli_user(who))->channel = member;
++chptr->users;
- ++who->user->joined;
+ ++((cli_user(who))->joined);
}
}
if (member->prev_channel)
member->prev_channel->next_channel = member->next_channel;
else
- member->user->user->channel = member->next_channel;
+ (cli_user(member->user))->channel = member->next_channel;
+
+ --(cli_user(member->user))->joined;
- --member->user->user->joined;
- MyFree(member);
+ member->next_member = membershipFreeList;
+ membershipFreeList = member;
return sub1_from_channel(chptr);
}
{
struct Membership* chan;
assert(0 != cptr);
- assert(0 != cptr->user);
+ assert(0 != cli_user(cptr));
- while ((chan = cptr->user->channel))
+ while ((chan = (cli_user(cptr))->channel))
remove_user_from_channel(cptr, chan->channel);
}
/*
* You can't speak if your off channel, if the channel is modeless, or
- * +n.(no external messages)
+ * +n (no external messages) or +m (moderated).
*/
if (!member) {
- if ((chptr->mode.mode & MODE_NOPRIVMSGS) || IsModelessChannel(chptr->chname))
+ if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED))
+ || IsModelessChannel(chptr->chname))
return 0;
else
return 1;
{
if (MyUser(cptr)) {
struct Membership* member;
- for (member = cptr->user->channel; member; member = member->next_channel) {
+ for (member = (cli_user(cptr))->channel; member;
+ member = member->next_channel) {
if (!IsVoicedOrOpped(member) && is_banned(cptr, member->channel, member))
return member->channel->chname;
}
if (*chptr->mode.key) {
*mbuf++ = 'k';
+ if (chptr->mode.limit)
+ strcat(pbuf, " ");
if (is_chan_op(cptr, chptr) || IsServer(cptr)) {
- if (chptr->mode.limit)
- strcat(pbuf, " ");
strcat(pbuf, chptr->mode.key);
- }
+ } else
+ strcat(pbuf, "*");
}
*mbuf = '\0';
}
-#if 0
-static int send_mode_list(struct Client *cptr, char *chname,
- time_t creationtime, struct SLink *top,
- int mask, char flag)
-{
- struct SLink* lp;
- char* cp;
- char* name;
- int count = 0;
- int send = 0;
- int sent = 0;
-
- cp = modebuf + strlen(modebuf);
- if (*parabuf) /* mode +l or +k xx */
- count = 1;
- for (lp = top; lp; lp = lp->next)
- {
- if (!(lp->flags & mask))
- continue;
- if (mask == CHFL_BAN)
- name = lp->value.ban.banstr;
- else
- name = lp->value.cptr->name;
- if (strlen(parabuf) + strlen(name) + 11 < MODEBUFLEN)
- {
- strcat(parabuf, " ");
- strcat(parabuf, name);
- count++;
- *cp++ = flag;
- *cp = '\0';
- }
- else if (*parabuf)
- send = 1;
- if (count == 6)
- send = 1;
- if (send)
- {
- /* cptr is always a server! So we send creationtimes */
- sendmodeto_one(cptr, me.name, chname, modebuf, parabuf, creationtime);
- sent = 1;
- send = 0;
- *parabuf = '\0';
- cp = modebuf;
- *cp++ = '+';
- if (count != 6)
- {
- strcpy(parabuf, name);
- *cp++ = flag;
- }
- count = 0;
- *cp = '\0';
- }
- }
- return sent;
-}
-
-#endif /* 0 */
-
/*
* send "cptr" a full list of the modes for channel chptr.
*/
int flag_cnt = 0;
int new_mode = 0;
size_t len;
- size_t sblen;
struct Membership* member;
struct SLink* lp2;
char modebuf[MODEBUFLEN];
char parabuf[MODEBUFLEN];
+ struct MsgBuf *mb;
assert(0 != cptr);
assert(0 != chptr);
all in one message */
/* (Continued) prefix: "<Y> B <channel> <TS>" */
- sprintf_irc(sendbuf, "%s B %s " TIME_T_FMT, NumServ(&me),
- chptr->chname, chptr->creationtime);
- sblen = strlen(sendbuf);
+ /* is there any better way we can do this? */
+ mb = msgq_make(&me, "%C " TOK_BURST " %H %Tu", &me, chptr,
+ chptr->creationtime);
if (first && modebuf[1]) /* Add simple modes (iklmnpst)
if first message */
{
/* prefix: "<Y> B <channel> <TS>[ <modes>[ <params>]]" */
- sendbuf[sblen++] = ' ';
- strcpy(sendbuf + sblen, modebuf);
- sblen += strlen(modebuf);
+ msgq_append(&me, mb, " %s", modebuf);
+
if (*parabuf)
- {
- sendbuf[sblen++] = ' ';
- strcpy(sendbuf + sblen, parabuf);
- sblen += strlen(parabuf);
- }
+ msgq_append(&me, mb, " %s", parabuf);
}
/*
if ((member->status & CHFL_VOICED_OR_OPPED) !=
current_flags[flag_cnt])
continue; /* Skip members with different flags */
- if (sblen + NUMNICKLEN + 4 > BUFSIZE - 3)
- /* The 4 is a possible ",:ov"
- The -3 is for the "\r\n\0" that is added in send.c */
+ if (msgq_bufleft(mb) < NUMNICKLEN + 4)
+ /* The 4 is a possible ",:ov" */
{
full = 1; /* Make sure we continue after
sending it so far */
mode. --Gte */
break; /* Do not add this member to this message */
}
- sendbuf[sblen++] = first ? ' ' : ',';
+ msgq_append(&me, mb, "%c%C", first ? ' ' : ',', member->user);
first = 0; /* From now on, us comma's to add new nicks */
- sprintf_irc(sendbuf + sblen, "%s%s", NumNick(member->user));
- sblen += strlen(sendbuf + sblen);
/*
* Do we have a nick with a new mode ?
* Or are we starting a new BURST line?
{
new_mode = 0;
if (IsVoicedOrOpped(member)) {
- sendbuf[sblen++] = ':';
+ char tbuf[4] = ":";
+ int loc = 1;
+
if (IsChanOp(member))
- sendbuf[sblen++] = 'o';
+ tbuf[loc++] = 'o';
if (HasVoice(member))
- sendbuf[sblen++] = 'v';
+ tbuf[loc++] = 'v';
+ tbuf[loc] = '\0';
+ msgq_append(&me, mb, tbuf);
}
}
}
for (first = 2; lp2; lp2 = lp2->next)
{
len = strlen(lp2->value.ban.banstr);
- if (sblen + len + 1 + first > BUFSIZE - 3)
+ if (msgq_bufleft(mb) < len + 1 + first)
/* The +1 stands for the added ' '.
* The +first stands for the added ":%".
- * The -3 is for the "\r\n\0" that is added in send.c
*/
{
full = 1;
break;
}
- if (first)
- {
- first = 0;
- sendbuf[sblen++] = ' ';
- sendbuf[sblen++] = ':'; /* Will be last parameter */
- sendbuf[sblen++] = '%'; /* To tell bans apart */
- }
- else
- sendbuf[sblen++] = ' ';
- strcpy(sendbuf + sblen, lp2->value.ban.banstr);
- sblen += len;
+ msgq_append(&me, mb, " %s%s", first ? ":%" : "",
+ lp2->value.ban.banstr);
+ first = 0;
}
}
- sendbuf[sblen] = '\0';
- sendbufto_one(cptr); /* Send this message */
+ send_buffer(cptr, mb, 0); /* Send this message */
+ msgq_clean(mb);
} /* Continue when there was something
that didn't fit (full==1) */
}
assert(0 != chptr);
for (lp = chptr->banlist; lp; lp = lp->next)
- sendto_one(cptr, rpl_str(RPL_BANLIST), me.name, cptr->name,
- chptr->chname, lp->value.ban.banstr, lp->value.ban.who,
- lp->value.ban.when);
- sendto_one(cptr, rpl_str(RPL_ENDOFBANLIST), me.name, cptr->name,
- chptr->chname);
-}
-
-/*
- * Check and try to apply the channel modes passed in the parv array for
- * the client ccptr to channel chptr. The resultant changes are printed
- * into mbuf and pbuf (if any) and applied to the channel.
- */
-int set_mode(struct Client* cptr, struct Client* sptr,
- struct Channel* chptr, int parc, char* parv[],
- char* mbuf, char* pbuf, char* npbuf, int* badop)
-{
- /*
- * This size is only needed when a broken
- * server sends more then MAXMODEPARAMS
- * parameters
- */
- static struct SLink chops[MAXPARA - 2];
- static int flags[] = {
- MODE_PRIVATE, 'p',
- MODE_SECRET, 's',
- MODE_MODERATED, 'm',
- MODE_NOPRIVMSGS, 'n',
- MODE_TOPICLIMIT, 't',
- MODE_INVITEONLY, 'i',
- MODE_VOICE, 'v',
- MODE_KEY, 'k',
- 0x0, 0x0
- };
-
- char bmodebuf[MODEBUFLEN];
- char bparambuf[MODEBUFLEN];
- char nbparambuf[MODEBUFLEN]; /* "Numeric" Bounce Parameter Buffer */
- struct SLink* lp;
- char* curr = parv[0];
- char* cp = NULL;
- int* ip;
- struct Membership* member_x;
- struct Membership* member_y;
- unsigned int whatt = MODE_ADD;
- unsigned int bwhatt = 0;
- int limitset = 0;
- int bounce;
- int add_banid_called = 0;
- size_t len;
- size_t nlen;
- size_t blen;
- size_t nblen;
- int keychange = 0;
- unsigned int nusers = 0;
- unsigned int newmode;
- int opcnt = 0;
- int banlsent = 0;
- int doesdeop = 0;
- int doesop = 0;
- int hacknotice = 0;
- int change;
- int gotts = 0;
- struct Client* who;
- struct Mode* mode;
- struct Mode oldm;
- static char numeric[16];
- char* bmbuf = bmodebuf;
- char* bpbuf = bparambuf;
- char* nbpbuf = nbparambuf;
- time_t newtime = 0;
- struct ConfItem* aconf;
-
- *mbuf = *pbuf = *npbuf = *bmbuf = *bpbuf = *nbpbuf = '\0';
- *badop = 0;
- if (parc < 1)
- return 0;
- /*
- * Mode is accepted when sptr is a channel operator
- * but also when the mode is received from a server.
- * At this point, let any member pass, so they are allowed
- * to see the bans.
- */
- member_y = find_channel_member(sptr, chptr);
- if (!(IsServer(cptr) || member_y))
- return 0;
-
-#ifdef OPER_MODE_LCHAN
- if (IsOperOnLocalChannel(sptr, chptr->chname) && !IsChanOp(member_y))
- LocalChanOperMode = 1;
-#endif
-
- mode = &(chptr->mode);
- memcpy(&oldm, mode, sizeof(struct Mode));
+ send_reply(cptr, RPL_BANLIST, chptr->chname, lp->value.ban.banstr,
+ lp->value.ban.who, lp->value.ban.when);
- newmode = mode->mode;
-
- while (curr && *curr) {
- switch (*curr) {
- case '+':
- whatt = MODE_ADD;
- break;
- case '-':
- whatt = MODE_DEL;
- break;
- case 'o':
- case 'v':
- if (--parc <= 0)
- break;
- parv++;
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- /*
- * Check for nickname changes and try to follow these
- * to make sure the right client is affected by the
- * mode change.
- * Even if we find a nick with find_chasing() there
- * is still a reason to ignore in a special case.
- * We need to ignore the mode when:
- * - It is part of a net.burst (from a server and
- * a MODE_ADD). Ofcourse we don't ignore mode
- * changes from Uworld.
- * - The found nick is not on the right side off
- * the net.junction.
- * This fixes the bug that when someone (tries to)
- * ride a net.break and does so with the nick of
- * someone on the otherside, that he is nick collided
- * (killed) but his +o still ops the other person.
- */
- if (MyUser(sptr))
- {
- if (!(who = find_chasing(sptr, parv[0], NULL)))
- break;
- }
- else
- {
- if (!(who = findNUser(parv[0])))
- break;
- }
- if (whatt == MODE_ADD && IsServer(sptr) && who->from != sptr->from &&
- !find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
- break;
-
- if (!(member_x = find_member_link(chptr, who)) ||
- (MyUser(sptr) && IsZombie(member_x)))
- {
- sendto_one(cptr, err_str(ERR_USERNOTINCHANNEL),
- me.name, cptr->name, who->name, chptr->chname);
- break;
- }
- /*
- * if the user is +k, prevent a deop from local user
- */
- if (whatt == MODE_DEL && IsChannelService(who) && *curr == 'o') {
- /*
- * XXX - CHECKME
- */
- if (MyUser(cptr)) {
- sendto_one(cptr, err_str(ERR_ISCHANSERVICE), me.name,
- cptr->name, parv[0], chptr->chname);
- break;
- }
- else {
- sprintf_irc(sendbuf,":%s NOTICE * :*** Notice -- Deop of +k user on %s by %s",
- me.name,chptr->chname,cptr->name);
- }
- }
-#ifdef NO_OPER_DEOP_LCHAN
- /*
- * if the user is an oper on a local channel, prevent him
- * from being deoped. that oper can deop himself though.
- */
- if (whatt == MODE_DEL && IsOperOnLocalChannel(who, chptr->chname) &&
- (who != sptr) && MyUser(cptr) && *curr == 'o')
- {
- sendto_one(cptr, err_str(ERR_ISOPERLCHAN), me.name,
- cptr->name, parv[0], chptr->chname);
- break;
- }
-#endif
- if (whatt == MODE_ADD)
- {
- lp = &chops[opcnt++];
- lp->value.cptr = who;
- if (IsServer(sptr) && (!(who->flags & FLAGS_TS8) || ((*curr == 'o') &&
- !(member_x->status & (CHFL_SERVOPOK | CHFL_CHANOP)))))
- *badop = ((member_x->status & CHFL_DEOPPED) && (*curr == 'o')) ? 2 : 3;
- lp->flags = (*curr == 'o') ? MODE_CHANOP : MODE_VOICE;
- lp->flags |= MODE_ADD;
- }
- else if (whatt == MODE_DEL)
- {
- lp = &chops[opcnt++];
- lp->value.cptr = who;
- doesdeop = 1; /* Also when -v */
- lp->flags = (*curr == 'o') ? MODE_CHANOP : MODE_VOICE;
- lp->flags |= MODE_DEL;
- }
- if (*curr == 'o')
- doesop = 1;
- break;
- case 'k':
- if (--parc <= 0)
- break;
- parv++;
- /* check now so we eat the parameter if present */
- if (keychange)
- break;
- else
- {
- char *s = &(*parv)[-1];
- unsigned short count = KEYLEN + 1;
-
- while (*++s > ' ' && *s != ':' && --count);
- *s = '\0';
- if (!**parv) /* nothing left in key */
- break;
- }
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- if (whatt == MODE_ADD)
- {
- if (*mode->key && !IsServer(cptr))
- sendto_one(cptr, err_str(ERR_KEYSET),
- me.name, cptr->name, chptr->chname);
- else if (!*mode->key || IsServer(cptr))
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- if (strlen(lp->value.cp) > KEYLEN)
- lp->value.cp[KEYLEN] = '\0';
- lp->flags = MODE_KEY | MODE_ADD;
- keychange = 1;
- }
- }
- else if (whatt == MODE_DEL)
- {
- /* Debug((DEBUG_INFO, "removing key: mode->key: >%s< *parv: >%s<", mode->key, *parv)); */
- if (0 == ircd_strcmp(mode->key, *parv) || IsServer(cptr))
- {
- /* Debug((DEBUG_INFO, "key matched")); */
- lp = &chops[opcnt++];
- lp->value.cp = mode->key;
- lp->flags = MODE_KEY | MODE_DEL;
- keychange = 1;
- }
- }
- break;
- case 'b':
- if (--parc <= 0) {
- if (0 == banlsent) {
- /*
- * Only send it once
- */
- send_ban_list(cptr, chptr);
- banlsent = 1;
- }
- break;
- }
- parv++;
- if (EmptyString(*parv))
- break;
- if (MyUser(sptr))
- {
- if ((cp = strchr(*parv, ' ')))
- *cp = 0;
- if (opcnt >= MAXMODEPARAMS || **parv == ':' || **parv == '\0')
- break;
- }
- if (whatt == MODE_ADD)
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- lp->flags = MODE_ADD | MODE_BAN;
- }
- else if (whatt == MODE_DEL)
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- lp->flags = MODE_DEL | MODE_BAN;
- }
- break;
- case 'l':
- /*
- * limit 'l' to only *1* change per mode command but
- * eat up others.
- */
- if (limitset)
- {
- if (whatt == MODE_ADD && --parc > 0)
- parv++;
- break;
- }
- if (whatt == MODE_DEL)
- {
- limitset = 1;
- nusers = 0;
- break;
- }
- if (--parc > 0)
- {
- if (EmptyString(*parv))
- break;
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- if (!(nusers = atoi(*++parv)))
- continue;
- lp = &chops[opcnt++];
- lp->flags = MODE_ADD | MODE_LIMIT;
- limitset = 1;
- break;
- }
- need_more_params(cptr, "MODE +l");
- break;
- case 'i': /* falls through for default case */
- if (whatt == MODE_DEL)
- while ((lp = chptr->invites))
- del_invite(lp->value.cptr, chptr);
- default:
- for (ip = flags; *ip; ip += 2)
- if (*(ip + 1) == *curr)
- break;
-
- if (*ip)
- {
- if (whatt == MODE_ADD)
- {
- if (*ip == MODE_PRIVATE)
- newmode &= ~MODE_SECRET;
- else if (*ip == MODE_SECRET)
- newmode &= ~MODE_PRIVATE;
- newmode |= *ip;
- }
- else
- newmode &= ~*ip;
- }
- else if (!IsServer(cptr))
- sendto_one(cptr, err_str(ERR_UNKNOWNMODE),
- me.name, cptr->name, *curr);
- break;
- }
- curr++;
- /*
- * Make sure mode strings such as "+m +t +p +i" are parsed
- * fully.
- */
- if (!*curr && parc > 0)
- {
- curr = *++parv;
- parc--;
- /* If this was from a server, and it is the last
- * parameter and it starts with a digit, it must
- * be the creationtime. --Run
- */
- if (IsServer(sptr))
- {
- if (parc == 1 && IsDigit(*curr))
- {
- newtime = atoi(curr);
- if (newtime && chptr->creationtime == MAGIC_REMOTE_JOIN_TS)
- {
- chptr->creationtime = newtime;
- *badop = 0;
- }
- gotts = 1;
- if (newtime == 0)
- {
- *badop = 2;
- hacknotice = 1;
- }
- else if (newtime > chptr->creationtime)
- { /* It is a net-break ride if we have ops.
- bounce modes if we have ops. --Run */
- if (doesdeop)
- *badop = 2;
- else if (chptr->creationtime == 0)
- {
- if (chptr->creationtime == 0 || doesop)
- chptr->creationtime = newtime;
- *badop = 0;
- }
- /* Bounce: */
- else
- *badop = 1;
- }
- /*
- * A legal *badop can occur when two
- * people join simultaneously a channel,
- * Allow for 10 min of lag (and thus hacking
- * on channels younger then 10 min) --Run
- */
- else if (*badop == 0 ||
- chptr->creationtime > (TStime() - TS_LAG_TIME))
- {
- if (newtime < chptr->creationtime)
- chptr->creationtime = newtime;
- *badop = 0;
- }
- break;
- }
- }
- else
- *badop = 0;
- }
- } /* end of while loop for MODE processing */
-
-#ifdef OPER_MODE_LCHAN
- /*
- * Now reject non chan ops. Accept modes from opers on local channels
- * even if they are deopped
- */
- if (!IsServer(cptr) &&
- (!member_y || !(IsChanOp(member_y) ||
- IsOperOnLocalChannel(sptr, chptr->chname))))
-#else
- if (!IsServer(cptr) && (!member_y || !IsChanOp(member_y)))
-#endif
- {
- *badop = 0;
- return (opcnt || newmode != mode->mode || limitset || keychange) ? 0 : -1;
- }
-
- if (doesop && newtime == 0 && IsServer(sptr))
- *badop = 2;
-
- if (*badop >= 2 &&
- (aconf = find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)))
- *badop = 4;
-
-#ifdef OPER_MODE_LCHAN
- bounce = (*badop == 1 || *badop == 2 ||
- (is_deopped(sptr, chptr) &&
- !IsOperOnLocalChannel(sptr, chptr->chname))) ? 1 : 0;
-#else
- bounce = (*badop == 1 || *badop == 2 || is_deopped(sptr, chptr)) ? 1 : 0;
-#endif
-
- whatt = 0;
- for (ip = flags; *ip; ip += 2) {
- if ((*ip & newmode) && !(*ip & oldm.mode))
- {
- if (bounce)
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- *bmbuf++ = *(ip + 1);
- }
- else
- {
- if (whatt != MODE_ADD)
- {
- *mbuf++ = '+';
- whatt = MODE_ADD;
- }
- mode->mode |= *ip;
- *mbuf++ = *(ip + 1);
- }
- }
- }
- for (ip = flags; *ip; ip += 2) {
- if ((*ip & oldm.mode) && !(*ip & newmode))
- {
- if (bounce)
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = *(ip + 1);
- }
- else
- {
- if (whatt != MODE_DEL)
- {
- *mbuf++ = '-';
- whatt = MODE_DEL;
- }
- mode->mode &= ~*ip;
- *mbuf++ = *(ip + 1);
- }
- }
- }
- blen = nblen = 0;
- if (limitset && !nusers && mode->limit)
- {
- if (bounce)
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = 'l';
- sprintf(numeric, "%-15d", mode->limit);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- strcat(bpbuf, numeric);
- blen += strlen(numeric);
- strcat(bpbuf, " ");
- strcat(nbpbuf, numeric);
- nblen += strlen(numeric);
- strcat(nbpbuf, " ");
- }
- else
- {
- if (whatt != MODE_DEL)
- {
- *mbuf++ = '-';
- whatt = MODE_DEL;
- }
- mode->mode &= ~MODE_LIMIT;
- mode->limit = 0;
- *mbuf++ = 'l';
- }
- }
- /*
- * Reconstruct "+bkov" chain.
- */
- if (opcnt)
- {
- int i = 0;
- char c = 0;
- unsigned int prev_whatt = 0;
-
- for (; i < opcnt; i++)
- {
- lp = &chops[i];
- /*
- * make sure we have correct mode change sign
- */
- if (whatt != (lp->flags & (MODE_ADD | MODE_DEL)))
- {
- if (lp->flags & MODE_ADD)
- {
- *mbuf++ = '+';
- prev_whatt = whatt;
- whatt = MODE_ADD;
- }
- else
- {
- *mbuf++ = '-';
- prev_whatt = whatt;
- whatt = MODE_DEL;
- }
- }
- len = strlen(pbuf);
- nlen = strlen(npbuf);
- /*
- * get c as the mode char and tmp as a pointer to
- * the parameter for this mode change.
- */
- switch (lp->flags & MODE_WPARAS)
- {
- case MODE_CHANOP:
- c = 'o';
- cp = lp->value.cptr->name;
- break;
- case MODE_VOICE:
- c = 'v';
- cp = lp->value.cptr->name;
- break;
- case MODE_BAN:
- /*
- * I made this a bit more user-friendly (tm):
- * nick = nick!*@*
- * nick!user = nick!user@*
- * user@host = *!user@host
- * host.name = *!*@host.name --Run
- */
- c = 'b';
- cp = pretty_mask(lp->value.cp);
- break;
- case MODE_KEY:
- c = 'k';
- cp = lp->value.cp;
- break;
- case MODE_LIMIT:
- c = 'l';
- sprintf(numeric, "%-15d", nusers);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- cp = numeric;
- break;
- }
-
- /* What could be added: cp+' '+' '+<TS>+'\0' */
- if (len + strlen(cp) + 13 > MODEBUFLEN ||
- nlen + strlen(cp) + NUMNICKLEN + 12 > MODEBUFLEN)
- break;
-
- switch (lp->flags & MODE_WPARAS)
- {
- case MODE_KEY:
- if (strlen(cp) > KEYLEN)
- *(cp + KEYLEN) = '\0';
- if ((whatt == MODE_ADD && (*mode->key == '\0' ||
- 0 != ircd_strcmp(mode->key, cp))) ||
- (whatt == MODE_DEL && (*mode->key != '\0')))
- {
- if (bounce)
- {
- if (*mode->key == '\0')
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- strcat(bpbuf, cp);
- blen += strlen(cp);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, cp);
- nblen += strlen(cp);
- strcat(nbpbuf, " ");
- nblen++;
- }
- else
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- strcat(bpbuf, mode->key);
- blen += strlen(mode->key);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, mode->key);
- nblen += strlen(mode->key);
- strcat(nbpbuf, " ");
- nblen++;
- }
- *bmbuf++ = c;
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- else
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- if (whatt == MODE_ADD)
- ircd_strncpy(mode->key, cp, KEYLEN);
- else
- *mode->key = '\0';
- }
- }
- break;
- case MODE_LIMIT:
- if (nusers && nusers != mode->limit)
- {
- if (bounce)
- {
- if (mode->limit == 0)
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- }
- else
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- sprintf(numeric, "%-15d", mode->limit);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- strcat(bpbuf, numeric);
- blen += strlen(numeric);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, numeric);
- nblen += strlen(numeric);
- strcat(nbpbuf, " ");
- nblen++;
- }
- *bmbuf++ = c;
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- else
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- mode->limit = nusers;
- }
- }
- break;
- case MODE_CHANOP:
- case MODE_VOICE:
- member_y = find_member_link(chptr, lp->value.cptr);
- if (lp->flags & MODE_ADD)
- {
- change = (~member_y->status) & CHFL_VOICED_OR_OPPED & lp->flags;
- if (change && bounce)
- {
- if (lp->flags & MODE_CHANOP)
- SetDeopped(member_y);
-
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- *bmbuf++ = c;
- strcat(bpbuf, lp->value.cptr->name);
- blen += strlen(lp->value.cptr->name);
- strcat(bpbuf, " ");
- blen++;
- sprintf_irc(nbpbuf + nblen, "%s%s ", NumNick(lp->value.cptr));
- nblen += strlen(nbpbuf + nblen);
- change = 0;
- }
- else if (change)
- {
- member_y->status |= lp->flags & CHFL_VOICED_OR_OPPED;
- if (IsChanOp(member_y))
- {
- ClearDeopped(member_y);
- if (IsServer(sptr))
- ClearServOpOk(member_y);
- }
- }
- }
- else
- {
- change = member_y->status & CHFL_VOICED_OR_OPPED & lp->flags;
- if (change && bounce)
- {
- if (lp->flags & MODE_CHANOP)
- ClearDeopped(member_y);
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = c;
- strcat(bpbuf, lp->value.cptr->name);
- blen += strlen(lp->value.cptr->name);
- strcat(bpbuf, " ");
- blen++;
- sprintf_irc(nbpbuf + nblen, "%s%s ", NumNick(lp->value.cptr));
- blen += strlen(bpbuf + blen);
- change = 0;
- }
- else
- {
- member_y->status &= ~change;
- if ((change & MODE_CHANOP) && IsServer(sptr))
- SetDeopped(member_y);
- }
- }
- if (change || *badop == 2 || *badop == 4)
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- sprintf_irc(npbuf + nlen, "%s%s ", NumNick(lp->value.cptr));
- nlen += strlen(npbuf + nlen);
- npbuf[nlen++] = ' ';
- npbuf[nlen] = 0;
- }
- else
- {
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- break;
- case MODE_BAN:
-/*
- * Only bans aren't bounced, it makes no sense to bounce last second
- * bans while propagating bans done before the net.rejoin. The reason
- * why I don't bounce net.rejoin bans is because it is too much
- * work to take care of too long strings adding the necessary TS to
- * net.burst bans -- RunLazy
- * We do have to check for *badop==2 now, we don't want HACKs to take
- * effect.
- *
- * Since BURST - I *did* implement net.rejoin ban bouncing. So now it
- * certainly makes sense to also bounce 'last second' bans (bans done
- * after the net.junction). -- RunHardWorker
- */
- if ((change = (whatt & MODE_ADD) &&
- !add_banid(sptr, chptr, cp, !bounce, !add_banid_called)))
- add_banid_called = 1;
- else
- change = (whatt & MODE_DEL) && !del_banid(chptr, cp, !bounce);
-
- if (bounce && change)
- {
- change = 0;
- if ((whatt & MODE_ADD))
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- }
- else if ((whatt & MODE_DEL))
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- }
- *bmbuf++ = c;
- strcat(bpbuf, cp);
- blen += strlen(cp);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, cp);
- nblen += strlen(cp);
- strcat(nbpbuf, " ");
- nblen++;
- }
- if (change)
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- }
- else
- {
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- break;
- }
- } /* for (; i < opcnt; i++) */
- } /* if (opcnt) */
-
- *mbuf++ = '\0';
- *bmbuf++ = '\0';
-
- /* Bounce here */
- if (!hacknotice && *bmodebuf && chptr->creationtime)
- {
- sendto_one(cptr, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
- NumServ(&me), chptr->chname, bmodebuf, nbparambuf,
- *badop == 2 ? (time_t) 0 : chptr->creationtime);
- }
- /* If there are possibly bans to re-add, bounce them now */
- if (add_banid_called && bounce)
- {
- struct SLink *ban[6]; /* Max 6 bans at a time */
- size_t len[6], sblen, total_len;
- int cnt, delayed = 0;
- while (delayed || (ban[0] = next_overlapped_ban()))
- {
- len[0] = strlen(ban[0]->value.ban.banstr);
- cnt = 1; /* We already got one ban :) */
- sblen = sprintf_irc(sendbuf, ":%s MODE %s +b",
- me.name, chptr->chname) - sendbuf;
- total_len = sblen + 1 + len[0]; /* 1 = ' ' */
- /* Find more bans: */
- delayed = 0;
- while (cnt < 6 && (ban[cnt] = next_overlapped_ban()))
- {
- len[cnt] = strlen(ban[cnt]->value.ban.banstr);
- if (total_len + 5 + len[cnt] > BUFSIZE) /* 5 = "b \r\n\0" */
- {
- delayed = cnt + 1; /* != 0 */
- break; /* Flush */
- }
- sendbuf[sblen++] = 'b';
- total_len += 2 + len[cnt++]; /* 2 = "b " */
- }
- while (cnt--)
- {
- sendbuf[sblen++] = ' ';
- strcpy(sendbuf + sblen, ban[cnt]->value.ban.banstr);
- sblen += len[cnt];
- }
- sendbufto_one(cptr); /* Send bounce to uplink */
- if (delayed)
- ban[0] = ban[delayed - 1];
- }
- }
- /* Send -b's of overlapped bans to clients to keep them synchronized */
- if (add_banid_called && !bounce)
- {
- struct SLink *ban;
- char *banstr[6]; /* Max 6 bans at a time */
- size_t len[6], sblen, psblen, total_len;
- int cnt, delayed = 0;
- struct Membership* member_z;
- struct Client *acptr;
- if (IsServer(sptr))
- psblen = sprintf_irc(sendbuf, ":%s MODE %s -b",
- sptr->name, chptr->chname) - sendbuf;
- else /* We rely on IsRegistered(sptr) being true for MODE */
- psblen = sprintf_irc(sendbuf, ":%s!%s@%s MODE %s -b", sptr->name,
- sptr->user->username, sptr->user->host, chptr->chname) - sendbuf;
- while (delayed || (ban = next_removed_overlapped_ban()))
- {
- if (!delayed)
- {
- len[0] = strlen((banstr[0] = ban->value.ban.banstr));
- ban->value.ban.banstr = NULL;
- }
- cnt = 1; /* We already got one ban :) */
- sblen = psblen;
- total_len = sblen + 1 + len[0]; /* 1 = ' ' */
- /* Find more bans: */
- delayed = 0;
- while (cnt < 6 && (ban = next_removed_overlapped_ban()))
- {
- len[cnt] = strlen((banstr[cnt] = ban->value.ban.banstr));
- ban->value.ban.banstr = NULL;
- if (total_len + 5 + len[cnt] > BUFSIZE) /* 5 = "b \r\n\0" */
- {
- delayed = cnt + 1; /* != 0 */
- break; /* Flush */
- }
- sendbuf[sblen++] = 'b';
- total_len += 2 + len[cnt++]; /* 2 = "b " */
- }
- while (cnt--)
- {
- sendbuf[sblen++] = ' ';
- strcpy(sendbuf + sblen, banstr[cnt]);
- MyFree(banstr[cnt]);
- sblen += len[cnt];
- }
- for (member_z = chptr->members; member_z; member_z = member_z->next_member) {
- acptr = member_z->user;
- if (MyConnect(acptr) && !IsZombie(member_z))
- sendbufto_one(acptr);
- }
- if (delayed)
- {
- banstr[0] = banstr[delayed - 1];
- len[0] = len[delayed - 1];
- }
- }
- }
-
- return gotts ? 1 : -1;
+ send_reply(cptr, RPL_ENDOFBANLIST, chptr->chname);
}
/* We are now treating the <key> part of /join <channel list> <key> as a key
* Now a user CAN escape anything if invited -- Isomer
*/
- for (lp = sptr->user->invited; lp; lp = lp->next)
+ for (lp = (cli_user(sptr))->invited; lp; lp = lp->next)
if (lp->value.chptr == chptr)
return 0;
-#ifdef OPER_WALK_THROUGH_LMODES
/* An oper can force a join on a local channel using "OVERRIDE" as the key.
a HACK(4) notice will be sent if he would not have been supposed
to join normally. */
- if (IsOperOnLocalChannel(sptr,chptr->chname) && !BadPtr(key) && compall("OVERRIDE",key) == 0)
- {
+ if (IsLocalChannel(chptr->chname) && HasPriv(sptr, PRIV_WALK_LCHAN) &&
+ !BadPtr(key) && compall("OVERRIDE",key) == 0)
overrideJoin = MAGIC_OPER_OVERRIDE;
- }
-#endif
if (chptr->mode.mode & MODE_INVITEONLY)
return overrideJoin + ERR_INVITEONLYCHAN;
*/
void clean_channelname(char *cn)
{
- for (; *cn; ++cn) {
- if (!IsChannelChar(*cn)) {
- *cn = '\0';
+ int i;
+
+ for (i = 0; cn[i]; i++) {
+ if (i >= CHANNELLEN || !IsChannelChar(cn[i])) {
+ cn[i] = '\0';
return;
}
- if (IsChannelLower(*cn)) {
- *cn = ToLower(*cn);
+ if (IsChannelLower(cn[i])) {
+ cn[i] = ToLower(cn[i]);
#ifndef FIXME
/*
* Remove for .08+
* toupper(0xd0)
*/
- if ((unsigned char)(*cn) == 0xd0)
- *cn = (char) 0xf0;
+ if ((unsigned char)(cn[i]) == 0xd0)
+ cn[i] = (char) 0xf0;
#endif
}
}
/*
* Delete last link in chain if the list is max length
*/
- assert(list_length(cptr->user->invited) == cptr->user->invites);
- if (cptr->user->invites>=MAXCHANNELSPERUSER)
- del_invite(cptr, cptr->user->invited->value.chptr);
+ assert(list_length((cli_user(cptr))->invited) == (cli_user(cptr))->invites);
+ if ((cli_user(cptr))->invites >= feature_int(FEAT_MAXCHANNELSPERUSER))
+ del_invite(cptr, (cli_user(cptr))->invited->value.chptr);
/*
* Add client to channel invite list
*/
/*
* Add channel to the end of the client invite list
*/
- for (tmp = &(cptr->user->invited); *tmp; tmp = &((*tmp)->next));
+ for (tmp = &((cli_user(cptr))->invited); *tmp; tmp = &((*tmp)->next));
inv = make_link();
inv->value.chptr = chptr;
inv->next = NULL;
(*tmp) = inv;
- cptr->user->invites++;
+ (cli_user(cptr))->invites++;
}
/*
*inv = tmp->next;
free_link(tmp);
tmp = 0;
- cptr->user->invites--;
+ (cli_user(cptr))->invites--;
break;
}
- for (inv = &(cptr->user->invited); (tmp = *inv); inv = &tmp->next)
+ for (inv = &((cli_user(cptr))->invited); (tmp = *inv); inv = &tmp->next)
if (tmp->value.chptr == chptr)
{
*inv = tmp->next;
/* List and skip all channels that are listen */
void list_next_channels(struct Client *cptr, int nr)
{
- struct ListingArgs *args = cptr->listing;
+ struct ListingArgs *args = cli_listing(cptr);
struct Channel *chptr = args->chptr;
chptr->mode.mode &= ~MODE_LISTED;
while (is_listed(chptr) || --nr >= 0)
{
for (; chptr; chptr = chptr->next)
{
- if (!cptr->user || (SecretChannel(chptr) && !find_channel_member(cptr, chptr)))
+ if (!cli_user(cptr) || (SecretChannel(chptr) && !find_channel_member(cptr, chptr)))
continue;
if (chptr->users > args->min_users && chptr->users < args->max_users &&
chptr->creationtime > args->min_time &&
chptr->topic_time < args->max_topic_time)))
{
if (ShowChannel(cptr,chptr))
- sendto_one(cptr, rpl_str(RPL_LIST), me.name, cptr->name,
- chptr->chname,
- chptr->users, chptr->topic);
+ send_reply(cptr, RPL_LIST, chptr->chname, chptr->users,
+ chptr->topic);
chptr = chptr->next;
break;
}
}
if (!chptr)
{
- MyFree(cptr->listing);
- cptr->listing = NULL;
- sendto_one(cptr, rpl_str(RPL_LISTEND), me.name, cptr->name);
+ MyFree(cli_listing(cptr));
+ cli_listing(cptr) = NULL;
+ send_reply(cptr, RPL_LISTEND);
break;
}
}
if (chptr)
{
- cptr->listing->chptr = chptr;
+ (cli_listing(cptr))->chptr = chptr;
chptr->mode.mode |= MODE_LISTED;
}
-}
-
-void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
- int *send_itp, char is_a_ban, int mode)
-{
- int first = *firstp;
-
- /*
- * Heh - we do not need to test if it still fits in the buffer, because
- * this BURST message is reconstructed from another BURST message, and
- * it only can become smaller. --Run
- */
-
- if (*firstp) /* First token in this parameter ? */
- {
- *firstp = 0;
- if (*send_itp == 0)
- *send_itp = 1; /* Buffer contains data to be sent */
- sendbuf[(*sblenp)++] = ' ';
- if (is_a_ban)
- {
- sendbuf[(*sblenp)++] = ':'; /* Bans are always the last "parv" */
- sendbuf[(*sblenp)++] = is_a_ban;
- }
- }
- else /* Of course, 'send_it' is already set here */
- /* Seperate banmasks with a space because
- they can contain commas themselfs: */
- sendbuf[(*sblenp)++] = is_a_ban ? ' ' : ',';
- strcpy(sendbuf + *sblenp, token);
- *sblenp += strlen(token);
- if (!is_a_ban) /* nick list ? Need to take care
- of modes for nicks: */
- {
- static int last_mode = 0;
- mode &= CHFL_CHANOP | CHFL_VOICE;
- if (first)
- last_mode = 0;
- if (last_mode != mode) /* Append mode like ':ov' if changed */
- {
- last_mode = mode;
- sendbuf[(*sblenp)++] = ':';
- if (mode & CHFL_CHANOP)
- sendbuf[(*sblenp)++] = 'o';
- if (mode & CHFL_VOICE)
- sendbuf[(*sblenp)++] = 'v';
- }
- sendbuf[*sblenp] = '\0';
- }
-}
-
-void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
- const char *param, int *count)
-{
- static char* pb;
- static char* sbp;
- static char* sbpi;
- int paramdoesntfit = 0;
- char parabuf[MODEBUFLEN];
-
- assert(0 != sptr);
- assert(0 != chptr);
- assert(0 != count);
-
- if (*count == -1) /* initialize ? */
- {
- sbp = sbpi =
- sprintf_irc(sendbuf, ":%s MODE %s -", sptr->name, chptr->chname);
- pb = parabuf;
- *count = 0;
- }
- /* m == 0 means flush */
- if (m)
- {
- if (param)
- {
- size_t nplen = strlen(param);
- if (pb - parabuf + nplen + 23 > MODEBUFLEN)
- paramdoesntfit = 1;
- else
- {
- *sbp++ = m;
- *pb++ = ' ';
- strcpy(pb, param);
- pb += nplen;
- ++*count;
- }
- }
- else
- *sbp++ = m;
- }
- else if (*count == 0)
- return;
- if (*count == 6 || !m || paramdoesntfit)
- {
- struct Membership* member;
- strcpy(sbp, parabuf);
- for (member = chptr->members; member; member = member->next_member)
- if (MyUser(member->user))
- sendbufto_one(member->user);
- sbp = sbpi;
- pb = parabuf;
- *count = 0;
- }
- if (paramdoesntfit)
- {
- *sbp++ = m;
- *pb++ = ' ';
- strcpy(pb, param);
- pb += strlen(param);
- ++*count;
- }
+ update_write(cptr);
}
-
/*
* Consider:
*
if (MyUser(who)) /* server 4 */
{
if (IsServer(cptr)) /* Case b) ? */
- sendto_one(cptr, PartFmt1, who->name, chptr->chname);
+ sendcmdto_one(who, CMD_PART, cptr, "%H", chptr);
remove_user_from_channel(who, chptr);
return;
}
- if (who->from == cptr) /* True on servers 1, 5 and 6 */
+ if (cli_from(who) == cptr) /* True on servers 1, 5 and 6 */
{
- struct Client *acptr = IsServer(sptr) ? sptr : sptr->user->server;
- for (; acptr != &me; acptr = acptr->serv->up)
- if (acptr == who->user->server) /* Case d) (server 5) */
+ struct Client *acptr = IsServer(sptr) ? sptr : (cli_user(sptr))->server;
+ for (; acptr != &me; acptr = (cli_serv(acptr))->up)
+ if (acptr == (cli_user(who))->server) /* Case d) (server 5) */
{
remove_user_from_channel(who, chptr);
return;
if (channel_all_zombies(chptr))
remove_user_from_channel(who, chptr);
+ /* XXX Can't actually call Debug here; if the channel is all zombies,
+ * chptr will no longer exist when we get here.
Debug((DEBUG_INFO, "%s is now a zombie on %s", who->name, chptr->chname));
+ */
}
int number_of_zombies(struct Channel *chptr)
return count;
}
-void send_user_joins(struct Client *cptr, struct Client *user)
-{
- struct Membership* chan;
- struct Channel* chptr;
- int cnt = 0;
- int len = 0;
- int clen;
- char* mask;
- char buf[BUFSIZE];
-
- *buf = ':';
- strcpy(buf + 1, user->name);
- strcat(buf, " JOIN ");
- len = strlen(user->name) + 7;
-
- for (chan = user->user->channel; chan; chan = chan->next_channel)
- {
- chptr = chan->channel;
- assert(0 != chptr);
-
- if ((mask = strchr(chptr->chname, ':')))
- if (match(++mask, cptr->name))
- continue;
- if (*chptr->chname == '&')
- continue;
- if (IsZombie(chan))
- continue;
- clen = strlen(chptr->chname);
- if (clen + 1 + len > BUFSIZE - 3)
- {
- if (cnt)
- {
- buf[len - 1] = '\0';
- sendto_one(cptr, "%s", buf);
- }
- *buf = ':';
- strcpy(buf + 1, user->name);
- strcat(buf, " JOIN ");
- len = strlen(user->name) + 7;
- cnt = 0;
- }
- strcpy(buf + len, chptr->chname);
- cnt++;
- len += clen;
- if (chan->next_channel)
- {
- len++;
- strcat(buf, ",");
- }
- }
- if (*buf && cnt)
- sendto_one(cptr, "%s", buf);
-}
-
-/*
- * send_hack_notice()
- *
- * parc & parv[] are the same as that of the calling function:
- * mtype == 1 is from m_mode, 2 is from m_create, 3 is from m_kick.
- *
- * This function prepares sendbuf with the server notices and wallops
- * to be sent for all hacks. -Ghostwolf 18-May-97
- */
-
-void send_hack_notice(struct Client *cptr, struct Client *sptr, int parc,
- char *parv[], int badop, int mtype)
-{
- struct Channel *chptr;
- static char params[MODEBUFLEN];
- int i = 3;
- chptr = FindChannel(parv[1]);
- *params = '\0';
-
- /* P10 servers require numeric nick conversion before sending. */
- switch (mtype)
- {
- case 1: /* Convert nicks for MODE HACKs here */
- {
- char *mode = parv[2];
- while (i < parc)
- {
- while (*mode && *mode != 'o' && *mode != 'v')
- ++mode;
- strcat(params, " ");
- if (*mode == 'o' || *mode == 'v')
- {
- /*
- * blindly stumble through parameter list hoping one of them
- * might turn out to be a numeric nick
- * NOTE: this should not cause a problem but _may_ end up finding
- * something we aren't looking for. findNUser should be able to
- * handle any garbage that is thrown at it, but may return a client
- * if we happen to get lucky with a mode string or a timestamp
- */
- struct Client *acptr;
- if ((acptr = findNUser(parv[i])) != NULL) /* Convert nicks here */
- strcat(params, acptr->name);
- else
- {
- strcat(params, "<");
- strcat(params, parv[i]);
- strcat(params, ">");
- }
- }
- else /* If it isn't a numnick, send it 'as is' */
- strcat(params, parv[i]);
- i++;
- }
- sprintf_irc(sendbuf,
- ":%s NOTICE * :*** Notice -- %sHACK(%d): %s MODE %s %s%s ["
- TIME_T_FMT "]", me.name, (badop == 3) ? "BOUNCE or " : "", badop,
- parv[0], parv[1], parv[2], params, chptr->creationtime);
- sendbufto_op_mask((badop == 3) ? SNO_HACK3 : (badop ==
- 4) ? SNO_HACK4 : SNO_HACK2);
-
- if ((IsServer(sptr)) && (badop == 2))
- {
- sprintf_irc(sendbuf, ":%s DESYNCH :HACK: %s MODE %s %s%s",
- me.name, parv[0], parv[1], parv[2], params);
- sendbufto_serv_butone(cptr);
- }
- break;
- }
- case 2: /* No conversion is needed for CREATE; the only numnick is sptr */
- {
- sendto_serv_butone(cptr, ":%s DESYNCH :HACK: %s CREATE %s %s",
- me.name, sptr->name, chptr->chname, parv[2]);
- sendto_op_mask(SNO_HACK2, "HACK(2): %s CREATE %s %s",
- sptr->name, chptr->chname, parv[2]);
- break;
- }
- case 3: /* Convert nick in KICK message */
- {
- struct Client *acptr;
- if ((acptr = findNUser(parv[2])) != NULL) /* attempt to convert nick */
- sprintf_irc(sendbuf,
- ":%s NOTICE * :*** Notice -- HACK: %s KICK %s %s :%s",
- me.name, sptr->name, parv[1], acptr->name, parv[3]);
- else /* if conversion fails, send it 'as is' in <>'s */
- sprintf_irc(sendbuf,
- ":%s NOTICE * :*** Notice -- HACK: %s KICK %s <%s> :%s",
- me.name, sptr->name, parv[1], parv[2], parv[3]);
- sendbufto_op_mask(SNO_HACK4);
- break;
- }
- }
-}
-
/*
* This helper function builds an argument string in strptr, consisting
* of the original string, a space, and str1 and str2 concatenated (if,
* of course, str2 is not NULL)
*/
static void
-build_string(char *strptr, int *strptr_i, char *str1, char *str2)
+build_string(char *strptr, int *strptr_i, char *str1, char *str2, char c)
{
- strptr[(*strptr_i)++] = ' ';
+ if (c)
+ strptr[(*strptr_i)++] = c;
while (*str1)
strptr[(*strptr_i)++] = *(str1++);
/* Ok, if we were given the OPMODE flag, hide the source if its a user */
if (mbuf->mb_dest & MODEBUF_DEST_OPMODE && !IsServer(mbuf->mb_source))
- app_source = mbuf->mb_source->user->server;
+ app_source = (cli_user(mbuf->mb_source))->server;
else
app_source = mbuf->mb_source;
}
if (MB_TYPE(mbuf, i) & (MODE_CHANOP | MODE_VOICE)) {
- tmp = strlen(MB_CLIENT(mbuf, i)->name);
+ tmp = strlen(cli_name(MB_CLIENT(mbuf, i)));
if ((totalbuflen - IRCD_MAX(5, tmp)) <= 0) /* don't overflow buffer */
MB_TYPE(mbuf, i) |= MODE_SAVE; /* save for later */
/* deal with clients... */
if (MB_TYPE(mbuf, i) & (MODE_CHANOP | MODE_VOICE))
- build_string(strptr, strptr_i, MB_CLIENT(mbuf, i)->name, 0);
+ build_string(strptr, strptr_i, cli_name(MB_CLIENT(mbuf, i)), 0, ' ');
/* deal with strings... */
else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN))
- build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0);
+ build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0, ' ');
/*
* deal with limit; note we cannot include the limit parameter if we're
*/
else if ((MB_TYPE(mbuf, i) & (MODE_ADD | MODE_LIMIT)) ==
(MODE_ADD | MODE_LIMIT))
- build_string(strptr, strptr_i, limitbuf, 0);
+ build_string(strptr, strptr_i, limitbuf, 0, ' ');
}
/* send the messages off to their destination */
if (mbuf->mb_dest & MODEBUF_DEST_HACK2) {
- sendto_op_mask(SNO_HACK2, "HACK(2): %s MODE %s %s%s%s%s%s%s [" TIME_T_FMT
- "]", app_source->name, mbuf->mb_channel->chname,
- rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "", addbuf,
- remstr, addstr, mbuf->mb_channel->creationtime);
- sendto_serv_butone(mbuf->mb_connect, "%s " TOK_DESYNCH
- " :HACK: %s MODE %s %s%s%s%s%s%s [" TIME_T_FMT "]",
- NumServ(&me), app_source->name,
- mbuf->mb_channel->chname, rembuf_i ? "-" : "", rembuf,
- addbuf_i ? "+" : "", addbuf, remstr, addstr,
- mbuf->mb_channel->creationtime);
+ sendto_opmask_butone(0, SNO_HACK2, "HACK(2): %s MODE %s %s%s%s%s%s%s "
+ "[%Tu]", cli_name(app_source),
+ mbuf->mb_channel->chname,
+ rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
+ addbuf, remstr, addstr,
+ mbuf->mb_channel->creationtime);
+ sendcmdto_serv_butone(&me, CMD_DESYNCH, mbuf->mb_connect,
+ ":HACK: %s MODE %s %s%s%s%s%s%s [%Tu]",
+ cli_name(app_source), mbuf->mb_channel->chname,
+ rembuf_i ? "-" : "", rembuf,
+ addbuf_i ? "+" : "", addbuf, remstr, addstr,
+ mbuf->mb_channel->creationtime);
}
if (mbuf->mb_dest & MODEBUF_DEST_HACK3)
- sendto_op_mask(SNO_HACK3, "BOUNCE or HACK(3): %s MODE %s %s%s%s%s%s%s ["
- TIME_T_FMT "]", app_source->name,
- mbuf->mb_channel->chname, rembuf_i ? "-" : "", rembuf,
- addbuf_i ? "+" : "", addbuf, remstr, addstr,
- mbuf->mb_channel->creationtime);
+ sendto_opmask_butone(0, SNO_HACK3, "BOUNCE or HACK(3): %s MODE %s "
+ "%s%s%s%s%s%s [%Tu]", cli_name(app_source),
+ mbuf->mb_channel->chname, rembuf_i ? "-" : "",
+ rembuf, addbuf_i ? "+" : "", addbuf, remstr, addstr,
+ mbuf->mb_channel->creationtime);
if (mbuf->mb_dest & MODEBUF_DEST_HACK4)
- sendto_op_mask(SNO_HACK4, "HACK(4): %s MODE %s %s%s%s%s%s%s [" TIME_T_FMT
- "]", app_source->name, mbuf->mb_channel->chname,
- rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "", addbuf,
- remstr, addstr, mbuf->mb_channel->creationtime);
+ sendto_opmask_butone(0, SNO_HACK4, "HACK(4): %s MODE %s %s%s%s%s%s%s "
+ "[%Tu]", cli_name(app_source),
+ mbuf->mb_channel->chname,
+ rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
+ addbuf, remstr, addstr,
+ mbuf->mb_channel->creationtime);
-#ifdef OPATH
- if (mbuf->mb_dest & MODEBUF_DEST_LOG) {
- if (IsServer(mbuf->mb_source))
- write_log(OPATH, TIME_T_FMT " %s OPMODE %s %s%s%s%s%s%s\n", TStime(),
- mbuf->mb_source->name, mbuf->mb_channel->chname,
- rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "", addbuf,
- remstr, addstr);
- else
- write_log(OPATH, TIME_T_FMT " %s!%s@%s OPMODE %s %s%s%s%s%s%s\n",
- TStime(), mbuf->mb_source->name,
- mbuf->mb_source->user->username, mbuf->mb_source->user->host,
- mbuf->mb_channel->chname, rembuf_i ? "-" : "", rembuf,
- addbuf_i ? "+" : "", addbuf, remstr, addstr);
- }
-#endif
+ if (mbuf->mb_dest & MODEBUF_DEST_LOG)
+ log_write(LS_OPERMODE, L_INFO, LOG_NOSNOTICE,
+ "%#C OPMODE %H %s%s%s%s%s%s", mbuf->mb_source,
+ mbuf->mb_channel, rembuf_i ? "-" : "", rembuf,
+ addbuf_i ? "+" : "", addbuf, remstr, addstr);
if (mbuf->mb_dest & MODEBUF_DEST_CHANNEL)
- sendto_channel_butserv(mbuf->mb_channel, app_source,
- ":%s MODE %s %s%s%s%s%s%s", app_source->name,
- mbuf->mb_channel->chname, rembuf_i ? "-" : "",
- rembuf, addbuf_i ? "+" : "", addbuf, remstr,
- addstr);
+ sendcmdto_channel_butserv(app_source, CMD_MODE, mbuf->mb_channel,
+ "%H %s%s%s%s%s%s", mbuf->mb_channel,
+ rembuf_i ? "-" : "", rembuf,
+ addbuf_i ? "+" : "", addbuf, remstr, addstr);
}
/* Now are we supposed to propagate to other servers? */
/* deal with modes that take clients */
if (MB_TYPE(mbuf, i) & (MODE_CHANOP | MODE_VOICE))
- build_string(strptr, strptr_i, NumNick(MB_CLIENT(mbuf, i)));
+ build_string(strptr, strptr_i, NumNick(MB_CLIENT(mbuf, i)), ' ');
/* deal with modes that take strings */
else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN))
- build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0);
+ build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0, ' ');
/*
* deal with the limit. Logic here is complicated; if HACK2 is set,
* include the original limit if it looks like it's being removed
*/
else if ((MB_TYPE(mbuf, i) & limitdel) == limitdel)
- build_string(strptr, strptr_i, limitbuf, 0);
+ build_string(strptr, strptr_i, limitbuf, 0, ' ');
}
/* we were told to deop the source */
if (mbuf->mb_dest & MODEBUF_DEST_DEOP) {
addbuf[addbuf_i++] = 'o'; /* remember, sense is reversed */
addbuf[addbuf_i] = '\0'; /* terminate the string... */
- build_string(addstr, &addstr_i, NumNick(mbuf->mb_source)); /* add user */
+ build_string(addstr, &addstr_i, NumNick(mbuf->mb_source), ' ');
/* mark that we've done this, so we don't do it again */
mbuf->mb_dest &= ~MODEBUF_DEST_DEOP;
if (mbuf->mb_dest & MODEBUF_DEST_OPMODE) {
/* If OPMODE was set, we're propagating the mode as an OPMODE message */
- if (IsServer(mbuf->mb_source))
- sendto_serv_butone(mbuf->mb_connect, "%s " TOK_OPMODE
- " %s %s%s%s%s%s%s", NumServ(mbuf->mb_source),
- mbuf->mb_channel->chname, rembuf_i ? "-" : "",
- rembuf, addbuf_i ? "+" : "", addbuf, remstr,
- addstr);
- else
- sendto_serv_butone(mbuf->mb_connect, "%s%s " TOK_OPMODE
- " %s %s%s%s%s%s%s", NumNick(mbuf->mb_source),
- mbuf->mb_channel->chname, rembuf_i ? "-" : "",
- rembuf, addbuf_i ? "+" : "", addbuf, remstr,
- addstr);
+ sendcmdto_serv_butone(mbuf->mb_source, CMD_OPMODE, mbuf->mb_connect,
+ "%H %s%s%s%s%s%s", mbuf->mb_channel,
+ rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
+ addbuf, remstr, addstr);
} else if (mbuf->mb_dest & MODEBUF_DEST_BOUNCE) {
/*
* If HACK2 was set, we're bouncing; we send the MODE back to the
* connection we got it from with the senses reversed and a TS of 0;
* origin is us
*/
- sendto_one(mbuf->mb_connect, "%s " TOK_MODE " %s %s%s%s%s%s%s "
- TIME_T_FMT, NumServ(&me), mbuf->mb_channel->chname,
- addbuf_i ? "-" : "", addbuf, rembuf_i ? "+" : "", rembuf,
- addstr, remstr, mbuf->mb_channel->creationtime);
+ sendcmdto_one(&me, CMD_MODE, mbuf->mb_connect, "%H %s%s%s%s%s%s %Tu",
+ mbuf->mb_channel, addbuf_i ? "-" : "", addbuf,
+ rembuf_i ? "+" : "", rembuf, addstr, remstr,
+ mbuf->mb_channel->creationtime);
} else {
/*
* We're propagating a normal MODE command to the rest of the network;
* we send the actual channel TS unless this is a HACK3 or a HACK4
*/
if (IsServer(mbuf->mb_source))
- sendto_serv_butone(mbuf->mb_connect, "%s " TOK_MODE " %s %s%s%s%s%s%s "
- TIME_T_FMT, NumServ(mbuf->mb_source),
- mbuf->mb_channel->chname, rembuf_i ? "-" : "",
- rembuf, addbuf_i ? "+" : "", addbuf, remstr,
- addstr, (mbuf->mb_dest & MODEBUF_DEST_HACK4) ? 0 :
- mbuf->mb_channel->creationtime);
+ sendcmdto_serv_butone(mbuf->mb_source, CMD_MODE, mbuf->mb_connect,
+ "%H %s%s%s%s%s%s %Tu", mbuf->mb_channel,
+ rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
+ addbuf, remstr, addstr,
+ (mbuf->mb_dest & MODEBUF_DEST_HACK4) ? 0 :
+ mbuf->mb_channel->creationtime);
else
- sendto_serv_butone(mbuf->mb_connect, "%s%s " TOK_MODE
- " %s %s%s%s%s%s%s", NumNick(mbuf->mb_source),
- mbuf->mb_channel->chname, rembuf_i ? "-" : "",
- rembuf, addbuf_i ? "+" : "", addbuf, remstr,
- addstr);
+ sendcmdto_serv_butone(mbuf->mb_source, CMD_MODE, mbuf->mb_connect,
+ "%H %s%s%s%s%s%s", mbuf->mb_channel,
+ rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
+ addbuf, remstr, addstr);
}
}
mode &= (MODE_ADD | MODE_DEL | MODE_PRIVATE | MODE_SECRET | MODE_MODERATED |
MODE_TOPICLIMIT | MODE_INVITEONLY | MODE_NOPRIVMSGS);
+ if (!(mode & ~(MODE_ADD | MODE_DEL))) /* don't add empty modes... */
+ return;
+
if (mode & MODE_ADD) {
mbuf->mb_rem &= ~mode;
mbuf->mb_add |= mode;
return modebuf_flush_int(mbuf, 1);
}
+/*
+ * This extracts the simple modes contained in mbuf
+ */
+void
+modebuf_extract(struct ModeBuf *mbuf, char *buf)
+{
+ static int flags[] = {
+/* MODE_CHANOP, 'o', */
+/* MODE_VOICE, 'v', */
+ MODE_PRIVATE, 'p',
+ MODE_SECRET, 's',
+ MODE_MODERATED, 'm',
+ MODE_TOPICLIMIT, 't',
+ MODE_INVITEONLY, 'i',
+ MODE_NOPRIVMSGS, 'n',
+ MODE_KEY, 'k',
+/* MODE_BAN, 'b', */
+ MODE_LIMIT, 'l',
+ 0x0, 0x0
+ };
+ unsigned int add;
+ int i, bufpos = 0, len;
+ int *flag_p;
+ char *key = 0, limitbuf[20];
+
+ assert(0 != mbuf);
+ assert(0 != buf);
+
+ buf[0] = '\0';
+
+ add = mbuf->mb_add;
+
+ for (i = 0; i < mbuf->mb_count; i++) { /* find keys and limits */
+ if (MB_TYPE(mbuf, i) & MODE_ADD) {
+ add |= MB_TYPE(mbuf, i) & (MODE_KEY | MODE_LIMIT);
+
+ if (MB_TYPE(mbuf, i) & MODE_KEY) /* keep strings */
+ key = MB_STRING(mbuf, i);
+ else if (MB_TYPE(mbuf, i) & MODE_LIMIT)
+ ircd_snprintf(0, limitbuf, sizeof(limitbuf), "%d", MB_UINT(mbuf, i));
+ }
+ }
+
+ if (!add)
+ return;
+
+ buf[bufpos++] = '+'; /* start building buffer */
+
+ for (flag_p = flags; flag_p[0]; flag_p += 2)
+ if (*flag_p & add)
+ buf[bufpos++] = flag_p[1];
+
+ for (i = 0, len = bufpos; i < len; i++) {
+ if (buf[i] == 'k')
+ build_string(buf, &bufpos, key, 0, ' ');
+ else if (buf[i] == 'l')
+ build_string(buf, &bufpos, limitbuf, 0, ' ');
+ }
+
+ buf[bufpos] = '\0';
+
+ return;
+}
+
/*
* Simple function to invalidate bans
*/
unsigned int flags;
unsigned int dir;
unsigned int done;
+ unsigned int add;
+ unsigned int del;
int args_used;
int max_args;
int numbans;
if (state->done & DONE_NOTOPER)
return;
- sendto_one(state->sptr, err_str(state->flags & MODE_PARSE_NOTOPER ?
- ERR_CHANOPRIVSNEEDED : ERR_NOTONCHANNEL),
- me.name, state->sptr->name, state->chptr->chname);
+ send_reply(state->sptr, (state->flags & MODE_PARSE_NOTOPER) ?
+ ERR_CHANOPRIVSNEEDED : ERR_NOTONCHANNEL, state->chptr->chname);
state->done |= DONE_NOTOPER;
}
state->parc--;
state->max_args--;
- if (!t_limit) /* if it was zero, ignore it */
+ if (!(state->flags & MODE_PARSE_WIPEOUT) &&
+ (!t_limit || t_limit == state->chptr->mode.limit))
return;
} else
t_limit = state->chptr->mode.limit;
return;
state->done |= DONE_LIMIT;
- assert(0 != state->mbuf);
+ if (!state->mbuf)
+ return;
modebuf_mode_uint(state->mbuf, state->dir | flag_p[0], t_limit);
state->chptr->mode.mode |= flag_p[0];
state->chptr->mode.limit = t_limit;
} else {
- state->chptr->mode.mode &= flag_p[0];
+ state->chptr->mode.mode &= ~flag_p[0];
state->chptr->mode.limit = 0;
}
}
return;
}
+ if (!state->mbuf)
+ return;
+
/* can't add a key if one is set, nor can one remove the wrong key */
if (!(state->flags & MODE_PARSE_FORCE))
if ((state->dir == MODE_ADD && *state->chptr->mode.key) ||
(state->dir == MODE_DEL &&
ircd_strcmp(state->chptr->mode.key, t_str))) {
- sendto_one(state->sptr, err_str(ERR_KEYSET), me.name, state->sptr->name,
- state->chptr->chname);
+ send_reply(state->sptr, ERR_KEYSET, state->chptr->chname);
return;
}
- assert(0 != state->mbuf);
+ if (!(state->flags & MODE_PARSE_WIPEOUT) && state->dir == MODE_ADD &&
+ !ircd_strcmp(state->chptr->mode.key, t_str))
+ return; /* no key change */
if (state->flags & MODE_PARSE_BOUNCE) {
if (*state->chptr->mode.key) /* reset old key */
newban->next = 0;
DupString(newban->value.ban.banstr, t_str);
- newban->value.ban.who = state->sptr->name;
+ newban->value.ban.who = cli_name(state->sptr);
newban->value.ban.when = TStime();
newban->flags = CHFL_BAN | MODE_ADD;
} else if (state->dir == MODE_ADD) {
/* if the ban already exists, don't worry about it */
if (!ircd_strcmp(ban->value.ban.banstr, t_str)) {
+ newban->flags &= ~MODE_ADD; /* don't add ban at all */
+ MyFree(newban->value.ban.banstr); /* stopper a leak */
+ state->numbans--; /* deallocate last ban */
if (state->done & DONE_BANCLEAN) /* If we're cleaning, finish */
break;
- continue;
} else if (!mmatch(ban->value.ban.banstr, t_str)) {
if (!(ban->flags & MODE_DEL))
newban->flags |= CHFL_BAN_OVERLAPPED; /* our ban overlaps */
} else if (!mmatch(t_str, ban->value.ban.banstr))
ban->flags |= MODE_DEL; /* mark ban for deletion: overlapping */
- if (!ban->next) {
+ if (!ban->next && (newban->flags & MODE_ADD)) {
ban->next = newban; /* add our ban with its flags */
break; /* get out of loop */
}
MyFree(ban->value.ban.banstr);
} else {
if (state->flags & MODE_PARSE_SET && MyUser(state->sptr) &&
- (len > MAXBANLENGTH || count >= MAXBANS)) {
- send_error_to_client(state->sptr, ERR_BANLISTFULL,
- state->chptr->chname, ban->value.ban.banstr);
+ (len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXBANS)) ||
+ count >= feature_int(FEAT_MAXBANS))) {
+ send_reply(state->sptr, ERR_BANLISTFULL, state->chptr->chname,
+ ban->value.ban.banstr);
count--;
len -= banlen;
if (MyUser(state->sptr) && state->max_args <= 0) /* drop if too many args */
return;
- if (state->parc <= 0) { /* warn if not enough args */
- if (MyUser(state->sptr))
- need_more_params(state->sptr, state->dir == MODE_ADD ?
- (flag_p[0] == MODE_CHANOP ? "MODE +o" : "MODE +v") :
- (flag_p[0] == MODE_CHANOP ? "MODE -o" : "MODE -v"));
+ if (state->parc <= 0) /* return if not enough args */
return;
- }
t_str = state->parv[state->args_used++]; /* grab arg */
state->parc--;
else
acptr = findNUser(t_str);
+ if (!acptr)
+ return; /* find_chasing() already reported an error to the user */
+
for (i = 0; i < MAXPARA; i++) /* find an element to stick them in */
if (!state->cli_change[i].flag || (state->cli_change[i].client == acptr &&
state->cli_change[i].flag & flag_p[0]))
state->cli_change[i].client)) ||
(MyUser(state->sptr) && IsZombie(member))) {
if (MyUser(state->sptr))
- sendto_one(state->sptr, err_str(ERR_USERNOTINCHANNEL), me.name,
- state->sptr->name, state->cli_change[i].client->name,
+ send_reply(state->sptr, ERR_USERNOTINCHANNEL,
+ cli_name(state->cli_change[i].client),
state->chptr->chname);
continue;
}
/* prevent +k users from being deopped */
if (IsChannelService(state->cli_change[i].client)) {
if (state->flags & MODE_PARSE_FORCE) /* it was forced */
- sendto_op_mask(SNO_HACK4, ":%s NOTICE * :*** Notice -- "
- "Deop of +k user on %s by %s",me.name,
- state->chptr->chname,
- (IsServer(state->sptr) ? state->sptr->name :
- state->sptr->user->server->name));
+ sendto_opmask_butone(0, SNO_HACK4, "Deop of +k user on %H by %s",
+ state->chptr,
+ (IsServer(state->sptr) ? cli_name(state->sptr) :
+ cli_name((cli_user(state->sptr))->server)));
else if (MyUser(state->sptr) && state->flags & MODE_PARSE_SET) {
- sendto_one(state->sptr, err_str(ERR_ISCHANSERVICE), me.name,
- state->sptr->name, state->cli_change[i].client->name,
+ send_reply(state->sptr, ERR_ISCHANSERVICE,
+ cli_name(state->cli_change[i].client),
state->chptr->chname);
continue;
}
}
-#ifdef NO_OPER_DEOP_LCHAN
/* don't allow local opers to be deopped on local channels */
if (MyUser(state->sptr) && state->cli_change[i].client != state->sptr &&
- IsOperOnLocalChannel(state->cli_change[i].client,
- state->chptr->chname)) {
- sendto_one(state->sptr, err_str(ERR_ISOPERLCHAN), me.name,
- state->sptr->name, state->cli_change[i].client->name,
+ IsLocalChannel(state->chptr->chname) &&
+ HasPriv(state->cli_change[i].client, PRIV_DEOP_LCHAN)) {
+ send_reply(state->sptr, ERR_ISOPERLCHAN,
+ cli_name(state->cli_change[i].client),
state->chptr->chname);
continue;
}
-#endif
}
/* accumulate the change */
static void
mode_parse_mode(struct ParseState *state, int *flag_p)
{
- if ((state->dir == MODE_ADD && (flag_p[0] & state->chptr->mode.mode)) ||
- (state->dir == MODE_DEL && !(flag_p[0] & state->chptr->mode.mode)))
- return; /* no change */
-
/* If they're not an oper, they can't change modes */
if (state->flags & (MODE_PARSE_NOTOPER | MODE_PARSE_NOTMEMBER)) {
send_notoper(state);
return;
}
- assert(0 != state->mbuf);
-
- modebuf_mode(state->mbuf, state->dir | flag_p[0]);
-
- /* make +p and +s mutually exclusive */
- if (state->dir == MODE_ADD && flag_p[0] & (MODE_SECRET | MODE_PRIVATE)) {
- if (flag_p[0] == MODE_SECRET && (state->chptr->mode.mode & MODE_PRIVATE))
- modebuf_mode(state->mbuf, MODE_DEL | MODE_PRIVATE);
- else if (flag_p[0] == MODE_PRIVATE &&
- (state->chptr->mode.mode & MODE_SECRET))
- modebuf_mode(state->mbuf, MODE_DEL | MODE_SECRET);
- }
-
- if (state->flags & MODE_PARSE_SET) { /* set the flags */
- if (state->dir == MODE_ADD) { /* add the mode to the channel */
- state->chptr->mode.mode |= flag_p[0];
+ if (!state->mbuf)
+ return;
- /* make +p and +s mutually exclusive */
- if (state->dir == MODE_ADD && flag_p[0] & (MODE_SECRET | MODE_PRIVATE)) {
- if (flag_p[0] == MODE_PRIVATE)
- state->chptr->mode.mode &= ~MODE_SECRET;
- else
- state->chptr->mode.mode &= ~MODE_PRIVATE;
- }
- } else /* remove the mode from the channel */
- state->chptr->mode.mode &= ~flag_p[0];
+ if (state->dir == MODE_ADD) {
+ state->add |= flag_p[0];
+ state->del &= ~flag_p[0];
+
+ if (flag_p[0] & MODE_SECRET) {
+ state->add &= ~MODE_PRIVATE;
+ state->del |= MODE_PRIVATE;
+ } else if (flag_p[0] & MODE_PRIVATE) {
+ state->add &= ~MODE_SECRET;
+ state->del |= MODE_SECRET;
+ }
+ } else {
+ state->add &= ~flag_p[0];
+ state->del |= flag_p[0];
}
- /* Clear out invite structures if we're removing invites */
- if (state->flags & MODE_PARSE_SET && state->dir == MODE_DEL &&
- flag_p[0] == MODE_INVITEONLY)
- mode_invite_clear(state->chptr);
+ assert(0 == (state->add & state->del));
+ assert((MODE_SECRET | MODE_PRIVATE) !=
+ (state->add & (MODE_SECRET | MODE_PRIVATE)));
}
/*
};
int i;
int *flag_p;
+ unsigned int t_mode;
char *modestr;
struct ParseState state;
state.flags = flags;
state.dir = MODE_ADD;
state.done = 0;
+ state.add = 0;
+ state.del = 0;
state.args_used = 0;
state.max_args = MAXMODEPARAMS;
state.numbans = 0;
if (!flag_p[0]) { /* didn't find it? complain and continue */
if (MyUser(state.sptr))
- sendto_one(state.sptr, err_str(ERR_UNKNOWNMODE), me.name,
- state.sptr->name, *modestr);
+ send_reply(state.sptr, ERR_UNKNOWNMODE, *modestr);
continue;
}
} /* switch (*modestr) { */
} /* for (; *modestr; modestr++) { */
+ if (state.flags & MODE_PARSE_BURST)
+ break; /* don't interpret any more arguments */
+
if (state.parc > 0) { /* process next argument in string */
modestr = state.parv[state.args_used++];
state.parc--;
* the rest of the function finishes building resultant MODEs; if the
* origin isn't a member or an oper, skip it.
*/
- if (state.flags & (MODE_PARSE_NOTOPER | MODE_PARSE_NOTMEMBER))
+ if (!state.mbuf || state.flags & (MODE_PARSE_NOTOPER | MODE_PARSE_NOTMEMBER))
return state.args_used; /* tell our parent how many args we gobbled */
- assert(0 != state.mbuf);
+ t_mode = state.chptr->mode.mode;
+
+ if (state.del & t_mode) { /* delete any modes to be deleted... */
+ modebuf_mode(state.mbuf, MODE_DEL | (state.del & t_mode));
+
+ t_mode &= ~state.del;
+ }
+ if (state.add & ~t_mode) { /* add any modes to be added... */
+ modebuf_mode(state.mbuf, MODE_ADD | (state.add & ~t_mode));
+
+ t_mode |= state.add;
+ }
+
+ if (state.flags & MODE_PARSE_SET) { /* set the channel modes */
+ if ((state.chptr->mode.mode & MODE_INVITEONLY) &&
+ !(t_mode & MODE_INVITEONLY))
+ mode_invite_clear(state.chptr);
+
+ state.chptr->mode.mode = t_mode;
+ }
+
+ if (state.flags & MODE_PARSE_WIPEOUT) {
+ if (state.chptr->mode.limit && !(state.done & DONE_LIMIT))
+ modebuf_mode_uint(state.mbuf, MODE_DEL | MODE_LIMIT,
+ state.chptr->mode.limit);
+ if (*state.chptr->mode.key && !(state.done & DONE_KEY))
+ modebuf_mode_string(state.mbuf, MODE_DEL | MODE_KEY,
+ state.chptr->mode.key, 0);
+ }
if (state.done & DONE_BANCLEAN) /* process bans */
mode_process_bans(&state);
return state.args_used; /* tell our parent how many args we gobbled */
}
+
+/*
+ * Initialize a join buffer
+ */
+void
+joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
+ struct Client *connect, unsigned int type, char *comment,
+ time_t create)
+{
+ int i;
+
+ assert(0 != jbuf);
+ assert(0 != source);
+ assert(0 != connect);
+
+ jbuf->jb_source = source; /* just initialize struct JoinBuf */
+ jbuf->jb_connect = connect;
+ jbuf->jb_type = type;
+ jbuf->jb_comment = comment;
+ jbuf->jb_create = create;
+ jbuf->jb_count = 0;
+ jbuf->jb_strlen = (((type == JOINBUF_TYPE_JOIN ||
+ type == JOINBUF_TYPE_PART ||
+ type == JOINBUF_TYPE_PARTALL) ?
+ STARTJOINLEN : STARTCREATELEN) +
+ (comment ? strlen(comment) + 2 : 0));
+
+ for (i = 0; i < MAXJOINARGS; i++)
+ jbuf->jb_channels[i] = 0;
+}
+
+/*
+ * Add a channel to the join buffer
+ */
+void
+joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan, unsigned int flags)
+{
+ unsigned int len;
+
+ assert(0 != jbuf);
+
+ if (!chan) {
+ if (jbuf->jb_type == JOINBUF_TYPE_JOIN)
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_JOIN, jbuf->jb_connect, "0");
+
+ return;
+ }
+
+ if (jbuf->jb_type == JOINBUF_TYPE_PART ||
+ jbuf->jb_type == JOINBUF_TYPE_PARTALL) {
+ /* Send notification to channel */
+ if (!(flags & CHFL_ZOMBIE))
+ sendcmdto_channel_butserv(jbuf->jb_source, CMD_PART, chan,
+ (flags & CHFL_BANNED || !jbuf->jb_comment) ?
+ ":%H" : "%H :%s", chan, jbuf->jb_comment);
+ else if (MyUser(jbuf->jb_source))
+ sendcmdto_one(jbuf->jb_source, CMD_PART, jbuf->jb_source,
+ (flags & CHFL_BANNED || !jbuf->jb_comment) ?
+ ":%H" : "%H :%s", chan, jbuf->jb_comment);
+ /* XXX: Shouldn't we send a PART here anyway? */
+ /* to users on the channel? Why? From their POV, the user isn't on
+ * the channel anymore anyway. We don't send to servers until below,
+ * when we gang all the channel parts together. Note that this is
+ * exactly the same logic, albeit somewhat more concise, as was in
+ * the original m_part.c */
+
+ if (jbuf->jb_type == JOINBUF_TYPE_PARTALL ||
+ IsLocalChannel(chan->chname)) /* got to remove user here */
+ remove_user_from_channel(jbuf->jb_source, chan);
+ } else {
+ /* Add user to channel */
+ add_user_to_channel(chan, jbuf->jb_source, flags);
+
+ /* send notification to all servers */
+ if (jbuf->jb_type != JOINBUF_TYPE_CREATE && !IsLocalChannel(chan->chname))
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_JOIN, jbuf->jb_connect,
+ "%H %Tu", chan, chan->creationtime);
+
+ /* Send the notification to the channel */
+ sendcmdto_channel_butserv(jbuf->jb_source, CMD_JOIN, chan, ":%H", chan);
+
+ /* send an op, too, if needed */
+ if (!MyUser(jbuf->jb_source) && jbuf->jb_type == JOINBUF_TYPE_CREATE &&
+ !IsModelessChannel(chan->chname))
+ sendcmdto_channel_butserv(jbuf->jb_source, CMD_MODE, chan, "%H +o %C",
+ chan, jbuf->jb_source);
+ }
+
+ if (jbuf->jb_type == JOINBUF_TYPE_PARTALL || IsLocalChannel(chan->chname))
+ return; /* don't send to remote */
+
+ /* figure out if channel name will cause buffer to be overflowed */
+ len = chan ? strlen(chan->chname) + 1 : 2;
+ if (jbuf->jb_strlen + len > BUFSIZE)
+ joinbuf_flush(jbuf);
+
+ /* add channel to list of channels to send and update counts */
+ jbuf->jb_channels[jbuf->jb_count++] = chan;
+ jbuf->jb_strlen += len;
+
+ /* if we've used up all slots, flush */
+ if (jbuf->jb_count >= MAXJOINARGS)
+ joinbuf_flush(jbuf);
+}
+
+/*
+ * Flush the channel list to remote servers
+ */
+int
+joinbuf_flush(struct JoinBuf *jbuf)
+{
+ char chanlist[BUFSIZE];
+ int chanlist_i = 0;
+ int i;
+
+ if (!jbuf->jb_count || jbuf->jb_type == JOINBUF_TYPE_PARTALL ||
+ jbuf->jb_type == JOINBUF_TYPE_JOIN)
+ return 0; /* no joins to process */
+
+ for (i = 0; i < jbuf->jb_count; i++) { /* build channel list */
+ build_string(chanlist, &chanlist_i,
+ jbuf->jb_channels[i] ? jbuf->jb_channels[i]->chname : "0", 0,
+ i == 0 ? '\0' : ',');
+ if (JOINBUF_TYPE_PART == jbuf->jb_type)
+ /* Remove user from channel */
+ remove_user_from_channel(jbuf->jb_source, jbuf->jb_channels[i]);
+
+ jbuf->jb_channels[i] = 0; /* mark slot empty */
+ }
+
+ jbuf->jb_count = 0; /* reset base counters */
+ jbuf->jb_strlen = ((jbuf->jb_type == JOINBUF_TYPE_PART ?
+ STARTJOINLEN : STARTCREATELEN) +
+ (jbuf->jb_comment ? strlen(jbuf->jb_comment) + 2 : 0));
+
+ /* and send the appropriate command */
+ switch (jbuf->jb_type) {
+ case JOINBUF_TYPE_CREATE:
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_CREATE, jbuf->jb_connect,
+ "%s %Tu", chanlist, jbuf->jb_create);
+ break;
+
+ case JOINBUF_TYPE_PART:
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_PART, jbuf->jb_connect,
+ jbuf->jb_comment ? "%s :%s" : "%s", chanlist,
+ jbuf->jb_comment);
+ break;
+ }
+
+ return 0;
+}