/** 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, SKIP_SERVERS. * @param[in] pattern Format string for command arguments. */ void sendcmdto_channel(struct Client *from, const char *cmd, const char *tok, struct Channel *to, struct Client *one, unsigned int skip, const char *pattern, ...) { struct Membership *member; struct VarData vd; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); user_mb = msgq_make(0, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? "%:#C %s @%v" : "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); /* Build buffer to send to servers */ if ((skip & SKIP_SERVERS) || IsLocalChannel(to->chname)) serv_mb = NULL; else { va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, skip & SKIP_NONOPS ? "%C %s @%v" : "%C %s %v", from, tok, &vd); va_end(vd.vd_args); } /* send buffer along! */ bump_sentalong(one); for (member = to->members; member; member = member->next_member) { /* skip duplicates, zombies, and flagged users... */ if (cli_sentalong(member->user) == sentalong_marker || IsZombie(member) || (skip & SKIP_DEAF && IsDeaf(member->user)) || #if defined(DDB) || defined(SERVICES) (skip & SKIP_NONOPS && !IsChanOwner(member) && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOwner(member) && !IsChanOp(member) && !HasVoice(member)) || #else (skip & SKIP_NONOPS && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member)) || #endif (skip & SKIP_COLOUR && !IsStripColour(member->user)) || (skip & SKIP_NOCOLOUR && IsStripColour(member->user)) || (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) || !(serv_mb || MyUser(member->user)) || cli_fd(cli_from(member->user)) < 0) continue; cli_sentalong(member->user) = sentalong_marker; /* pick right buffer to send */ send_buffer(member->user, MyConnect(member->user) ? user_mb : serv_mb, 0); } msgq_clean(user_mb); if (serv_mb) msgq_clean(serv_mb); }
/** Send a server notice to all users with the indicated \a mode except * for \a one. * @param[in] one Client direction to skip (or NULL). * @param[in] mode One mode character. * @param[in] pattern Format string for server notice. * @param[in] vl Argument list for format string. */ void vsendto_mode_butone(struct Client *one, struct Client *from, const char *mode, const char *pattern, va_list vl) { struct VarData vd; struct MsgBuf *mb; struct Client* acptr = 0; vd.vd_format = pattern; va_copy(vd.vd_args, vl); /* send to local users */ mb = msgq_make(0, ":%s " MSG_NOTICE " * :*** Notice -- %v", cli_name(from), &vd); for (acptr = &me; acptr; acptr = cli_prev(acptr)) { if (IsUser(acptr)) { switch (*mode) { case 'O': if (IsLocOp(acptr)) send_buffer(acptr, mb, 0); break; case 'o': if (IsOper(acptr)) send_buffer(acptr, mb, 0); break; default: break; /* ignore, should only happen if incorrectly injected via raw */ } } } msgq_clean(mb); }
/** 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 *from, struct Client *one, unsigned int mask, const char *pattern, va_list vl) { struct VarData vd; struct MsgBuf *mb; int i = 0; /* so that 1 points to opsarray[0] */ struct SLink *opslist; while ((mask >>= 1)) i++; if (!(opslist = opsarray[i])) return; /* * build string; I don't want to bother with client nicknames, so I hope * this is ok... */ vd.vd_format = pattern; va_copy(vd.vd_args, vl); mb = msgq_make(0, ":%s " MSG_NOTICE " * :*** Notice -- %v", cli_name(from), &vd); for (; opslist; opslist = opslist->next) if (opslist->value.cptr != one) send_buffer(opslist->value.cptr, mb, 0); msgq_clean(mb); }
/** Send a (prefixed) command to all local users on a channel with or without * a client capability specified. * @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] withcap CAP_* that the user must have active to receive the message. * @param[in] skipcap CAP_* that the user must not have active to receive the message. * @param[in] pattern Format string for command arguments. */ void sendcmdto_channel_capab_butserv_butone(struct Client *from, const char *cmd, const char *tok, struct Channel *to, struct Client *one, unsigned int skip, int withcap, int skipcap, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; struct Membership *member; vd.vd_format = pattern; /* set up the struct VarData for %v */ va_start(vd.vd_args, pattern); /* build the buffer */ mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); /* send the buffer to each local channel member */ for (member = to->members; member; member = member->next_member) { if (!MyConnect(member->user) || member->user == one || IsZombie(member) || (skip & SKIP_DEAF && IsDeaf(member->user)) || (skip & SKIP_NONOPS && !IsChanOp(member)) || (skip & SKIP_NONHOPS && !IsChanOp(member) && !IsHalfOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !IsHalfOp(member)&& !HasVoice(member)) || ((withcap != CAP_NONE) && !CapActive(member->user, withcap)) || ((skipcap != CAP_NONE) && CapActive(member->user, skipcap))) continue; send_buffer(member->user, mb, 0); } msgq_clean(mb); }
/** 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. */ 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_NONHOPS && !IsChanOp(member) && !IsHalfOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !IsHalfOp(member)&& !HasVoice(member))) continue; cli_sentalong(member->user) = sentalong_marker; send_buffer(member->user, serv_mb, 0); } msgq_clean(serv_mb); }
/** Send a bot command to all local users on a channel. * @param[in] botname Bot sending 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 sendcmdbotto_channel(const char *botname, const char *cmd, const char *tok, struct Channel *to, struct Client *one, unsigned int skip, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; struct Membership *member; vd.vd_format = pattern; /* set up the struct VarData for %v */ va_start(vd.vd_args, pattern); /* build the buffer */ mb = msgq_make(0, ":%s %s %v", botname, cmd, &vd); va_end(vd.vd_args); /* send the buffer to each local channel member */ for (member = to->members; member; member = member->next_member) { if (!MyConnect(member->user) || member->user == one || IsZombie(member) || (skip & SKIP_DEAF && IsDeaf(member->user)) #if defined(DDB) || defined(SERVICES) || (skip & SKIP_NONOPS && !IsChanOwner(member) && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOwner(member) && !IsChanOp(member) && !HasVoice(member))) #else || (skip & SKIP_NONOPS && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member))) #endif continue; send_buffer(member->user, 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(struct Client *from, const char *cmd, const char *tok, struct Client *one, 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); /* canonicalize 'one' pointer */ if (one) one = cli_from(one); /* send it to our downlinks */ for (lp = cli_serv(&me)->down; lp; lp = lp->next) { if (lp->value.cptr == one) continue; send_buffer(lp->value.cptr, mb, 0); } msgq_clean(mb); }
/** * 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 server notice out across the network before sending to all * users subscribing to the indicated \a mask except for \a one. * @param[in] from Client TOK_SNO is sent from. * @param[in] mask One of the SNO_* constants. * @param[in] pattern Format string for server notice. */ void sendto_opmask_butone_global(struct Client *one, unsigned int mask, const char *pattern, ...) { va_list vl; struct VarData vd; struct MsgBuf *mb; struct DLink *lp; va_start(vl, pattern); if (cli_serv(&me) && (lp = cli_serv(&me)->down)) { vd.vd_format = pattern; va_copy(vd.vd_args, vl); mb = msgq_make(&me, "%C " TOK_SNO " %d :%v", &me, mask, &vd); 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); } msgq_clean(mb); } vsendto_opmask_butone(&me, one, mask, pattern, vl); va_end(vl); }
/** 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, struct Client *one, unsigned int skip, const char *pattern, ...) { struct Membership *member; struct VarData vd; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); 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 */ va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd); va_end(vd.vd_args); /* send buffer along! */ bump_sentalong(one); for (member = to->members; member; member = member->next_member) { /* skip one, zombies, and deaf users... */ 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; cli_sentalong(member->user) = sentalong_marker; if (MyConnect(member->user)) /* pick right buffer to send */ send_buffer(member->user, user_mb, 0); else send_buffer(member->user, serv_mb, 0); } msgq_clean(user_mb); msgq_clean(serv_mb); }
/** 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, struct Client *one, unsigned int who, const char *pattern, ...) { struct VarData vd; struct Client *cptr; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); user_mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); /* Build buffer to send to servers */ va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd); va_end(vd.vd_args); /* send buffer along */ bump_sentalong(one); for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) { 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 */ cli_sentalong(cptr) = sentalong_marker; if (MyConnect(cptr)) /* send right buffer */ send_buffer(cptr, user_mb, 0); else send_buffer(cptr, serv_mb, 0); } msgq_clean(user_mb); msgq_clean(serv_mb); }
/** 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, ...) { struct MsgBuf *mb; va_list vl; va_start(vl, pattern); mb = msgq_vmake(to, pattern, vl); va_end(vl); send_buffer(to, mb, 0); msgq_clean(mb); }
/** 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_capab_butone(struct Client *from, const char *cmd, const char *tok, struct Client *one, int withcap, int skipcap, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; struct Membership *chan; struct Membership *member; assert(0 != from); assert(0 != cli_from(from)); assert(0 != pattern); assert(!IsServer(from) && !IsMe(from)); vd.vd_format = pattern; /* set up the struct VarData for %v */ va_start(vd.vd_args, pattern); /* build the buffer */ mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); 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) { 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)) && member->user != one && cli_sentalong(member->user) != sentalong_marker && ((withcap == CAP_NONE) || CapActive(member->user, withcap)) && ((skipcap == CAP_NONE) || !CapActive(member->user, skipcap))) { cli_sentalong(member->user) = sentalong_marker; send_buffer(member->user, mb, 0); } } if (MyConnect(from) && from != one) send_buffer(from, mb, 0); msgq_clean(mb); }
/** Report privileges of \a client to \a to. * @param[in] to Client requesting privilege list. * @param[in] client Client whos privileges should be listed. * @return Zero. */ int client_report_privs(struct Client *to, struct Client *client) { struct MsgBuf *mb; int found1 = 0; int i; mb = msgq_make(to, rpl_str(RPL_PRIVS), cli_name(&me), cli_name(to), cli_name(client)); for (i = 0; privtab[i].name; i++) if (HasPriv(client, privtab[i].priv)) msgq_append(0, mb, "%s%s", found1++ ? " " : "", privtab[i].name); send_buffer(to, mb, 0); /* send response */ msgq_clean(mb); return 0; }
/** Send a bot command to a single client. * @param[in] botname Bot 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 sendcmdbotto_one(const char *botname, const char *cmd, const char *tok, struct Client *to, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; 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, ":%s %s %v", botname, cmd, &vd); va_end(vd.vd_args); send_buffer(to, mb, 0); msgq_clean(mb); }
/** * 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; 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, 1); msgq_clean(mb); }
/** Send a server notice to all local users on this server. * @param[in] pattern Format string for server notice. */ void sendto_lusers(const char *pattern, ...) { struct VarData vd; struct Client *cptr; struct MsgBuf *mb; int i; /* Build the message we're going to send... */ vd.vd_format = pattern; va_start(vd.vd_args, pattern); mb = msgq_make(0, ":%s " MSG_NOTICE " * :*** Notice -- %v", cli_name(&me), &vd); va_end(vd.vd_args); /* send it along */ for (i = 0; i <= HighestFd; i++) { if (!(cptr = LocalClientArray[i]) || !IsUser(cptr)) continue; /* skip empty slots... */ send_buffer(cptr, mb, 1); /* send with high priority */ } msgq_clean(mb); /* clean up after ourselves */ }
/** 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 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; char *prefix=NULL; char *tok=NULL; int his_wallops; int i; vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); 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! */ 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); } msgq_clean(mb); /* Build buffer to send to servers */ va_start(vd.vd_args, pattern); 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, 1); } msgq_clean(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, struct Client *one, unsigned int skip, unsigned char prefix, const char *pattern, ...) { struct Membership *member; struct VarData vd; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; struct Client *service; const char *userfmt; const char *usercmd; vd.vd_format = pattern; /* Build buffer to send to users */ usercmd = cmd; userfmt = "%:#C %s %v"; if (skip & (SKIP_NONOPS | SKIP_NONHOPS | SKIP_NONVOICES)) { usercmd = MSG_NOTICE; if (skip & SKIP_NONVOICES) userfmt = "%:#C %s +%v"; else if (skip & SKIP_NONHOPS) userfmt = "%:#C %s %%%v"; else userfmt = "%:#C %s @%v"; } va_start(vd.vd_args, pattern); user_mb = msgq_make(0, userfmt, from, usercmd, &vd); va_end(vd.vd_args); /* Build buffer to send to servers */ va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd); va_end(vd.vd_args); /* send buffer along! */ bump_sentalong(one); for (member = to->members; member; member = member->next_member) { /* skip one, zombies, and deaf users... */ if (IsZombie(member) || (skip & SKIP_DEAF && IsDeaf(member->user)) || (skip & SKIP_NONOPS && !IsChanOp(member)) || (skip & SKIP_NONHOPS && !IsChanOp(member) && !IsHalfOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !IsHalfOp(member) && !HasVoice(member)) || (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) || (is_silenced(from, member->user, 1)) || cli_fd(cli_from(member->user)) < 0 || cli_sentalong(member->user) == sentalong_marker) continue; cli_sentalong(member->user) = sentalong_marker; if (MyConnect(member->user)) /* pick right buffer to send */ send_buffer(member->user, user_mb, 0); else send_buffer(member->user, serv_mb, 0); } /* Consult service forwarding table. */ if(GlobalForwards[prefix] && (service = FindServer(GlobalForwards[prefix])) && cli_sentalong(service) != sentalong_marker) { cli_sentalong(service) = sentalong_marker; send_buffer(service, serv_mb, 0); } msgq_clean(user_mb); msgq_clean(serv_mb); }
/** 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(struct Client *from, const char *cmd, const char *tok, const char *to, struct Client *one, unsigned int who, const char *pattern, ...) { struct VarData vd; struct irc_in_addr addr; struct Client *cptr; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; unsigned char nbits; vd.vd_format = pattern; /* See if destination looks like an IP mask. */ if (!ipmask_parse(to, &addr, &nbits)) nbits = 255; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); /* TODO-ZOLTAN: Revisar el tema de Globales if (IsUser(from) && IsService(cli_user(from)->server)) */ user_mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd); /* else { char *mask, *msg; mask = (char *)va_arg(vd.vd_args, char *); msg = (char *)va_arg(vd.vd_args, char *); user_mb = msgq_make(0, "%:#C %s :*** Global Message -> (%s): %s", from, cmd, mask, msg); } */ va_end(vd.vd_args); /* Build buffer to send to servers */ va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd); va_end(vd.vd_args); /* send buffer along */ bump_sentalong(one); for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) { if (cli_sentalong(cptr) == sentalong_marker || !IsRegistered(cptr) || IsServer(cptr) || !match_it(from, cptr, to, &addr, nbits, who) || cli_fd(cli_from(cptr)) < 0) continue; /* skip it */ cli_sentalong(cptr) = sentalong_marker; if (MyConnect(cptr)) /* send right buffer */ send_buffer(cptr, user_mb, 0); else send_buffer(cptr, serv_mb, 0); } msgq_clean(user_mb); msgq_clean(serv_mb); }