X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fsend.c;h=b9309b85337fb67f7a5a41f3459c759721648ea3;hb=7fbfc390d32f9acc3192d011b813f66f35370faa;hp=bf8335dc7b26ab951f409a54c22be4b9369947d6;hpb=fda30451cac5936729c683d38a700f4928812c6f;p=ircu2.10.12-pk.git diff --git a/ircd/send.c b/ircd/send.c index bf8335d..b9309b8 100644 --- a/ircd/send.c +++ b/ircd/send.c @@ -16,8 +16,10 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ + */ +/** @file + * @brief Send messages to certain targets. + * @version $Id$ */ #include "config.h" @@ -26,37 +28,40 @@ #include "class.h" #include "client.h" #include "ircd.h" +#include "ircd_features.h" +#include "ircd_log.h" #include "ircd_snprintf.h" #include "ircd_string.h" #include "list.h" #include "match.h" #include "msg.h" #include "numnicks.h" +#include "parse.h" #include "s_bsd.h" #include "s_debug.h" #include "s_misc.h" #include "s_user.h" -#include "sprintf_irc.h" #include "struct.h" #include "sys.h" -#include +/* #include -- Now using assert in ircd_log.h */ #include #include - -static int sentalong[MAXCONNECTIONS]; +/** Last used marker value. */ static int sentalong_marker; +/** Array of users with the corresponding server notice mask bit set. */ struct SLink *opsarray[32]; /* don't use highest bit unless you change atoi to strtoul in sendto_op_mask() */ -static struct Connection *send_queues = 0; +/** Linked list of all connections with data queued to send. */ +static struct Connection *send_queues; /* * dead_link * * An error has been detected. The link *must* be closed, * but *cannot* call ExitClient (m_bye) from here. - * Instead, mark it with FLAGS_DEADSOCKET. This should + * Instead, mark it with FLAG_DEADSOCKET. This should * generate ExitClient from the main loop. * * If 'notice' is not NULL, it is assumed to be a format @@ -67,10 +72,15 @@ static struct Connection *send_queues = 0; * Also, the notice is skipped for "uninteresting" cases, * like Persons and yet unknown connections... */ - +/** Mark a client as dead, even if they are not the current message source. + * This is done by setting the DEADSOCKET flag on the user and letting the + * main loop perform the actual exit logic. + * @param[in,out] to Client being killed. + * @param[in] notice Message for local opers. + */ static void dead_link(struct Client *to, char *notice) { - cli_flags(to) |= FLAGS_DEADSOCKET; + SetFlag(to, FLAG_DEADSOCKET); /* * If because of BUFFERPOOL problem then clean dbuf's now so that * notices don't hurt operators below. @@ -84,17 +94,49 @@ static void dead_link(struct Client *to, char *notice) */ ircd_strncpy(cli_info(to), notice, REALLEN); - if (!IsUser(to) && !IsUnknown(to) && !(cli_flags(to) & FLAGS_CLOSING)) + if (!IsUser(to) && !IsUnknown(to) && !HasFlag(to, FLAG_CLOSING)) sendto_opmask_butone(0, SNO_OLDSNO, "%s for %s", cli_info(to), cli_name(to)); Debug((DEBUG_ERROR, cli_info(to))); } +/** Test whether we can send to a client. + * @param[in] to Client we want to send to. + * @return Non-zero if we can send to the client. + */ static int can_send(struct Client* to) { assert(0 != to); return (IsDead(to) || IsMe(to) || -1 == cli_fd(to)) ? 0 : 1; } +/** Close the connection with the highest sendq. + * This should be called when we need to free buffer memory. + * @param[in] servers_too If non-zero, consider killing servers, too. + */ +void +kill_highest_sendq(int servers_too) +{ + int i; + unsigned int highest_sendq = 0; + struct Client *highest_client = 0; + + for (i = HighestFd; i >= 0; i--) + { + if (!LocalClientArray[i] || (!servers_too && cli_serv(LocalClientArray[i]))) + continue; /* skip servers */ + + /* If this sendq is higher than one we last saw, remember it */ + if (MsgQLength(&(cli_sendQ(LocalClientArray[i]))) > highest_sendq) + { + highest_client = LocalClientArray[i]; + highest_sendq = MsgQLength(&(cli_sendQ(highest_client))); + } + } + + if (highest_client) + dead_link(highest_client, "Buffer allocation error"); +} + /* * flush_connections * @@ -105,9 +147,15 @@ static int can_send(struct Client* to) * client and try to send it. if we cant send it, it goes into the sendQ * -avalon */ +/** Flush data queued for one or all connections. + * @param[in] cptr Client to flush (if NULL, do all). + */ void flush_connections(struct Client* cptr) { + struct SSLConnection *ssl = cli_connect(cptr)->con_ssl; if (cptr) { + if(ssl) + ssl_connection_flush(ssl); send_queued(cptr); } else { @@ -116,6 +164,7 @@ void flush_connections(struct Client* cptr) assert(0 < MsgQLength(&(con_sendQ(con)))); send_queued(con_client(con)); } + ssl_connection_flush(NULL); } } @@ -126,6 +175,9 @@ void flush_connections(struct Client* cptr) * when there is a chance that some output would be possible. This * attempts to empty the send queue as far as possible... */ +/** Attempt to send data queued for a client. + * @param[in] to Client to send data to. + */ void send_queued(struct Client *to) { assert(0 != to); @@ -160,6 +212,11 @@ void send_queued(struct Client *to) update_write(to); } +/** Try to send a buffer to a client, queueing it if needed. + * @param[in,out] to Client to send message to. + * @param[in] buf Message to send. + * @param[in] prio If non-zero, send as high priority. + */ void send_buffer(struct Client* to, struct MsgBuf* buf, int prio) { assert(0 != to); @@ -215,21 +272,29 @@ void send_buffer(struct Client* to, struct MsgBuf* buf, int prio) * addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de) */ -static int match_it(struct Client *one, const char *mask, int what) +/** Check whether a client matches a target mask. + * @param[in] from Client trying to send a message (ignored). + * @param[in] one Client being considered as a target. + * @param[in] mask Mask for matching against. + * @param[in] what Type of match (either MATCH_HOST or MATCH_SERVER). + * @return Non-zero if \a one matches, zero if not. + */ +static int match_it(struct Client *from, struct Client *one, const char *mask, int what) { switch (what) { case MATCH_HOST: - return (match(mask, cli_user(one)->host) == 0); + return (match(mask, cli_user(one)->host) == 0 || + (HasHiddenHost(one) && match(mask, cli_user(one)->realhost) == 0)); case MATCH_SERVER: default: return (match(mask, cli_name(cli_user(one)->server)) == 0); } } -/* - * Send a raw command to a single client; use *ONLY* if you absolutely - * must send a command without a prefix. +/** Send an unprefixed line to a client. + * @param[in] to Client receiving message. + * @param[in] pattern Format string of message. */ void sendrawto_one(struct Client *to, const char *pattern, ...) { @@ -245,23 +310,44 @@ void sendrawto_one(struct Client *to, const char *pattern, ...) msgq_clean(mb); } -/* - * Send a (prefixed) command to a single client; select which of - * to use depending on if to is a server or not. is the - * originator of the command. +/** Send a (prefixed) command to a single client. + * @param[in] from Client sending the command. + * @param[in] cmd Long name of command (used if \a to is a user). + * @param[in] tok Short name of command (used if \a to is a server). + * @param[in] to Destination of command. + * @param[in] pattern Format string for command arguments. */ void sendcmdto_one(struct Client *from, const char *cmd, const char *tok, struct Client *to, const char *pattern, ...) { - va_list vl; + struct VarData vd; + struct MsgBuf *mb; - va_start(vl, pattern); - vsendcmdto_one(from, cmd, tok, to, pattern, vl); - va_end(vl); + to = cli_from(to); + + vd.vd_format = pattern; /* set up the struct VarData for %v */ + va_start(vd.vd_args, pattern); + + mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd, + &vd); + + va_end(vd.vd_args); + + send_buffer(to, mb, 0); + + msgq_clean(mb); } -void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok, - struct Client *to, const char *pattern, va_list vl) +/** + * Send a (prefixed) command to a single client in the priority queue. + * @param[in] from Client sending the command. + * @param[in] cmd Long name of command (used if \a to is a user). + * @param[in] tok Short name of command (used if \a to is a server). + * @param[in] to Destination of command. + * @param[in] pattern Format string for command arguments. + */ +void sendcmdto_prio_one(struct Client *from, const char *cmd, const char *tok, + struct Client *to, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; @@ -269,19 +355,66 @@ void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok, to = cli_from(to); vd.vd_format = pattern; /* set up the struct VarData for %v */ - vd.vd_args = vl; + va_start(vd.vd_args, pattern); mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd, &vd); - send_buffer(to, mb, 0); + va_end(vd.vd_args); + + send_buffer(to, mb, 1); msgq_clean(mb); } -/* - * Send a (prefixed) command to all servers but one, using tok; cmd - * is ignored in this particular function. +/** + * Send a (prefixed) command to all servers matching or not matching a + * flag but one. + * @param[in] from Client sending the command. + * @param[in] cmd Long name of command (ignored). + * @param[in] tok Short name of command. + * @param[in] one Client direction to skip (or NULL). + * @param[in] require Only send to servers with this Flag bit set. + * @param[in] forbid Do not send to servers with this Flag bit set. + * @param[in] pattern Format string for command arguments. + */ +void sendcmdto_flag_serv_butone(struct Client *from, const char *cmd, + const char *tok, struct Client *one, + int require, int forbid, + const char *pattern, ...) +{ + struct VarData vd; + struct MsgBuf *mb; + struct DLink *lp; + + vd.vd_format = pattern; /* set up the struct VarData for %v */ + va_start(vd.vd_args, pattern); + + /* use token */ + mb = msgq_make(&me, "%C %s %v", from, tok, &vd); + va_end(vd.vd_args); + + /* send it to our downlinks */ + for (lp = cli_serv(&me)->down; lp; lp = lp->next) { + if (one && lp->value.cptr == cli_from(one)) + continue; + if ((require < FLAG_LAST_FLAG) && !HasFlag(lp->value.cptr, require)) + continue; + if ((forbid < FLAG_LAST_FLAG) && HasFlag(lp->value.cptr, forbid)) + continue; + send_buffer(lp->value.cptr, mb, 0); + } + + msgq_clean(mb); +} + +/** + * Send a (prefixed) command to all servers but one. + * @param[in] from Client sending the command. + * @param[in] cmd Long name of command (ignored). + * @param[in] tok Short name of command. + * @param[in] one Client direction to skip (or NULL). + * @param[in] pattern Format string for command arguments. */ void sendcmdto_serv_butone(struct Client *from, const char *cmd, const char *tok, struct Client *one, @@ -308,25 +441,38 @@ void sendcmdto_serv_butone(struct Client *from, const char *cmd, msgq_clean(mb); } -/* - * Send a (prefix) command originating from to all channels - * is locally on. must be a user. is ignored in - * this function. +/** Safely increment the sentalong marker. + * This increments the sentalong marker. Since new connections will + * have con_sentalong() == 0, and to avoid confusion when the counter + * wraps, we reset all sentalong markers to zero when the sentalong + * marker hits zero. + * @param[in,out] one Client to mark with new sentalong marker (if any). */ -/* XXX sentalong_marker used XXX - * - * There is not an easy way to revoke the need for sentalong_marker - * from this function. Thoughts and ideas would be welcome... -Kev - * - * One possibility would be to internalize the sentalong array; that - * could be prohibitively big, though. We could get around that by - * making one that's the number of connected servers or something... - * or perhaps by adding a special flag to the servers we've sent a - * message to, and then a final loop through the connected servers - * to delete the flag. -Kev +static void +bump_sentalong(struct Client *one) +{ + if (!++sentalong_marker) + { + int ii; + for (ii = 0; ii < HighestFd; ++ii) + if (LocalClientArray[ii]) + cli_sentalong(LocalClientArray[ii]) = 0; + ++sentalong_marker; + } + if (one) + cli_sentalong(one) = sentalong_marker; +} + +/** Send a (prefixed) command to all channels that \a from is on. + * @param[in] from Client originating the command. + * @param[in] cmd Long name of command. + * @param[in] tok Short name of command. + * @param[in] one Client direction to skip (or NULL). + * @param[in] pattern Format string for command arguments. */ -void sendcmdto_common_channels(struct Client *from, const char *cmd, - const char *tok, const char *pattern, ...) +void sendcmdto_common_channels_butone(struct Client *from, const char *cmd, + const char *tok, struct Client *one, + const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; @@ -346,34 +492,43 @@ void sendcmdto_common_channels(struct Client *from, const char *cmd, mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); - sentalong_marker++; - if (-1 < cli_fd(cli_from(from))) - sentalong[cli_fd(cli_from(from))] = sentalong_marker; + bump_sentalong(from); /* * loop through from's channels, and the members on their channels */ - for (chan = cli_user(from)->channel; chan; chan = chan->next_channel) + for (chan = cli_user(from)->channel; chan; chan = chan->next_channel) { + if (IsZombie(chan) || IsDelayedJoin(chan)) + continue; for (member = chan->channel->members; member; member = member->next_member) - if (MyConnect(member->user) && -1 < cli_fd(cli_from(member->user)) && - sentalong[cli_fd(cli_from(member->user))] != sentalong_marker) { - sentalong[cli_fd(cli_from(member->user))] = sentalong_marker; + if (MyConnect(member->user) + && -1 < cli_fd(cli_from(member->user)) + && member->user != one + && cli_sentalong(member->user) != sentalong_marker) { + cli_sentalong(member->user) = sentalong_marker; send_buffer(member->user, mb, 0); } + } - if (MyConnect(from)) + if (MyConnect(from) && from != one) send_buffer(from, mb, 0); msgq_clean(mb); } -/* - * Send a (prefixed) command to all local users on the channel specified - * by ; is ignored by this function +/** Send a (prefixed) command to all local users on a channel. + * @param[in] from Client originating the command. + * @param[in] cmd Long name of command. + * @param[in] tok Short name of command (ignored). + * @param[in] to Destination channel. + * @param[in] one Client direction to skip (or NULL). + * @param[in] skip Bitmask of SKIP_DEAF, SKIP_NONOPS, SKIP_NONVOICES indicating which clients to skip. + * @param[in] pattern Format string for command arguments. */ -void sendcmdto_channel_butserv(struct Client *from, const char *cmd, - const char *tok, struct Channel *to, - const char *pattern, ...) +void sendcmdto_channel_butserv_butone(struct Client *from, const char *cmd, + const char *tok, struct Channel *to, + struct Client *one, unsigned int skip, + const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; @@ -388,29 +543,72 @@ void sendcmdto_channel_butserv(struct Client *from, const char *cmd, /* send the buffer to each local channel member */ for (member = to->members; member; member = member->next_member) { - if (MyConnect(member->user) && !IsZombie(member)) + if (!MyConnect(member->user) + || member->user == one + || IsZombie(member) + || (skip & SKIP_DEAF && IsDeaf(member->user)) + || (skip & SKIP_NONOPS && !IsChanOp(member)) + || (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member))) + continue; send_buffer(member->user, mb, 0); } msgq_clean(mb); } -/* - * Send a (prefixed) command to all users on this channel, including - * remote users; users to skip may be specified by setting appropriate - * flags in the argument. will also be skipped. +/** Send a (prefixed) command to all servers with users on \a to. + * Skip \a from and \a one plus those indicated in \a skip. + * @param[in] from Client originating the command. + * @param[in] cmd Long name of command (ignored). + * @param[in] tok Short name of command. + * @param[in] to Destination channel. + * @param[in] one Client direction to skip (or NULL). + * @param[in] skip Bitmask of SKIP_NONOPS and SKIP_NONVOICES indicating which clients to skip. + * @param[in] pattern Format string for command arguments. */ -/* XXX sentalong_marker used XXX - * - * We can drop sentalong_marker from this function by adding a field to - * channels and to connections; what we do is make a user's connection - * a "member" of the channel by adding it to the new list, and we use - * the struct Membership status as a reference count. Then, to implement - * this function, we just walk the list of connections. Unfortunately, - * this doesn't account for sending only to channel ops, or for not - * sending to +d users; we could account for that by splitting those - * counts out, but that would imply adding two more fields (at least) to - * the struct Membership... -Kev +void sendcmdto_channel_servers_butone(struct Client *from, const char *cmd, + const char *tok, struct Channel *to, + struct Client *one, unsigned int skip, + const char *pattern, ...) +{ + struct VarData vd; + struct MsgBuf *serv_mb; + struct Membership *member; + + /* build the buffer */ + vd.vd_format = pattern; + va_start(vd.vd_args, pattern); + serv_mb = msgq_make(&me, "%:#C %s %v", from, tok, &vd); + va_end(vd.vd_args); + + /* send the buffer to each server */ + bump_sentalong(one); + cli_sentalong(from) = sentalong_marker; + for (member = to->members; member; member = member->next_member) { + if (MyConnect(member->user) + || IsZombie(member) + || cli_fd(cli_from(member->user)) < 0 + || cli_sentalong(member->user) == sentalong_marker + || (skip & SKIP_NONOPS && !IsChanOp(member)) + || (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member))) + continue; + cli_sentalong(member->user) = sentalong_marker; + send_buffer(member->user, serv_mb, 0); + } + msgq_clean(serv_mb); +} + + +/** Send a (prefixed) command to all users on this channel, except for + * \a one and those matching \a skip. + * @warning \a pattern must not contain %v. + * @param[in] from Client originating the command. + * @param[in] cmd Long name of command. + * @param[in] tok Short name of command. + * @param[in] to Destination channel. + * @param[in] one Client direction to skip (or NULL). + * @param[in] skip Bitmask of SKIP_NONOPS, SKIP_NONVOICES, SKIP_DEAF, SKIP_BURST. + * @param[in] pattern Format string for command arguments. */ void sendcmdto_channel_butone(struct Client *from, const char *cmd, const char *tok, struct Channel *to, @@ -426,8 +624,8 @@ void sendcmdto_channel_butone(struct Client *from, const char *cmd, /* Build buffer to send to users */ va_start(vd.vd_args, pattern); - user_mb = msgq_make(0, skip & SKIP_NONOPS ? "%:#C %s @%v" : "%:#C %s %v", - from, skip & SKIP_NONOPS ? MSG_NOTICE : cmd, &vd); + user_mb = msgq_make(0, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? "%:#C %s @%v" : "%:#C %s %v", + from, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? MSG_NOTICE : cmd, &vd); va_end(vd.vd_args); /* Build buffer to send to servers */ @@ -436,17 +634,18 @@ void sendcmdto_channel_butone(struct Client *from, const char *cmd, va_end(vd.vd_args); /* send buffer along! */ - sentalong_marker++; + bump_sentalong(one); for (member = to->members; member; member = member->next_member) { /* skip one, zombies, and deaf users... */ - if (cli_from(member->user) == one || IsZombie(member) || - (skip & SKIP_DEAF && IsDeaf(member->user)) || - (skip & SKIP_NONOPS && !IsChanOp(member)) || - (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) || - cli_fd(cli_from(member->user)) < 0 || - sentalong[cli_fd(cli_from(member->user))] == sentalong_marker) + if (IsZombie(member) || + (skip & SKIP_DEAF && IsDeaf(member->user)) || + (skip & SKIP_NONOPS && !IsChanOp(member)) || + (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member)) || + (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) || + cli_fd(cli_from(member->user)) < 0 || + cli_sentalong(member->user) == sentalong_marker) continue; - sentalong[cli_fd(cli_from(member->user))] = sentalong_marker; + cli_sentalong(member->user) = sentalong_marker; if (MyConnect(member->user)) /* pick right buffer to send */ send_buffer(member->user, user_mb, 0); @@ -458,37 +657,58 @@ void sendcmdto_channel_butone(struct Client *from, const char *cmd, msgq_clean(serv_mb); } -/* - * Send a (prefixed) command to all users except that have - * set. +/** Send a (prefixed) WALL of type \a type to all users except \a one. + * @warning \a pattern must not contain %v. + * @param[in] from Source of the command. + * @param[in] type One of WALL_DESYNCH, WALL_WALLOPS or WALL_WALLUSERS. + * @param[in] one Client direction to skip (or NULL). + * @param[in] pattern Format string for command arguments. */ -void sendcmdto_flag_butone(struct Client *from, const char *cmd, - const char *tok, struct Client *one, - unsigned int flag, const char *pattern, ...) +void sendwallto_group_butone(struct Client *from, int type, struct Client *one, + const char *pattern, ...) { struct VarData vd; struct Client *cptr; struct MsgBuf *mb; struct DLink *lp; - unsigned int oper_fl = 0; + char *prefix=NULL; + char *tok=NULL; + int his_wallops; int i; - if (flag & FLAGS_OPER) { - flag &= ~FLAGS_OPER; - oper_fl++; - } - vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); - mb = msgq_make(0, "%:#C " MSG_WALLOPS " %v", from, &vd); + switch (type) { + case WALL_DESYNCH: + prefix=""; + tok=TOK_DESYNCH; + break; + case WALL_WALLOPS: + prefix="* "; + tok=TOK_WALLOPS; + break; + case WALL_WALLUSERS: + prefix="$ "; + tok=TOK_WALLUSERS; + break; + default: + assert(0); + } + mb = msgq_make(0, "%:#C " MSG_WALLOPS " :%s%v", from, prefix,&vd); va_end(vd.vd_args); /* send buffer along! */ - for (i = 0; i <= HighestFd; i++) { - if (!(cptr = LocalClientArray[i]) || !(cli_flags(cptr) & flag) || - (oper_fl && !IsAnOper(cptr)) || cli_fd(cli_from(cptr)) < 0) + his_wallops = feature_bool(FEAT_HIS_WALLOPS); + for (i = 0; i <= HighestFd; i++) + { + if (!(cptr = LocalClientArray[i]) || + (cli_fd(cli_from(cptr)) < 0) || + (type == WALL_DESYNCH && !SendDebug(cptr)) || + (type == WALL_WALLOPS && + (!SendWallops(cptr) || (his_wallops && !IsAnOper(cptr)))) || + (type == WALL_WALLUSERS && !SendWallops(cptr))) continue; /* skip it */ send_buffer(cptr, mb, 1); } @@ -497,36 +717,28 @@ void sendcmdto_flag_butone(struct Client *from, const char *cmd, /* Build buffer to send to servers */ va_start(vd.vd_args, pattern); - mb = msgq_make(&me, "%C %s %v", from, tok, &vd); + mb = msgq_make(&me, "%C %s :%v", from, tok, &vd); va_end(vd.vd_args); /* send buffer along! */ for (lp = cli_serv(&me)->down; lp; lp = lp->next) { if (one && lp->value.cptr == cli_from(one)) continue; - send_buffer(lp->value.cptr, mb, 0); + send_buffer(lp->value.cptr, mb, 1); } msgq_clean(mb); } -/* - * Send a (prefixed) command to all users who match , under control - * of - */ -/* XXX sentalong_marker used XXX - * - * This is also a difficult one to solve. The basic approach would be - * to walk the client list of each connected server until we find a - * match--but then, we also have to walk the client list of all the - * servers behind that one. We could implement this recursively--or we - * could add (yet another) field to the connection struct that would be - * a linked list of clients introduced through that link, and just walk - * that, making this into an iterative implementation. Unfortunately, - * we probably would not be able to use tail recursion for the recursive - * solution, so a deep network could exhaust our stack space; therefore - * I favor the extra linked list, even though that increases the - * complexity of the database. -Kev +/** Send a (prefixed) command to all users matching \a to as \a who. + * @warning \a pattern must not contain %v. + * @param[in] from Source of the command. + * @param[in] cmd Long name of command. + * @param[in] tok Short name of command. + * @param[in] to Destination host/server mask. + * @param[in] one Client direction to skip (or NULL). + * @param[in] who Type of match for \a to (either MATCH_HOST or MATCH_SERVER). + * @param[in] pattern Format string for command arguments. */ void sendcmdto_match_butone(struct Client *from, const char *cmd, const char *tok, const char *to, @@ -551,13 +763,13 @@ void sendcmdto_match_butone(struct Client *from, const char *cmd, va_end(vd.vd_args); /* send buffer along */ - sentalong_marker++; + bump_sentalong(one); for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) { - if (cli_from(cptr) == one || IsServer(cptr) || IsMe(cptr) || - !match_it(cptr, to, who) || cli_fd(cli_from(cptr)) < 0 || - sentalong[cli_fd(cli_from(cptr))] == sentalong_marker) + if (!IsRegistered(cptr) || IsServer(cptr) || cli_fd(cli_from(cptr)) < 0 || + cli_sentalong(cptr) == sentalong_marker || + !match_it(from, cptr, to, who)) continue; /* skip it */ - sentalong[cli_fd(cli_from(cptr))] = sentalong_marker; + cli_sentalong(cptr) = sentalong_marker; if (MyConnect(cptr)) /* send right buffer */ send_buffer(cptr, user_mb, 0); @@ -569,9 +781,11 @@ void sendcmdto_match_butone(struct Client *from, const char *cmd, msgq_clean(serv_mb); } -/* - * Send a server notice to all users subscribing to the indicated - * except for +/** Send a server notice to all users subscribing to the indicated \a + * mask except for \a one. + * @param[in] one Client direction to skip (or NULL). + * @param[in] mask One of the SNO_* constants. + * @param[in] pattern Format string for server notice. */ void sendto_opmask_butone(struct Client *one, unsigned int mask, const char *pattern, ...) @@ -583,8 +797,35 @@ void sendto_opmask_butone(struct Client *one, unsigned int mask, va_end(vl); } -/* - * Same as above, except called with a variable argument list +/** Send a server notice to all users subscribing to the indicated \a + * mask except for \a one, rate-limited to once per 30 seconds. + * @param[in] one Client direction to skip (or NULL). + * @param[in] mask One of the SNO_* constants. + * @param[in,out] rate Pointer to the last time the message was sent. + * @param[in] pattern Format string for server notice. + */ +void sendto_opmask_butone_ratelimited(struct Client *one, unsigned int mask, + time_t *rate, const char *pattern, ...) +{ + va_list vl; + + if ((CurrentTime - *rate) < 30) + return; + else + *rate = CurrentTime; + + va_start(vl, pattern); + vsendto_opmask_butone(one, mask, pattern, vl); + va_end(vl); +} + + +/** Send a server notice to all users subscribing to the indicated \a + * mask except for \a one. + * @param[in] one Client direction to skip (or NULL). + * @param[in] mask One of the SNO_* constants. + * @param[in] pattern Format string for server notice. + * @param[in] vl Argument list for format string. */ void vsendto_opmask_butone(struct Client *one, unsigned int mask, const char *pattern, va_list vl) @@ -605,12 +846,13 @@ void vsendto_opmask_butone(struct Client *one, unsigned int mask, * this is ok... */ vd.vd_format = pattern; - vd.vd_args = vl; + va_copy(vd.vd_args, vl); mb = msgq_make(0, ":%s " MSG_NOTICE " * :*** Notice -- %v", cli_name(&me), &vd); for (; opslist; opslist = opslist->next) - send_buffer(opslist->value.cptr, mb, 0); + if (opslist->value.cptr != one) + send_buffer(opslist->value.cptr, mb, 0); msgq_clean(mb); }