2 * IRC - Internet Relay Chat, common/send.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "ircd_snprintf.h"
28 #include "ircd_string.h"
37 #include "sprintf_irc.h"
47 static int sentalong[MAXCONNECTIONS];
48 static int sentalong_marker;
49 struct SLink *opsarray[32]; /* don't use highest bit unless you change
50 atoi to strtoul in sendto_op_mask() */
59 * An error has been detected. The link *must* be closed,
60 * but *cannot* call ExitClient (m_bye) from here.
61 * Instead, mark it with FLAGS_DEADSOCKET. This should
62 * generate ExitClient from the main loop.
64 * If 'notice' is not NULL, it is assumed to be a format
65 * for a message to local opers. It can contain only one
66 * '%s', which will be replaced by the sockhost field of
69 * Also, the notice is skipped for "uninteresting" cases,
70 * like Persons and yet unknown connections...
73 static void dead_link(struct Client *to, char *notice)
75 to->flags |= FLAGS_DEADSOCKET;
77 * If because of BUFFERPOOL problem then clean dbuf's now so that
78 * notices don't hurt operators below.
80 DBufClear(&to->recvQ);
81 DBufClear(&to->sendQ);
84 * Keep a copy of the last comment, for later use...
86 ircd_strncpy(to->info, notice, REALLEN);
88 if (!IsUser(to) && !IsUnknown(to) && !(to->flags & FLAGS_CLOSING))
89 sendto_ops("%s for %s", to->info, to->name);
90 Debug((DEBUG_ERROR, to->info));
93 static int can_send(struct Client* to)
96 return (IsDead(to) || IsMe(to) || -1 == to->fd) ? 0 : 1;
102 * Used to empty all output buffers for all connections. Should only
103 * be called once per scan of connections. There should be a select in
104 * here perhaps but that means either forcing a timeout or doing a poll.
105 * When flushing, all we do is empty the obuffer array for each local
106 * client and try to send it. if we cant send it, it goes into the sendQ
109 void flush_connections(struct Client* cptr)
116 for (i = HighestFd; i >= 0; i--) {
117 if ((cptr = LocalClientArray[i]))
124 * flush_sendq_except - run through local client array and flush
125 * the sendq for each client, if the address of the client sendq
126 * is the same as the one specified, it is skipped. This is used
127 * by dbuf_put to try to get some more memory before bailing and
128 * causing the client to be disconnected.
130 void flush_sendq_except(const struct DBuf* one)
134 for (i = HighestFd; i >= 0; i--) {
135 if ( (cptr = LocalClientArray[i]) && one != &cptr->sendQ)
143 * This function is called from the main select-loop (or whatever)
144 * when there is a chance that some output would be possible. This
145 * attempts to empty the send queue as far as possible...
147 void send_queued(struct Client *to)
150 assert(0 != to->local);
152 if (IsBlocked(to) || !can_send(to))
153 return; /* Don't bother */
155 while (DBufLength(&to->sendQ) > 0) {
157 const char* msg = dbuf_map(&to->sendQ, &len);
159 if ((len = deliver_it(to, msg, len))) {
160 dbuf_delete(&to->sendQ, len);
161 to->lastsq = DBufLength(&to->sendQ) / 1024;
168 sprintf(tmp,"Write error: %s",(strerror(to->error)) ? (strerror(to->error)) : "Unknown error" );
177 * send message to single client
179 /* See sendcmdto_one, below */
180 void sendto_one(struct Client *to, const char* pattern, ...)
183 va_start(vl, pattern);
184 vsendto_one(to, pattern, vl);
188 /* See vsendcmdto_one, below */
189 void vsendto_one(struct Client *to, const char* pattern, va_list vl)
191 vsprintf_irc(sendbuf, pattern, vl);
196 static void send_to_god(struct Client* to, const char* buf)
198 if (!sdbflag && !IsUser(to)) {
199 char sbuf2[BUFSIZE + 1];
200 unsigned int len = strlen(buf) - 2; /* Remove "\r\n" */
203 len = IRCD_MIN(len, BUFSIZE);
204 ircd_strncpy(sbuf2, buf, len);
210 sendto_ops("SND:%-8.8s(%.4d): \"%s...%s\"",
211 to->name, len, sbuf2, &sbuf2[len - 200]);
214 sendto_ops("SND:%-8.8s(%.4d): \"%s\"", to->name, len, sbuf2);
220 void send_buffer(struct Client* to, char* buf)
231 * This socket has already been marked as dead
235 if (DBufLength(&to->sendQ) > get_sendq(to)) {
237 sendto_ops("Max SendQ limit exceeded for %s: " SIZE_T_FMT " > " SIZE_T_FMT,
238 to->name, DBufLength(&to->sendQ), get_sendq(to));
239 dead_link(to, "Max sendQ exceeded");
243 Debug((DEBUG_SEND, "Sending [%s] to %s", buf, to->name));
246 if (buf[len - 1] != '\n') {
254 if (0 == dbuf_put(&to->sendQ, buf, len)) {
255 dead_link(to, "Buffer allocation error");
260 send_to_god(to, buf);
263 * Update statistics. The following is slightly incorrect
264 * because it counts messages even if queued, but bytes
265 * only really sent. Queued bytes get updated in SendQueued.
270 * This little bit is to stop the sendQ from growing too large when
271 * there is no need for it to. Thus we call send_queued() every time
272 * 2k has been added to the queue since the last non-fatal write.
273 * Also stops us from deliberately building a large sendQ and then
274 * trying to flood that link with data (possible during the net
275 * relinking done by servers with a large load).
277 if (DBufLength(&to->sendQ) / 1024 > to->lastsq)
281 void sendbufto_one(struct Client* to)
283 send_buffer(to, sendbuf);
286 /* See vsendcmdto_one, below */
287 static void vsendto_prefix_one(struct Client *to, struct Client *from,
288 const char* pattern, va_list vl)
290 if (to && from && MyUser(to) && IsUser(from))
292 static char sender[HOSTLEN + NICKLEN + USERLEN + 5];
295 struct User *user = from->user;
297 par = va_arg(vl, char *);
298 strcpy(sender, from->name);
304 strcat(sender, user->username);
306 if (*user->host && !MyConnect(from))
309 strcat(sender, user->host);
314 * Flag is used instead of strchr(sender, '@') for speed and
315 * also since username/nick may have had a '@' in them. -avalon
317 if (!flag && MyConnect(from) && *user->host)
320 strcat(sender, from->sockhost);
323 strcpy(&sendbuf[1], sender);
324 /* Assuming 'pattern' always starts with ":%s ..." */
325 vsprintf_irc(sendbuf + strlen(sendbuf), &pattern[3], vl);
328 vsprintf_irc(sendbuf, pattern, vl);
332 /* See sendcmdto_channel_butone, below */
333 void sendto_channel_butone(struct Client *one, struct Client *from, struct Channel *chptr,
334 const char* pattern, ...)
337 struct Membership* member;
338 struct Client *acptr;
341 va_start(vl, pattern);
344 for (member = chptr->members; member; member = member->next_member)
346 acptr = member->user;
347 /* ...was the one I should skip */
348 if (acptr->from == one || IsZombie(member) || IsDeaf(acptr))
350 if (MyConnect(acptr)) /* (It is always a client) */
351 vsendto_prefix_one(acptr, from, pattern, vl);
352 else if (-1 < (i = acptr->from->fd) && sentalong[i] != sentalong_marker)
354 sentalong[i] = sentalong_marker;
356 * Don't send channel messages to links that are still eating
357 * the net.burst: -- Run 2/1/1997
359 if (!IsBurstOrBurstAck(acptr->from))
360 vsendto_prefix_one(acptr, from, pattern, vl);
366 /* See sendcmdto_channel_butone, below */
367 void sendmsgto_channel_butone(struct Client *one, struct Client *from,
368 struct Channel *chptr, const char *sender,
369 const char *cmd, const char *chname, const char *msg)
372 * Sends a PRIVMSG/NOTICE to all members on a channel but 'one', translating
373 * TOKENS to full messages when sent to local clients. --Gte (12/12/99)
375 struct Membership* member;
376 struct Client *acptr;
384 * Precalculate the buffers we sent to the clients instead of doing an
385 * expensive sprintf() per member that we send to. We still have to
386 * use strcpy() which is evil.
388 if (IsServer(from)) {
389 sprintf(userbuf,":%s %s %s :%s",
390 from->name, ('P' == *cmd) ? MSG_PRIVATE : MSG_NOTICE, chname, msg);
391 sprintf(servbuf,"%s %s %s :%s", NumServ(from), cmd, chname, msg);
394 sprintf(userbuf,":%s!%s@%s %s %s :%s",
395 from->name, from->user->username, from->user->host,
396 ('P' == *cmd) ? MSG_PRIVATE : MSG_NOTICE, chname, msg);
397 sprintf(servbuf,"%s%s %s %s :%s", NumNick(from), cmd, chname, msg);
401 for (member = chptr->members; member; member = member->next_member)
403 acptr = member->user;
404 /* ...was the one I should skip */
405 if (acptr->from == one || IsZombie(member) || IsDeaf(acptr))
407 if (MyConnect(acptr)) { /* (It is always a client) */
409 strcpy(sendbuf,userbuf);
411 sendbufto_one(acptr);
413 else if (-1 < (i = acptr->from->fd) && sentalong[i] != sentalong_marker)
415 sentalong[i] = sentalong_marker;
416 if (!IsBurstOrBurstAck(acptr->from)) {
418 strcpy(sendbuf,servbuf);
420 sendbufto_one(acptr);
422 } /* of if MyConnect() */
423 } /* of for(members) */
426 /* See sendcmdto_channel_butone, below */
427 void sendto_lchanops_butone(struct Client *one, struct Client *from, struct Channel *chptr,
428 const char* pattern, ...)
431 struct Membership* member;
432 struct Client *acptr;
434 va_start(vl, pattern);
436 for (member = chptr->members; member; member = member->next_member)
438 acptr = member->user;
439 /* ...was the one I should skip */
440 if (acptr == one || !IsChanOp(member) || IsZombie(member) || IsDeaf(acptr))
442 if (MyConnect(acptr)) /* (It is always a client) */
443 vsendto_prefix_one(acptr, from, pattern, vl);
449 /* See sendcmdto_channel_butone, below */
450 void sendto_chanopsserv_butone(struct Client *one, struct Client *from, struct Channel *chptr,
451 const char* pattern, ...)
454 struct Membership* member;
455 struct Client *acptr;
464 va_start(vl, pattern);
467 for (member = chptr->members; member; member = member->next_member)
469 acptr = member->user;
470 if (acptr->from == acptr || /* Skip local clients */
472 Protocol(acptr->from) < 10 || /* Skip P09 links */
474 acptr->from == one || /* ...was the one I should skip */
475 !IsChanOp(member) || /* Skip non chanops */
476 IsZombie(member) || IsDeaf(acptr))
478 if (-1 < (i = acptr->from->fd) && sentalong[i] != sentalong_marker)
480 sentalong[i] = sentalong_marker;
481 /* Don't send channel messages to links that are
482 still eating the net.burst: -- Run 2/1/1997 */
483 if (!IsBurstOrBurstAck(acptr->from))
484 vsendto_prefix_one(acptr, from, pattern, vl);
489 /* Send message to all 2.9 servers */
490 /* This is a hack, because it assumes that we know how `vl' is build up */
491 source = va_arg(vl, char *);
492 tp = va_arg(vl, char *); /* Channel */
493 msg = va_arg(vl, char *);
494 for (member = chptr->members; member; member = member->next_member)
496 acptr = member->user;
497 if (acptr->from == acptr || /* Skip local clients */
498 Protocol(acptr->from) > 9 || /* Skip P10 servers */
499 acptr->from == one || /* ...was the one I should skip */
500 !IsChanOp(member) || /* Skip non chanops */
501 IsZombie(member) || IsDeaf(acptr))
503 if (-1 < (i = acptr->from->fd) && sentalong[i] != sentalong_marker)
505 sentalong[i] = sentalong_marker;
506 /* Don't send channel messages to links that are
507 still eating the net.burst: -- Run 2/1/1997 */
508 if (!IsBurstOrBurstAck(acptr->from))
510 struct Membership* other_member;
511 struct Client* acptr2;
514 /* Find all chanops in this direction: */
515 for (other_member = chptr->members; other_member; other_member = other_member->next_member)
517 acptr2 = other_member->user;
518 if (acptr2->from == acptr->from && acptr2->from != one &&
519 IsChanOp(other_member) && !IsZombie(other_member) &&
522 int len = strlen(acptr2->name);
523 if (tp + len + 2 > target + sizeof(target))
525 sendto_prefix_one(acptr, from,
526 ":%s NOTICE %s :%s", source, target, msg);
532 strcpy(tp, acptr2->name);
536 sendto_prefix_one(acptr, from,
537 ":%s NOTICE %s :%s", source, target, msg);
550 * Send a message to all connected servers except the client 'one'.
552 /* See sendcmdto_serv_butone, below */
553 void sendto_serv_butone(struct Client *one, const char* pattern, ...)
558 va_start(vl, pattern);
559 vsprintf_irc(sendbuf, pattern, vl);
562 for (lp = me.serv->down; lp; lp = lp->next)
564 if (one && lp->value.cptr == one->from)
566 sendbufto_one(lp->value.cptr);
572 * sendbufto_serv_butone()
574 * Send prepared sendbuf to all connected servers except the client 'one'
575 * -Ghostwolf 18-May-97
577 void sendbufto_serv_butone(struct Client *one)
581 for (lp = me.serv->down; lp; lp = lp->next)
583 if (one && lp->value.cptr == one->from)
585 sendbufto_one(lp->value.cptr);
591 * sendto_common_channels()
593 * Sends a message to all people (inclusing `acptr') on local server
594 * who are in same channel with client `acptr'.
596 /* See sendcmdto_common_channels, below */
597 void sendto_common_channels(struct Client *acptr, const char* pattern, ...)
600 struct Membership* chan;
601 struct Membership* member;
604 assert(0 != acptr->from);
605 assert(0 != pattern);
607 va_start(vl, pattern);
610 if (-1 < acptr->from->fd)
611 sentalong[acptr->from->fd] = sentalong_marker;
613 * loop through acptr's channels, and the members on their channels
616 for (chan = acptr->user->channel; chan; chan = chan->next_channel) {
617 for (member = chan->channel->members; member; member = member->next_member) {
618 struct Client *cptr = member->user;
620 if (MyConnect(cptr) &&
621 -1 < (i = cptr->fd) && sentalong[i] != sentalong_marker) {
622 sentalong[i] = sentalong_marker;
623 vsendto_prefix_one(cptr, acptr, pattern, vl);
628 if (MyConnect(acptr))
629 vsendto_prefix_one(acptr, acptr, pattern, vl);
635 * sendto_channel_butserv
637 * Send a message to all members of a channel that
638 * are connected to this server.
640 * This contains a subtle bug; after the first call to vsendto_prefix_one()
641 * below, vl is in an indeterminate state, according to ANSI; we'd have to
642 * move va_start() and va_end() into the loop to correct the problem. It's
643 * easier, however, just to use sendcmdto_channel_butserv(), which builds a
644 * buffer and sends that prepared buffer to each channel member.
646 /* See sendcmdto_channel_butserv, below */
647 void sendto_channel_butserv(struct Channel *chptr, struct Client *from, const char* pattern, ...)
650 struct Membership* member;
651 struct Client *acptr;
653 va_start(vl, pattern);
655 for (member = chptr->members; member; member = member->next_member) {
656 acptr = member->user;
657 if (MyConnect(acptr) && !IsZombie(member))
658 vsendto_prefix_one(acptr, from, pattern, vl);
665 * Send a msg to all ppl on servers/hosts that match a specified mask
666 * (used for enhanced PRIVMSGs)
668 * addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
671 static int match_it(struct Client *one, const char *mask, int what)
676 return (match(mask, one->user->host) == 0);
679 return (match(mask, one->user->server->name) == 0);
684 * sendto_match_butone
686 * Send to all clients which match the mask in a way defined on 'what';
687 * either by user hostname or user servername.
689 /* See sendcmdto_match_butone, below */
690 void sendto_match_butone(struct Client *one, struct Client *from,
691 const char *mask, int what, const char* pattern, ...)
695 struct Client *cptr, *acptr;
697 va_start(vl, pattern);
698 for (i = 0; i <= HighestFd; i++)
700 if (!(cptr = LocalClientArray[i]))
701 continue; /* that clients are not mine */
702 if (cptr == one) /* must skip the origin !! */
706 for (acptr = GlobalClientList; acptr; acptr = acptr->next)
707 if (IsUser(acptr) && match_it(acptr, mask, what) && acptr->from == cptr)
709 /* a person on that server matches the mask, so we
710 * send *one* msg to that server ...
714 /* ... but only if there *IS* a matching person */
716 /* my client, does he match ? */
717 else if (!(IsUser(cptr) && match_it(cptr, mask, what)))
719 vsendto_prefix_one(cptr, from, pattern, vl);
729 * Send to *local* ops but one.
731 /* See sendto_opmask_butone, below */
732 void sendto_lops_butone(struct Client* one, const char* pattern, ...)
736 struct Client** clients = me.serv->client_list;
740 assert(0 != clients);
742 sprintf_irc(nbuf, ":%s NOTICE %%s :*** Notice -- ", me.name);
743 va_start(vl, pattern);
744 vsprintf_irc(nbuf + strlen(nbuf), pattern, vl);
747 for (i = 0; i <= me.serv->nn_mask; ++i) {
748 if ((cptr = clients[i]) && cptr != one && SendServNotice(cptr)) {
749 sprintf_irc(sendbuf, nbuf, cptr->name);
758 * Sends message to the list indicated by the bitmask field.
759 * Don't try to send to more than one list! That is not supported.
762 #ifdef OLD_VSENDTO_OP_MASK
763 void vsendto_op_mask(unsigned int mask, const char *pattern, va_list vl)
765 static char fmt[1024];
767 int i = 0; /* so that 1 points to opsarray[0] */
768 struct SLink *opslist;
772 if (!(opslist = opsarray[i]))
775 fmt_target = sprintf_irc(fmt, ":%s NOTICE ", me.name);
778 strcpy(fmt_target, opslist->value.cptr->name);
779 strcat(fmt_target, " :*** Notice -- ");
780 strcat(fmt_target, pattern);
781 vsendto_one(opslist->value.cptr, fmt, vl);
782 opslist = opslist->next;
786 #else /* !OLD_VSENDTO_OP_MASK */
787 void vsendto_op_mask(unsigned int mask, const char *pattern, va_list vl)
789 vsendto_opmask_butone(0, mask, pattern, vl);
791 #endif /* OLD_VSENDTO_OP_MASK */
796 * Send a prepared sendbuf to the list indicated by the bitmask field.
797 * Ghostwolf 16-May-97
799 void sendbufto_op_mask(unsigned int mask)
801 int i = 0; /* so that 1 points to opsarray[0] */
802 struct SLink *opslist;
805 if (!(opslist = opsarray[i]))
809 sendbufto_one(opslist->value.cptr);
810 opslist = opslist->next;
819 * Send to *local* ops only.
821 /* See vsendto_opmask_butone, below */
822 void vsendto_ops(const char *pattern, va_list vl)
829 fmt_target = sprintf_irc(fmt, ":%s NOTICE ", me.name);
831 for (i = 0; i <= HighestFd; i++)
832 if ((cptr = LocalClientArray[i]) && !IsServer(cptr) &&
833 SendServNotice(cptr))
835 strcpy(fmt_target, cptr->name);
836 strcat(fmt_target, " :*** Notice -- ");
837 strcat(fmt_target, pattern);
838 vsendto_one(cptr, fmt, vl);
842 /* See sendto_opmask_butone, below */
843 void sendto_op_mask(unsigned int mask, const char *pattern, ...)
846 va_start(vl, pattern);
847 vsendto_op_mask(mask, pattern, vl);
851 /* See sendto_opmask_butone, below */
852 void sendto_ops(const char *pattern, ...)
855 va_start(vl, pattern);
856 vsendto_op_mask(SNO_OLDSNO, pattern, vl);
863 * Send message to all operators.
864 * one - client not to send message to
865 * from- client which message is from *NEVER* NULL!!
867 void sendto_ops_butone(struct Client *one, struct Client *from, const char *pattern, ...)
873 va_start(vl, pattern);
875 for (cptr = GlobalClientList; cptr; cptr = cptr->next)
877 if (!SendWallops(cptr))
879 i = cptr->from->fd; /* find connection oper is on */
880 if (i < 0 || sentalong[i] == sentalong_marker) /* sent message along it already ? */
882 if (cptr->from == one)
883 continue; /* ...was the one I should skip */
884 sentalong[i] = sentalong_marker;
885 vsendto_prefix_one(cptr->from, from, pattern, vl);
893 * sendto_g_serv_butone
895 * Send message to all remote +g users (server links).
897 * one - server not to send message to.
899 void sendto_g_serv_butone(struct Client *one, const char *pattern, ...)
905 va_start(vl, pattern);
907 vsprintf_irc(sendbuf, pattern, vl);
908 for (cptr = GlobalClientList; cptr; cptr = cptr->next)
910 if (!SendDebug(cptr))
912 i = cptr->from->fd; /* find connection user is on */
913 if (i < 0 || sentalong[i] == sentalong_marker) /* sent message along it already ? */
917 sentalong[i] = sentalong_marker;
918 if (cptr->from == one)
930 * to - destination client
931 * from - client which message is from
933 * NOTE: NEITHER OF THESE SHOULD *EVER* BE NULL!!
936 /* See sendcmdto_one, below */
937 void sendto_prefix_one(struct Client *to, struct Client *from, const char *pattern, ...)
940 va_start(vl, pattern);
941 vsendto_prefix_one(to, from, pattern, vl);
948 * Send to *local* ops only but NOT +s nonopers.
950 /* See sendto_opmask_butone, below */
951 void sendto_realops(const char *pattern, ...)
955 va_start(vl, pattern);
956 vsendto_op_mask(SNO_OLDREALOP, pattern, vl);
963 * Send message to all servers of protocol 'p' and lower.
965 /* See sendcmdto_serv_butone, below */
966 void sendto_lowprot_butone(struct Client *cptr, int p, const char *pattern, ...)
970 va_start(vl, pattern);
971 for (lp = me.serv->down; lp; lp = lp->next)
972 if (lp->value.cptr != cptr && Protocol(lp->value.cptr) <= p)
973 vsendto_one(lp->value.cptr, pattern, vl);
978 * Send message to all servers of protocol 'p' and higher.
980 /* See sendcmdto_serv_butone, below */
981 void sendto_highprot_butone(struct Client *cptr, int p, const char *pattern, ...)
985 va_start(vl, pattern);
986 for (lp = me.serv->down; lp; lp = lp->next)
987 if (lp->value.cptr != cptr && Protocol(lp->value.cptr) >= p)
988 vsendto_one(lp->value.cptr, pattern, vl);
993 * Send a (prefixed) command to a single client; select which of <cmd>
994 * <tok> to use depending on if to is a server or not. <from> is the
995 * originator of the command.
997 void sendcmdto_one(struct Client *from, const char *cmd, const char *tok,
998 struct Client *to, const char *pattern, ...)
1002 va_start(vl, pattern);
1003 vsendcmdto_one(from, cmd, tok, to, pattern, vl);
1007 void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok,
1008 struct Client *to, const char *pattern, va_list vl)
1011 char sndbuf[IRC_BUFSIZE];
1013 vd.vd_format = pattern; /* set up the struct VarData for %v */
1016 if (MyUser(to)) { /* :nick!user@host form; use cmd */
1017 if (IsServer(from) || IsMe(from))
1018 ircd_snprintf(to, sndbuf, sizeof(sndbuf) - 2, ":%s %s %v",
1019 from->name, cmd, &vd);
1021 ircd_snprintf(to, sndbuf, sizeof(sndbuf) - 2, ":%s!%s@%s %s %v",
1022 from->name, from->user->username, from->user->host,
1024 } else /* numeric form; use tok */
1025 ircd_snprintf(to, sndbuf, sizeof(sndbuf) - 2, "%C %s %v", from, tok, &vd);
1027 send_buffer(to, sndbuf);
1031 * Send a (prefixed) command to all servers but one, using tok; cmd
1032 * is ignored in this particular function.
1034 void sendcmdto_serv_butone(struct Client *from, const char *cmd,
1035 const char *tok, struct Client *one,
1036 const char *pattern, ...)
1039 char sndbuf[IRC_BUFSIZE];
1042 vd.vd_format = pattern; /* set up the struct VarData for %v */
1043 va_start(vd.vd_args, pattern);
1046 ircd_snprintf(&me, sndbuf, sizeof(sndbuf) - 2, "%C %s %v", from, tok, &vd);
1049 /* send it to our downlinks */
1050 for (lp = me.serv->down; lp; lp = lp->next) {
1051 if (one && lp->value.cptr == one->from)
1053 send_buffer(lp->value.cptr, sndbuf);
1058 * Send a (prefix) command originating from <from> to all channels
1059 * <from> is locally on. <from> must be a user. <tok> is ignored in
1062 void sendcmdto_common_channels(struct Client *from, const char *cmd,
1063 const char *tok, const char *pattern, ...)
1066 char sndbuf[IRC_BUFSIZE];
1067 struct Membership *chan;
1068 struct Membership *member;
1071 assert(0 != from->from);
1072 assert(0 != pattern);
1073 assert(!IsServer(from) && !IsMe(from));
1075 vd.vd_format = pattern; /* set up the struct VarData for %v */
1077 va_start(vd.vd_args, pattern);
1079 /* build the buffer */
1080 ircd_snprintf(0, sndbuf, sizeof(sndbuf) - 2, ":%s!%s@%s %s %v", from->name,
1081 from->user->username, from->user->host, cmd, &vd);
1085 if (-1 < from->from->fd)
1086 sentalong[from->from->fd] = sentalong_marker;
1088 * loop through from's channels, and the members on their channels
1090 for (chan = from->user->channel; chan; chan = chan->next_channel)
1091 for (member = chan->channel->members; member;
1092 member = member->next_member)
1093 if (MyConnect(member->user) && -1 < from->fd &&
1094 sentalong[member->user->from->fd] != sentalong_marker) {
1095 sentalong[member->user->from->fd] = sentalong_marker;
1096 send_buffer(member->user, sndbuf);
1099 if (MyConnect(from))
1100 send_buffer(from, sndbuf);
1104 * Send a (prefixed) command to all local users on the channel specified
1105 * by <to>; <tok> is ignored by this function
1107 void sendcmdto_channel_butserv(struct Client *from, const char *cmd,
1108 const char *tok, struct Channel *to,
1109 const char *pattern, ...)
1112 char sndbuf[IRC_BUFSIZE];
1113 struct Membership *member;
1115 vd.vd_format = pattern; /* set up the struct VarData for %v */
1116 va_start(vd.vd_args, pattern);
1118 /* build the buffer */
1119 if (IsServer(from) || IsMe(from))
1120 ircd_snprintf(0, sndbuf, sizeof(sndbuf) - 2, ":%s %s %v", from->name,
1123 ircd_snprintf(0, sndbuf, sizeof(sndbuf) - 2, ":%s!%s@%s %s %v", from->name,
1124 from->user->username, from->user->host, cmd, &vd);
1127 /* send the buffer to each local channel member */
1128 for (member = to->members; member; member = member->next_member) {
1129 if (MyConnect(member->user) && !IsZombie(member))
1130 send_buffer(member->user, sndbuf);
1135 * Send a (prefixed) command to all users on this channel, including
1136 * remote users; users to skip may be specified by setting appropriate
1137 * flags in the <skip> argument. <one> will also be skipped.
1139 void sendcmdto_channel_butone(struct Client *from, const char *cmd,
1140 const char *tok, struct Channel *to,
1141 struct Client *one, unsigned int skip,
1142 const char *pattern, ...)
1144 struct Membership *member;
1146 char userbuf[IRC_BUFSIZE];
1147 char servbuf[IRC_BUFSIZE];
1149 vd.vd_format = pattern;
1151 /* Build buffer to send to users */
1152 va_start(vd.vd_args, pattern);
1153 if (IsServer(from) || IsMe(from))
1154 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s %s %v", from->name,
1157 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s!%s@%s %s %v",
1158 from->name, from->user->username, from->user->host, cmd,
1162 /* Build buffer to send to servers */
1163 va_start(vd.vd_args, pattern);
1164 ircd_snprintf(&me, servbuf, sizeof(servbuf) - 2, "%C %s %v", from, tok, &vd);
1167 /* send buffer along! */
1169 for (member = to->members; member; member = member->next_member) {
1170 /* skip one, zombies, and deaf users... */
1171 if (member->user->from == one || IsZombie(member) ||
1172 (skip & SKIP_DEAF && IsDeaf(member->user)) ||
1173 (skip & SKIP_NONOPS && !IsChanOp(member)) ||
1174 (skip & SKIP_BURST && IsBurstOrBurstAck(member->user->from)) ||
1175 member->user->from->fd < -1 ||
1176 sentalong[member->user->from->fd] == sentalong_marker)
1179 if (MyConnect(member->user)) /* pick right buffer to send */
1180 send_buffer(member->user, userbuf);
1182 send_buffer(member->user, servbuf);
1187 * Send a (prefixed) command to all users except <one> that have
1190 void sendcmdto_flag_butone(struct Client *from, const char *cmd,
1191 const char *tok, struct Client *one,
1192 unsigned int flag, const char *pattern, ...)
1195 struct Client *cptr;
1196 char userbuf[IRC_BUFSIZE];
1197 char servbuf[IRC_BUFSIZE];
1199 vd.vd_format = pattern;
1201 /* Build buffer to send to users */
1202 va_start(vd.vd_args, pattern);
1203 if (IsServer(from) || IsMe(from))
1204 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s %s %v", from->name,
1207 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s!%s@%s %s %v",
1208 from->name, from->user->username, from->user->host, cmd,
1212 /* Build buffer to send to servers */
1213 va_start(vd.vd_args, pattern);
1214 ircd_snprintf(&me, servbuf, sizeof(servbuf) - 2, "%C %s %v", from, tok, &vd);
1217 /* send buffer along! */
1219 for (cptr = GlobalClientList; cptr; cptr = cptr->next) {
1220 if (cptr->from == one || IsServer(cptr) || !(cptr->flags & flag) ||
1221 cptr->from->fd < 0 || sentalong[cptr->from->fd] == sentalong_marker)
1222 continue; /* skip it */
1224 if (MyConnect(cptr)) /* send right buffer */
1225 send_buffer(cptr, userbuf);
1227 send_buffer(cptr, servbuf);
1232 * Send a (prefixed) command to all users who match <to>, under control
1235 void sendcmdto_match_butone(struct Client *from, const char *cmd,
1236 const char *tok, const char *to,
1237 struct Client *one, unsigned int who,
1238 const char *pattern, ...)
1241 struct Client *cptr;
1242 char userbuf[IRC_BUFSIZE];
1243 char servbuf[IRC_BUFSIZE];
1245 vd.vd_format = pattern;
1247 /* Build buffer to send to users */
1248 va_start(vd.vd_args, pattern);
1249 if (IsServer(from) || IsMe(from)) /* probably a bad idea :) */
1250 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s %s %v", from->name,
1253 ircd_snprintf(0, userbuf, sizeof(userbuf) - 2, ":%s!%s@%s %s %v",
1254 from->name, from->user->username, from->user->host, cmd,
1258 /* Build buffer to send to servers */
1259 va_start(vd.vd_args, pattern);
1260 ircd_snprintf(&me, servbuf, sizeof(servbuf) - 2, "%C %s %v", from, tok, &vd);
1263 /* send buffer along */
1265 for (cptr = GlobalClientList; cptr; cptr = cptr->next) {
1266 if (cptr->from == one || IsServer(cptr) || !match_it(cptr, to, who) ||
1267 cptr->from->fd < 0 || sentalong[cptr->from->fd] == sentalong_marker)
1268 continue; /* skip it */
1270 if (MyConnect(cptr)) /* send right buffer */
1271 send_buffer(cptr, userbuf);
1273 send_buffer(cptr, servbuf);
1278 * Send a server notice to all users subscribing to the indicated <mask>
1281 void sendto_opmask_butone(struct Client *one, unsigned int mask,
1282 const char *pattern, ...)
1286 va_start(vl, pattern);
1287 vsendto_opmask_butone(one, mask, pattern, vl);
1292 * Same as above, except called with a variable argument list
1294 void vsendto_opmask_butone(struct Client *one, unsigned int mask,
1295 const char *pattern, va_list vl)
1298 char sndbuf[IRC_BUFSIZE];
1299 int i = 0; /* so that 1 points to opsarray[0] */
1300 struct SLink *opslist;
1302 while ((mask >>= 1))
1305 if (!(opslist = opsarray[i]))
1309 * build string; I don't want to bother with client nicknames, so I hope
1312 vd.vd_format = pattern;
1314 ircd_snprintf(0, sndbuf, sizeof(sndbuf) - 2, ":%s " MSG_NOTICE
1315 " * :*** Notice -- %v", me.name, &vd);
1317 for (; opslist; opslist = opslist->next)
1318 send_buffer(opslist->value.cptr, sndbuf);