]>
jfr.im git - irc/rqf/shadowircd.git/blob - src/send.c
2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: send.c 3161 2007-01-25 07:23:01Z nenolod $
34 #include "irc_string.h"
39 #include "sprintf_irc.h"
41 #include "s_newconf.h"
47 #define LOG_BUFSIZE 2048
49 /* send the message to the link the target is attached to */
50 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
52 unsigned long current_serial
= 0L;
56 * inputs - client to send to, linebuf to attach
58 * side effects - linebuf is attached to client
61 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
65 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
69 if(!MyConnect(to
) || IsIOError(to
))
72 if(linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
76 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
77 "Max SendQ limit exceeded for %s: %u > %lu",
78 get_server_name(to
, HIDE_IP
),
79 linebuf_len(&to
->localClient
->buf_sendq
),
82 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to
, SHOW_IP
),
84 linebuf_len(&to
->localClient
->buf_sendq
),
89 to
->flags
|= FLAGS_SENDQEX
;
96 /* just attach the linebuf to the sendq instead of
97 * generating a new one
99 linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
103 ** Update statistics. The following is slightly incorrect
104 ** because it counts messages even if queued, but bytes
105 ** only really sent. Queued bytes get updated in SendQueued.
107 to
->localClient
->sendM
+= 1;
108 me
.localClient
->sendM
+= 1;
109 if(linebuf_len(&to
->localClient
->buf_sendq
) > 0)
110 send_queued_write(to
->localClient
->fd
, to
);
114 /* send_linebuf_remote()
116 * inputs - client to attach to, sender, linebuf
118 * side effects - client has linebuf attached
121 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
126 /* test for fake direction */
127 if(!MyClient(from
) && IsPerson(to
) && (to
== from
->from
))
131 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
132 "Send message to %s[%s] dropped from %s(Fake Dir)",
133 to
->name
, to
->from
->name
, from
->name
);
137 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
138 "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
139 to
->name
, to
->username
, to
->host
,
140 from
->name
, from
->username
, from
->host
, to
->from
->name
);
141 kill_client_serv_butone(NULL
, to
, "%s (%s[%s@%s] Ghosted %s)",
142 me
.name
, to
->name
, to
->username
,
143 to
->host
, to
->from
->name
);
145 to
->flags
|= FLAGS_KILLED
;
147 exit_client(NULL
, to
, &me
, "Ghosted client");
151 _send_linebuf(to
, linebuf
);
155 /* send_queued_write()
157 * inputs - fd to have queue sent, client we're sending to
158 * outputs - contents of queue
159 * side effects - write is rescheduled if queue isnt emptied
162 send_queued_write(int fd
, void *data
)
164 struct Client
*to
= data
;
167 #ifdef USE_IODEBUG_HOOKS
170 /* cant write anything to a dead socket. */
174 #ifdef USE_IODEBUG_HOOKS
176 if(to
->localClient
->buf_sendq
.list
.head
)
177 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
178 to
->localClient
->buf_sendq
.writeofs
;
181 if(linebuf_len(&to
->localClient
->buf_sendq
))
184 linebuf_flush(to
->localClient
->fd
, &to
->localClient
->buf_sendq
)) > 0)
186 /* We have some data written .. update counters */
187 #ifdef USE_IODEBUG_HOOKS
189 call_hook(h_iosend_id
, &hd
);
191 if(to
->localClient
->buf_sendq
.list
.head
)
193 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
194 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
198 to
->localClient
->sendB
+= retlen
;
199 me
.localClient
->sendB
+= retlen
;
200 if(to
->localClient
->sendB
> 1023)
202 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
203 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
205 else if(me
.localClient
->sendB
> 1023)
207 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
208 me
.localClient
->sendB
&= 0x03ff;
212 if(retlen
== 0 || (retlen
< 0 && !ignoreErrno(errno
)))
218 if(ignoreErrno(errno
))
219 flags
= COMM_SELECT_WRITE
|COMM_SELECT_RETRY
;
221 flags
= COMM_SELECT_WRITE
;
222 if(linebuf_len(&to
->localClient
->buf_sendq
))
223 comm_setselect(fd
, FDLIST_IDLECLIENT
, flags
,
224 send_queued_write
, to
, 0);
227 /* send_queued_slink_write()
229 * inputs - fd to have queue sent, client we're sending to
230 * outputs - contents of queue
231 * side effects - write is rescheduled if queue isnt emptied
234 send_queued_slink_write(int fd
, void *data
)
236 struct Client
*to
= data
;
240 ** Once socket is marked dead, we cannot start writing to it,
241 ** even if the error is removed...
246 /* Next, lets try to write some data */
247 if(to
->localClient
->slinkq
)
249 retlen
= write(to
->localClient
->ctrlfd
,
250 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
251 to
->localClient
->slinkq_len
);
255 /* If we have a fatal error */
256 if(!ignoreErrno(errno
))
262 /* 0 bytes is an EOF .. */
270 to
->localClient
->slinkq_len
-= retlen
;
272 s_assert(to
->localClient
->slinkq_len
>= 0);
273 if(to
->localClient
->slinkq_len
)
274 to
->localClient
->slinkq_ofs
+= retlen
;
277 to
->localClient
->slinkq_ofs
= 0;
278 MyFree(to
->localClient
->slinkq
);
279 to
->localClient
->slinkq
= NULL
;
284 /* if we have any more data, reschedule a write */
285 if(to
->localClient
->slinkq_len
)
286 comm_setselect(to
->localClient
->ctrlfd
, FDLIST_IDLECLIENT
,
287 COMM_SELECT_WRITE
|COMM_SELECT_RETRY
, send_queued_slink_write
, to
, 0);
292 * inputs - client to send to, va_args
293 * outputs - client has message put into its queue
297 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
302 /* send remote if to->from non NULL */
303 if(target_p
->from
!= NULL
)
304 target_p
= target_p
->from
;
306 if(IsIOError(target_p
))
309 linebuf_newbuf(&linebuf
);
311 va_start(args
, pattern
);
312 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
315 _send_linebuf(target_p
, &linebuf
);
317 linebuf_donebuf(&linebuf
);
321 /* sendto_one_prefix()
323 * inputs - client to send to, va_args
324 * outputs - client has message put into its queue
325 * side effects - source(us)/target is chosen based on TS6 capability
328 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
329 const char *command
, const char *pattern
, ...)
331 struct Client
*dest_p
;
335 /* send remote if to->from non NULL */
336 if(target_p
->from
!= NULL
)
337 dest_p
= target_p
->from
;
341 if(IsIOError(dest_p
))
346 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
350 linebuf_newbuf(&linebuf
);
351 va_start(args
, pattern
);
352 linebuf_putmsg(&linebuf
, pattern
, &args
,
354 get_id(source_p
, target_p
),
355 command
, get_id(target_p
, target_p
));
358 _send_linebuf(dest_p
, &linebuf
);
359 linebuf_donebuf(&linebuf
);
362 /* sendto_one_notice()
364 * inputs - client to send to, va_args
365 * outputs - client has a NOTICE put into its queue
366 * side effects - source(us)/target is chosen based on TS6 capability
369 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
371 struct Client
*dest_p
;
376 /* send remote if to->from non NULL */
377 if(target_p
->from
!= NULL
)
378 dest_p
= target_p
->from
;
382 if(IsIOError(dest_p
))
387 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
391 linebuf_newbuf(&linebuf
);
392 va_start(args
, pattern
);
393 linebuf_putmsg(&linebuf
, pattern
, &args
,
395 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
398 _send_linebuf(dest_p
, &linebuf
);
399 linebuf_donebuf(&linebuf
);
403 /* sendto_one_numeric()
405 * inputs - client to send to, va_args
406 * outputs - client has message put into its queue
407 * side effects - source/target is chosen based on TS6 capability
410 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
412 struct Client
*dest_p
;
417 /* send remote if to->from non NULL */
418 if(target_p
->from
!= NULL
)
419 dest_p
= target_p
->from
;
423 if(IsIOError(dest_p
))
428 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
432 linebuf_newbuf(&linebuf
);
433 va_start(args
, pattern
);
434 linebuf_putmsg(&linebuf
, pattern
, &args
,
436 get_id(&me
, target_p
),
437 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
440 _send_linebuf(dest_p
, &linebuf
);
441 linebuf_donebuf(&linebuf
);
447 * inputs - pointer to client to NOT send to
448 * - caps or'd together which must ALL be present
449 * - caps or'd together which must ALL NOT be present
450 * - printf style format string
451 * - args to format string
453 * side effects - Send a message to all connected servers, except the
454 * client 'one' (if non-NULL), as long as the servers
455 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
457 * This function was written in an attempt to merge together the other
458 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
462 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
463 unsigned long nocaps
, const char *format
, ...)
466 struct Client
*target_p
;
468 dlink_node
*next_ptr
;
471 /* noone to send to.. */
472 if(dlink_list_length(&serv_list
) == 0)
475 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
478 linebuf_newbuf(&linebuf
);
479 va_start(args
, format
);
480 linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
483 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
485 target_p
= ptr
->data
;
487 /* check against 'one' */
488 if(one
!= NULL
&& (target_p
== one
->from
))
491 /* check we have required capabs */
492 if(!IsCapable(target_p
, caps
))
495 /* check we don't have any forbidden capabs */
496 if(!NotCapable(target_p
, nocaps
))
499 _send_linebuf(target_p
, &linebuf
);
502 linebuf_donebuf(&linebuf
);
506 /* sendto_channel_flags()
508 * inputs - server not to send to, flags needed, source, channel, va_args
509 * outputs - message is sent to channel members
513 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
514 struct Channel
*chptr
, const char *pattern
, ...)
516 static char buf
[BUFSIZE
];
518 buf_head_t linebuf_local
;
519 buf_head_t linebuf_name
;
520 buf_head_t linebuf_id
;
521 struct Client
*target_p
;
522 struct membership
*msptr
;
524 dlink_node
*next_ptr
;
526 linebuf_newbuf(&linebuf_local
);
527 linebuf_newbuf(&linebuf_name
);
528 linebuf_newbuf(&linebuf_id
);
532 va_start(args
, pattern
);
533 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
536 if(IsServer(source_p
))
537 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
538 ":%s %s", source_p
->name
, buf
);
540 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
542 source_p
->name
, source_p
->username
,
543 source_p
->host
, buf
);
545 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
546 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
548 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
551 target_p
= msptr
->client_p
;
553 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
556 if(type
&& ((msptr
->flags
& type
) == 0))
562 if(!MyClient(target_p
))
564 /* if we've got a specific type, target must support
567 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
570 if(target_p
->from
->serial
!= current_serial
)
572 if(has_id(target_p
->from
))
573 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
575 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
577 target_p
->from
->serial
= current_serial
;
581 _send_linebuf(target_p
, &linebuf_local
);
584 linebuf_donebuf(&linebuf_local
);
585 linebuf_donebuf(&linebuf_name
);
586 linebuf_donebuf(&linebuf_id
);
590 /* sendto_channel_local()
592 * inputs - flags to send to, channel to send to, va_args
593 * outputs - message to local channel members
597 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
601 struct membership
*msptr
;
602 struct Client
*target_p
;
604 dlink_node
*next_ptr
;
606 linebuf_newbuf(&linebuf
);
608 va_start(args
, pattern
);
609 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
612 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
615 target_p
= msptr
->client_p
;
617 if(IsIOError(target_p
))
620 if(type
&& ((msptr
->flags
& type
) == 0))
623 _send_linebuf(target_p
, &linebuf
);
626 linebuf_donebuf(&linebuf
);
629 /* sendto_channel_local_butone()
631 * inputs - flags to send to, channel to send to, va_args
632 * - user to ignore when sending
633 * outputs - message to local channel members
637 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
641 struct membership
*msptr
;
642 struct Client
*target_p
;
644 dlink_node
*next_ptr
;
646 linebuf_newbuf(&linebuf
);
648 va_start(args
, pattern
);
649 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
652 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
655 target_p
= msptr
->client_p
;
660 if(IsIOError(target_p
))
663 if(type
&& ((msptr
->flags
& type
) == 0))
666 _send_linebuf(target_p
, &linebuf
);
669 linebuf_donebuf(&linebuf
);
673 * sendto_common_channels_local()
675 * inputs - pointer to client
678 * side effects - Sends a message to all people on local server who are
679 * in same channel with user.
680 * used by m_nick.c and exit_one_client.
683 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
687 dlink_node
*next_ptr
;
689 dlink_node
*next_uptr
;
690 struct Channel
*chptr
;
691 struct Client
*target_p
;
692 struct membership
*msptr
;
693 struct membership
*mscptr
;
696 linebuf_newbuf(&linebuf
);
697 va_start(args
, pattern
);
698 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
703 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
706 chptr
= mscptr
->chptr
;
708 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
711 target_p
= msptr
->client_p
;
713 if(IsIOError(target_p
) ||
714 target_p
->serial
== current_serial
)
717 target_p
->serial
= current_serial
;
718 send_linebuf(target_p
, &linebuf
);
722 /* this can happen when the user isnt in any channels, but we still
723 * need to send them the data, ie a nick change
725 if(MyConnect(user
) && (user
->serial
!= current_serial
))
726 send_linebuf(user
, &linebuf
);
728 linebuf_donebuf(&linebuf
);
732 * sendto_common_channels_local_butone()
734 * inputs - pointer to client
737 * side effects - Sends a message to all people on local server who are
738 * in same channel with user, except for user itself.
741 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
745 dlink_node
*next_ptr
;
747 dlink_node
*next_uptr
;
748 struct Channel
*chptr
;
749 struct Client
*target_p
;
750 struct membership
*msptr
;
751 struct membership
*mscptr
;
754 linebuf_newbuf(&linebuf
);
755 va_start(args
, pattern
);
756 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
760 /* Skip them -- jilles */
761 user
->serial
= current_serial
;
763 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
766 chptr
= mscptr
->chptr
;
768 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
771 target_p
= msptr
->client_p
;
773 if(IsIOError(target_p
) ||
774 target_p
->serial
== current_serial
)
777 target_p
->serial
= current_serial
;
778 send_linebuf(target_p
, &linebuf
);
782 linebuf_donebuf(&linebuf
);
785 /* sendto_match_butone()
787 * inputs - server not to send to, source, mask, type of mask, va_args
789 * side effects - message is sent to matching clients
792 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
793 const char *mask
, int what
, const char *pattern
, ...)
795 static char buf
[BUFSIZE
];
797 struct Client
*target_p
;
799 dlink_node
*next_ptr
;
800 buf_head_t linebuf_local
;
801 buf_head_t linebuf_name
;
802 buf_head_t linebuf_id
;
804 linebuf_newbuf(&linebuf_local
);
805 linebuf_newbuf(&linebuf_name
);
806 linebuf_newbuf(&linebuf_id
);
808 va_start(args
, pattern
);
809 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
812 if(IsServer(source_p
))
813 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
814 ":%s %s", source_p
->name
, buf
);
816 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
818 source_p
->name
, source_p
->username
,
819 source_p
->host
, buf
);
821 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
822 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
824 if(what
== MATCH_HOST
)
826 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
828 target_p
= ptr
->data
;
830 if(match(mask
, target_p
->host
))
831 _send_linebuf(target_p
, &linebuf_local
);
834 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
835 else if(match(mask
, me
.name
))
837 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
839 target_p
= ptr
->data
;
840 _send_linebuf(target_p
, &linebuf_local
);
844 DLINK_FOREACH(ptr
, serv_list
.head
)
846 target_p
= ptr
->data
;
852 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
854 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
857 linebuf_donebuf(&linebuf_local
);
858 linebuf_donebuf(&linebuf_id
);
859 linebuf_donebuf(&linebuf_name
);
862 /* sendto_match_servs()
864 * inputs - source, mask to send to, caps needed, va_args
866 * side effects - message is sent to matching servers with caps.
869 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
870 int nocap
, const char *pattern
, ...)
872 static char buf
[BUFSIZE
];
875 struct Client
*target_p
;
876 buf_head_t linebuf_id
;
877 buf_head_t linebuf_name
;
879 if(EmptyString(mask
))
882 linebuf_newbuf(&linebuf_id
);
883 linebuf_newbuf(&linebuf_name
);
885 va_start(args
, pattern
);
886 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
889 linebuf_putmsg(&linebuf_id
, NULL
, NULL
,
890 ":%s %s", use_id(source_p
), buf
);
891 linebuf_putmsg(&linebuf_name
, NULL
, NULL
,
892 ":%s %s", source_p
->name
, buf
);
896 DLINK_FOREACH(ptr
, global_serv_list
.head
)
898 target_p
= ptr
->data
;
900 /* dont send to ourselves, or back to where it came from.. */
901 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
904 if(target_p
->from
->serial
== current_serial
)
907 if(match(mask
, target_p
->name
))
909 /* if we set the serial here, then we'll never do
910 * a match() again if !IsCapable()
912 target_p
->from
->serial
= current_serial
;
914 if(cap
&& !IsCapable(target_p
->from
, cap
))
917 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
920 if(has_id(target_p
->from
))
921 _send_linebuf(target_p
->from
, &linebuf_id
);
923 _send_linebuf(target_p
->from
, &linebuf_name
);
927 linebuf_donebuf(&linebuf_id
);
928 linebuf_donebuf(&linebuf_name
);
933 * inputs - target, source, va_args
935 * side effects - client is sent message with correct prefix.
938 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
939 const char *command
, const char *pattern
, ...)
944 linebuf_newbuf(&linebuf
);
946 va_start(args
, pattern
);
948 if(MyClient(target_p
))
950 if(IsServer(source_p
))
951 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
952 source_p
->name
, command
,
955 linebuf_putmsg(&linebuf
, pattern
, &args
,
957 source_p
->name
, source_p
->username
,
958 source_p
->host
, command
,
962 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
963 get_id(source_p
, target_p
), command
,
964 get_id(target_p
, target_p
));
967 if(MyClient(target_p
))
968 _send_linebuf(target_p
, &linebuf
);
970 send_linebuf_remote(target_p
, source_p
, &linebuf
);
972 linebuf_donebuf(&linebuf
);
975 /* sendto_realops_flags()
977 * inputs - umode needed, level (opers/admin), va_args
979 * side effects - message is sent to opers with matching umodes
982 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
984 struct Client
*client_p
;
986 dlink_node
*next_ptr
;
990 linebuf_newbuf(&linebuf
);
992 va_start(args
, pattern
);
993 linebuf_putmsg(&linebuf
, pattern
, &args
,
994 ":%s NOTICE * :*** Notice -- ", me
.name
);
997 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
999 client_p
= ptr
->data
;
1001 /* If we're sending it to opers and theyre an admin, skip.
1002 * If we're sending it to admins, and theyre not, skip.
1004 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1005 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1008 if(client_p
->umodes
& flags
)
1009 _send_linebuf(client_p
, &linebuf
);
1012 linebuf_donebuf(&linebuf
);
1015 /* sendto_realops_snomask()
1017 * inputs - snomask needed, level (opers/admin), va_args
1019 * side effects - message is sent to opers with matching snomasks
1022 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1024 static char buf
[BUFSIZE
];
1026 struct Client
*client_p
;
1028 dlink_node
*next_ptr
;
1032 linebuf_newbuf(&linebuf
);
1034 /* Be very sure not to do things like "Trying to send to myself"
1035 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1036 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1038 /* rather a lot of copying around, oh well -- jilles */
1039 va_start(args
, pattern
);
1040 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1042 linebuf_putmsg(&linebuf
, pattern
, NULL
,
1043 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1044 snobuf
= construct_snobuf(flags
);
1045 if (snobuf
[1] != '\0')
1047 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1048 ":%s ENCAP * SNOTE %c :%s",
1049 me
.id
, snobuf
[1], buf
);
1050 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1051 ":%s ENCAP * SNOTE %c :%s",
1052 me
.name
, snobuf
[1], buf
);
1057 va_start(args
, pattern
);
1058 linebuf_putmsg(&linebuf
, pattern
, &args
,
1059 ":%s NOTICE * :*** Notice -- ", me
.name
);
1062 level
&= ~L_NETWIDE
;
1064 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1066 client_p
= ptr
->data
;
1068 /* If we're sending it to opers and theyre an admin, skip.
1069 * If we're sending it to admins, and theyre not, skip.
1071 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1072 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1075 if(client_p
->snomask
& flags
)
1076 _send_linebuf(client_p
, &linebuf
);
1079 linebuf_donebuf(&linebuf
);
1081 /* sendto_realops_snomask_from()
1083 * inputs - snomask needed, level (opers/admin), source server, va_args
1085 * side effects - message is sent to opers with matching snomask
1088 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1089 const char *pattern
, ...)
1091 struct Client
*client_p
;
1093 dlink_node
*next_ptr
;
1097 linebuf_newbuf(&linebuf
);
1099 va_start(args
, pattern
);
1100 linebuf_putmsg(&linebuf
, pattern
, &args
,
1101 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1104 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1106 client_p
= ptr
->data
;
1108 /* If we're sending it to opers and theyre an admin, skip.
1109 * If we're sending it to admins, and theyre not, skip.
1111 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1112 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1115 if(client_p
->snomask
& flags
)
1116 _send_linebuf(client_p
, &linebuf
);
1119 linebuf_donebuf(&linebuf
);
1123 * sendto_wallops_flags
1125 * inputs - flag types of messages to show to real opers
1126 * - client sending request
1127 * - var args input message
1129 * side effects - Send a wallops to local opers
1132 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1134 struct Client
*client_p
;
1136 dlink_node
*next_ptr
;
1140 linebuf_newbuf(&linebuf
);
1142 va_start(args
, pattern
);
1144 if(IsPerson(source_p
))
1145 linebuf_putmsg(&linebuf
, pattern
, &args
,
1146 ":%s!%s@%s WALLOPS :", source_p
->name
,
1147 source_p
->username
, source_p
->host
);
1149 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1153 DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1155 client_p
= ptr
->data
;
1157 if(client_p
->umodes
& flags
)
1158 _send_linebuf(client_p
, &linebuf
);
1161 linebuf_donebuf(&linebuf
);
1166 * input - client to send kill to, client to kill, va_args
1168 * side effects - we issue a kill for the client
1171 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1176 linebuf_newbuf(&linebuf
);
1178 va_start(args
, pattern
);
1179 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1180 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1183 send_linebuf(target_p
, &linebuf
);
1184 linebuf_donebuf(&linebuf
);
1189 * kill_client_serv_butone
1191 * inputs - pointer to client to not send to
1192 * - pointer to client to kill
1194 * side effects - Send a KILL for the given client
1195 * message to all connected servers
1196 * except the client 'one'. Also deal with
1197 * client being unknown to leaf, as in lazylink...
1200 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1202 static char buf
[BUFSIZE
];
1204 struct Client
*client_p
;
1206 dlink_node
*next_ptr
;
1207 buf_head_t linebuf_id
;
1208 buf_head_t linebuf_name
;
1210 linebuf_newbuf(&linebuf_name
);
1211 linebuf_newbuf(&linebuf_id
);
1213 va_start(args
, pattern
);
1214 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1217 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1218 me
.name
, target_p
->name
, buf
);
1219 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1220 use_id(&me
), use_id(target_p
), buf
);
1222 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1224 client_p
= ptr
->data
;
1226 /* ok, if the client we're supposed to not send to has an
1227 * ID, then we still want to issue the kill there..
1229 if(one
!= NULL
&& (client_p
== one
->from
) &&
1230 (!has_id(client_p
) || !has_id(target_p
)))
1233 if(has_id(client_p
))
1234 _send_linebuf(client_p
, &linebuf_id
);
1236 _send_linebuf(client_p
, &linebuf_name
);
1239 linebuf_donebuf(&linebuf_id
);
1240 linebuf_donebuf(&linebuf_name
);