]>
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 3520 2007-06-30 22:15:35Z jilles $
34 #include "irc_string.h"
39 #include "sprintf_irc.h"
41 #include "s_newconf.h"
48 #define LOG_BUFSIZE 2048
50 /* send the message to the link the target is attached to */
51 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
53 unsigned long current_serial
= 0L;
57 * inputs - client to send to, linebuf to attach
59 * side effects - linebuf is attached to client
62 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
66 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
70 if(!MyConnect(to
) || IsIOError(to
))
73 if(linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
77 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
78 "Max SendQ limit exceeded for %s: %u > %lu",
79 get_server_name(to
, HIDE_IP
),
80 linebuf_len(&to
->localClient
->buf_sendq
),
83 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
84 log_client_name(to
, SHOW_IP
),
85 linebuf_len(&to
->localClient
->buf_sendq
),
90 to
->flags
|= FLAGS_SENDQEX
;
97 /* just attach the linebuf to the sendq instead of
98 * generating a new one
100 linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
104 ** Update statistics. The following is slightly incorrect
105 ** because it counts messages even if queued, but bytes
106 ** only really sent. Queued bytes get updated in SendQueued.
108 to
->localClient
->sendM
+= 1;
109 me
.localClient
->sendM
+= 1;
110 if(linebuf_len(&to
->localClient
->buf_sendq
) > 0)
111 send_queued_write(to
->localClient
->F
->fd
, to
);
115 /* send_linebuf_remote()
117 * inputs - client to attach to, sender, linebuf
119 * side effects - client has linebuf attached
122 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
127 /* we assume the caller has already tested for fake direction */
129 _send_linebuf(to
, linebuf
);
133 /* send_queued_write()
135 * inputs - fd to have queue sent, client we're sending to
136 * outputs - contents of queue
137 * side effects - write is rescheduled if queue isnt emptied
140 send_queued_write(int fd
, void *data
)
142 struct Client
*to
= data
;
145 #ifdef USE_IODEBUG_HOOKS
148 fde_t
*F
= rb_locate_fd(to
->localClient
->F
->fd
);
152 /* cant write anything to a dead socket. */
156 #ifdef USE_IODEBUG_HOOKS
158 if(to
->localClient
->buf_sendq
.list
.head
)
159 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
160 to
->localClient
->buf_sendq
.writeofs
;
163 if(linebuf_len(&to
->localClient
->buf_sendq
))
166 linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
168 /* We have some data written .. update counters */
169 #ifdef USE_IODEBUG_HOOKS
171 call_hook(h_iosend_id
, &hd
);
173 if(to
->localClient
->buf_sendq
.list
.head
)
175 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
176 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
180 to
->localClient
->sendB
+= retlen
;
181 me
.localClient
->sendB
+= retlen
;
182 if(to
->localClient
->sendB
> 1023)
184 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
185 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
187 else if(me
.localClient
->sendB
> 1023)
189 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
190 me
.localClient
->sendB
&= 0x03ff;
194 if(retlen
== 0 || (retlen
< 0 && !ignoreErrno(errno
)))
200 if(ignoreErrno(errno
))
201 flags
= COMM_SELECT_WRITE
|COMM_SELECT_RETRY
;
203 flags
= COMM_SELECT_WRITE
;
204 if(linebuf_len(&to
->localClient
->buf_sendq
))
205 rb_setselect(fd
, FDLIST_IDLECLIENT
, flags
,
206 send_queued_write
, to
, 0);
209 /* send_queued_slink_write()
211 * inputs - fd to have queue sent, client we're sending to
212 * outputs - contents of queue
213 * side effects - write is rescheduled if queue isnt emptied
216 send_queued_slink_write(int fd
, void *data
)
218 struct Client
*to
= data
;
222 ** Once socket is marked dead, we cannot start writing to it,
223 ** even if the error is removed...
228 /* Next, lets try to write some data */
229 if(to
->localClient
->slinkq
)
231 retlen
= write(to
->localClient
->ctrlfd
,
232 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
233 to
->localClient
->slinkq_len
);
237 /* If we have a fatal error */
238 if(!ignoreErrno(errno
))
244 /* 0 bytes is an EOF .. */
252 to
->localClient
->slinkq_len
-= retlen
;
254 s_assert(to
->localClient
->slinkq_len
>= 0);
255 if(to
->localClient
->slinkq_len
)
256 to
->localClient
->slinkq_ofs
+= retlen
;
259 to
->localClient
->slinkq_ofs
= 0;
260 MyFree(to
->localClient
->slinkq
);
261 to
->localClient
->slinkq
= NULL
;
266 /* if we have any more data, reschedule a write */
267 if(to
->localClient
->slinkq_len
)
268 rb_setselect(to
->localClient
->ctrlfd
, FDLIST_IDLECLIENT
,
269 COMM_SELECT_WRITE
|COMM_SELECT_RETRY
, send_queued_slink_write
, to
, 0);
274 * inputs - client to send to, va_args
275 * outputs - client has message put into its queue
279 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
284 /* send remote if to->from non NULL */
285 if(target_p
->from
!= NULL
)
286 target_p
= target_p
->from
;
288 if(IsIOError(target_p
))
291 linebuf_newbuf(&linebuf
);
293 va_start(args
, pattern
);
294 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
297 _send_linebuf(target_p
, &linebuf
);
299 linebuf_donebuf(&linebuf
);
303 /* sendto_one_prefix()
305 * inputs - client to send to, va_args
306 * outputs - client has message put into its queue
307 * side effects - source(us)/target is chosen based on TS6 capability
310 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
311 const char *command
, const char *pattern
, ...)
313 struct Client
*dest_p
;
317 /* send remote if to->from non NULL */
318 if(target_p
->from
!= NULL
)
319 dest_p
= target_p
->from
;
323 if(IsIOError(dest_p
))
328 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
332 linebuf_newbuf(&linebuf
);
333 va_start(args
, pattern
);
334 linebuf_putmsg(&linebuf
, pattern
, &args
,
336 get_id(source_p
, target_p
),
337 command
, get_id(target_p
, target_p
));
340 _send_linebuf(dest_p
, &linebuf
);
341 linebuf_donebuf(&linebuf
);
344 /* sendto_one_notice()
346 * inputs - client to send to, va_args
347 * outputs - client has a NOTICE put into its queue
348 * side effects - source(us)/target is chosen based on TS6 capability
351 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
353 struct Client
*dest_p
;
358 /* send remote if to->from non NULL */
359 if(target_p
->from
!= NULL
)
360 dest_p
= target_p
->from
;
364 if(IsIOError(dest_p
))
369 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
373 linebuf_newbuf(&linebuf
);
374 va_start(args
, pattern
);
375 linebuf_putmsg(&linebuf
, pattern
, &args
,
377 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
380 _send_linebuf(dest_p
, &linebuf
);
381 linebuf_donebuf(&linebuf
);
385 /* sendto_one_numeric()
387 * inputs - client to send to, va_args
388 * outputs - client has message put into its queue
389 * side effects - source/target is chosen based on TS6 capability
392 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
394 struct Client
*dest_p
;
399 /* send remote if to->from non NULL */
400 if(target_p
->from
!= NULL
)
401 dest_p
= target_p
->from
;
405 if(IsIOError(dest_p
))
410 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
414 linebuf_newbuf(&linebuf
);
415 va_start(args
, pattern
);
416 linebuf_putmsg(&linebuf
, pattern
, &args
,
418 get_id(&me
, target_p
),
419 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
422 _send_linebuf(dest_p
, &linebuf
);
423 linebuf_donebuf(&linebuf
);
429 * inputs - pointer to client to NOT send to
430 * - caps or'd together which must ALL be present
431 * - caps or'd together which must ALL NOT be present
432 * - printf style format string
433 * - args to format string
435 * side effects - Send a message to all connected servers, except the
436 * client 'one' (if non-NULL), as long as the servers
437 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
439 * This function was written in an attempt to merge together the other
440 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
444 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
445 unsigned long nocaps
, const char *format
, ...)
448 struct Client
*target_p
;
450 dlink_node
*next_ptr
;
453 /* noone to send to.. */
454 if(dlink_list_length(&serv_list
) == 0)
457 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
460 linebuf_newbuf(&linebuf
);
461 va_start(args
, format
);
462 linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
465 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
467 target_p
= ptr
->data
;
469 /* check against 'one' */
470 if(one
!= NULL
&& (target_p
== one
->from
))
473 /* check we have required capabs */
474 if(!IsCapable(target_p
, caps
))
477 /* check we don't have any forbidden capabs */
478 if(!NotCapable(target_p
, nocaps
))
481 _send_linebuf(target_p
, &linebuf
);
484 linebuf_donebuf(&linebuf
);
488 /* sendto_channel_flags()
490 * inputs - server not to send to, flags needed, source, channel, va_args
491 * outputs - message is sent to channel members
495 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
496 struct Channel
*chptr
, const char *pattern
, ...)
498 static char buf
[BUFSIZE
];
500 buf_head_t linebuf_local
;
501 buf_head_t linebuf_name
;
502 buf_head_t linebuf_id
;
503 struct Client
*target_p
;
504 struct membership
*msptr
;
506 dlink_node
*next_ptr
;
508 linebuf_newbuf(&linebuf_local
);
509 linebuf_newbuf(&linebuf_name
);
510 linebuf_newbuf(&linebuf_id
);
514 va_start(args
, pattern
);
515 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
518 if(IsServer(source_p
))
519 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
520 ":%s %s", source_p
->name
, buf
);
522 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
524 source_p
->name
, source_p
->username
,
525 source_p
->host
, buf
);
527 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
528 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
530 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
533 target_p
= msptr
->client_p
;
535 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
538 if(type
&& ((msptr
->flags
& type
) == 0))
544 if(!MyClient(target_p
))
546 /* if we've got a specific type, target must support
549 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
552 if(target_p
->from
->serial
!= current_serial
)
554 if(has_id(target_p
->from
))
555 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
557 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
559 target_p
->from
->serial
= current_serial
;
563 _send_linebuf(target_p
, &linebuf_local
);
566 linebuf_donebuf(&linebuf_local
);
567 linebuf_donebuf(&linebuf_name
);
568 linebuf_donebuf(&linebuf_id
);
572 /* sendto_channel_local()
574 * inputs - flags to send to, channel to send to, va_args
575 * outputs - message to local channel members
579 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
583 struct membership
*msptr
;
584 struct Client
*target_p
;
586 dlink_node
*next_ptr
;
588 linebuf_newbuf(&linebuf
);
590 va_start(args
, pattern
);
591 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
594 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
597 target_p
= msptr
->client_p
;
599 if(IsIOError(target_p
))
602 if(type
&& ((msptr
->flags
& type
) == 0))
605 _send_linebuf(target_p
, &linebuf
);
608 linebuf_donebuf(&linebuf
);
611 /* sendto_channel_local_butone()
613 * inputs - flags to send to, channel to send to, va_args
614 * - user to ignore when sending
615 * outputs - message to local channel members
619 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
623 struct membership
*msptr
;
624 struct Client
*target_p
;
626 dlink_node
*next_ptr
;
628 linebuf_newbuf(&linebuf
);
630 va_start(args
, pattern
);
631 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
634 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
637 target_p
= msptr
->client_p
;
642 if(IsIOError(target_p
))
645 if(type
&& ((msptr
->flags
& type
) == 0))
648 _send_linebuf(target_p
, &linebuf
);
651 linebuf_donebuf(&linebuf
);
655 * sendto_common_channels_local()
657 * inputs - pointer to client
660 * side effects - Sends a message to all people on local server who are
661 * in same channel with user.
662 * used by m_nick.c and exit_one_client.
665 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
669 dlink_node
*next_ptr
;
671 dlink_node
*next_uptr
;
672 struct Channel
*chptr
;
673 struct Client
*target_p
;
674 struct membership
*msptr
;
675 struct membership
*mscptr
;
678 linebuf_newbuf(&linebuf
);
679 va_start(args
, pattern
);
680 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
685 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
688 chptr
= mscptr
->chptr
;
690 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
693 target_p
= msptr
->client_p
;
695 if(IsIOError(target_p
) ||
696 target_p
->serial
== current_serial
)
699 target_p
->serial
= current_serial
;
700 send_linebuf(target_p
, &linebuf
);
704 /* this can happen when the user isnt in any channels, but we still
705 * need to send them the data, ie a nick change
707 if(MyConnect(user
) && (user
->serial
!= current_serial
))
708 send_linebuf(user
, &linebuf
);
710 linebuf_donebuf(&linebuf
);
714 * sendto_common_channels_local_butone()
716 * inputs - pointer to client
719 * side effects - Sends a message to all people on local server who are
720 * in same channel with user, except for user itself.
723 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
727 dlink_node
*next_ptr
;
729 dlink_node
*next_uptr
;
730 struct Channel
*chptr
;
731 struct Client
*target_p
;
732 struct membership
*msptr
;
733 struct membership
*mscptr
;
736 linebuf_newbuf(&linebuf
);
737 va_start(args
, pattern
);
738 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
742 /* Skip them -- jilles */
743 user
->serial
= current_serial
;
745 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
748 chptr
= mscptr
->chptr
;
750 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
753 target_p
= msptr
->client_p
;
755 if(IsIOError(target_p
) ||
756 target_p
->serial
== current_serial
)
759 target_p
->serial
= current_serial
;
760 send_linebuf(target_p
, &linebuf
);
764 linebuf_donebuf(&linebuf
);
767 /* sendto_match_butone()
769 * inputs - server not to send to, source, mask, type of mask, va_args
771 * side effects - message is sent to matching clients
774 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
775 const char *mask
, int what
, const char *pattern
, ...)
777 static char buf
[BUFSIZE
];
779 struct Client
*target_p
;
781 dlink_node
*next_ptr
;
782 buf_head_t linebuf_local
;
783 buf_head_t linebuf_name
;
784 buf_head_t linebuf_id
;
786 linebuf_newbuf(&linebuf_local
);
787 linebuf_newbuf(&linebuf_name
);
788 linebuf_newbuf(&linebuf_id
);
790 va_start(args
, pattern
);
791 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
794 if(IsServer(source_p
))
795 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
796 ":%s %s", source_p
->name
, buf
);
798 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
800 source_p
->name
, source_p
->username
,
801 source_p
->host
, buf
);
803 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
804 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
806 if(what
== MATCH_HOST
)
808 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
810 target_p
= ptr
->data
;
812 if(match(mask
, target_p
->host
))
813 _send_linebuf(target_p
, &linebuf_local
);
816 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
817 else if(match(mask
, me
.name
))
819 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
821 target_p
= ptr
->data
;
822 _send_linebuf(target_p
, &linebuf_local
);
826 DLINK_FOREACH(ptr
, serv_list
.head
)
828 target_p
= ptr
->data
;
834 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
836 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
839 linebuf_donebuf(&linebuf_local
);
840 linebuf_donebuf(&linebuf_id
);
841 linebuf_donebuf(&linebuf_name
);
844 /* sendto_match_servs()
846 * inputs - source, mask to send to, caps needed, va_args
848 * side effects - message is sent to matching servers with caps.
851 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
852 int nocap
, const char *pattern
, ...)
854 static char buf
[BUFSIZE
];
857 struct Client
*target_p
;
858 buf_head_t linebuf_id
;
859 buf_head_t linebuf_name
;
861 if(EmptyString(mask
))
864 linebuf_newbuf(&linebuf_id
);
865 linebuf_newbuf(&linebuf_name
);
867 va_start(args
, pattern
);
868 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
871 linebuf_putmsg(&linebuf_id
, NULL
, NULL
,
872 ":%s %s", use_id(source_p
), buf
);
873 linebuf_putmsg(&linebuf_name
, NULL
, NULL
,
874 ":%s %s", source_p
->name
, buf
);
878 DLINK_FOREACH(ptr
, global_serv_list
.head
)
880 target_p
= ptr
->data
;
882 /* dont send to ourselves, or back to where it came from.. */
883 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
886 if(target_p
->from
->serial
== current_serial
)
889 if(match(mask
, target_p
->name
))
891 /* if we set the serial here, then we'll never do
892 * a match() again if !IsCapable()
894 target_p
->from
->serial
= current_serial
;
896 if(cap
&& !IsCapable(target_p
->from
, cap
))
899 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
902 if(has_id(target_p
->from
))
903 _send_linebuf(target_p
->from
, &linebuf_id
);
905 _send_linebuf(target_p
->from
, &linebuf_name
);
909 linebuf_donebuf(&linebuf_id
);
910 linebuf_donebuf(&linebuf_name
);
915 * inputs - monitor nick to send to, format, va_args
916 * outputs - message to local users monitoring the given nick
920 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
924 struct Client
*target_p
;
926 dlink_node
*next_ptr
;
928 linebuf_newbuf(&linebuf
);
930 va_start(args
, pattern
);
931 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
934 DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
936 target_p
= ptr
->data
;
938 if(IsIOError(target_p
))
941 _send_linebuf(target_p
, &linebuf
);
944 linebuf_donebuf(&linebuf
);
949 * inputs - target, source, va_args
951 * side effects - client is sent message with correct prefix.
954 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
955 const char *command
, const char *pattern
, ...)
960 linebuf_newbuf(&linebuf
);
962 va_start(args
, pattern
);
964 if(MyClient(target_p
))
966 if(IsServer(source_p
))
967 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
968 source_p
->name
, command
,
971 linebuf_putmsg(&linebuf
, pattern
, &args
,
973 source_p
->name
, source_p
->username
,
974 source_p
->host
, command
,
978 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
979 get_id(source_p
, target_p
), command
,
980 get_id(target_p
, target_p
));
983 if(MyClient(target_p
))
984 _send_linebuf(target_p
, &linebuf
);
986 send_linebuf_remote(target_p
, source_p
, &linebuf
);
988 linebuf_donebuf(&linebuf
);
991 /* sendto_realops_flags()
993 * inputs - umode needed, level (opers/admin), va_args
995 * side effects - message is sent to opers with matching umodes
998 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
1000 struct Client
*client_p
;
1002 dlink_node
*next_ptr
;
1006 linebuf_newbuf(&linebuf
);
1008 va_start(args
, pattern
);
1009 linebuf_putmsg(&linebuf
, pattern
, &args
,
1010 ":%s NOTICE * :*** Notice -- ", me
.name
);
1013 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1015 client_p
= ptr
->data
;
1017 /* If we're sending it to opers and theyre an admin, skip.
1018 * If we're sending it to admins, and theyre not, skip.
1020 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1021 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1024 if(client_p
->umodes
& flags
)
1025 _send_linebuf(client_p
, &linebuf
);
1028 linebuf_donebuf(&linebuf
);
1031 /* sendto_realops_snomask()
1033 * inputs - snomask needed, level (opers/admin), va_args
1035 * side effects - message is sent to opers with matching snomasks
1038 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1040 static char buf
[BUFSIZE
];
1042 struct Client
*client_p
;
1044 dlink_node
*next_ptr
;
1048 linebuf_newbuf(&linebuf
);
1050 /* Be very sure not to do things like "Trying to send to myself"
1051 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1052 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1054 /* rather a lot of copying around, oh well -- jilles */
1055 va_start(args
, pattern
);
1056 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1058 linebuf_putmsg(&linebuf
, pattern
, NULL
,
1059 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1060 snobuf
= construct_snobuf(flags
);
1061 if (snobuf
[1] != '\0')
1063 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1064 ":%s ENCAP * SNOTE %c :%s",
1065 me
.id
, snobuf
[1], buf
);
1066 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1067 ":%s ENCAP * SNOTE %c :%s",
1068 me
.name
, snobuf
[1], buf
);
1073 va_start(args
, pattern
);
1074 linebuf_putmsg(&linebuf
, pattern
, &args
,
1075 ":%s NOTICE * :*** Notice -- ", me
.name
);
1078 level
&= ~L_NETWIDE
;
1080 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1082 client_p
= ptr
->data
;
1084 /* If we're sending it to opers and theyre an admin, skip.
1085 * If we're sending it to admins, and theyre not, skip.
1087 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1088 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1091 if(client_p
->snomask
& flags
)
1092 _send_linebuf(client_p
, &linebuf
);
1095 linebuf_donebuf(&linebuf
);
1097 /* sendto_realops_snomask_from()
1099 * inputs - snomask needed, level (opers/admin), source server, va_args
1101 * side effects - message is sent to opers with matching snomask
1104 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1105 const char *pattern
, ...)
1107 struct Client
*client_p
;
1109 dlink_node
*next_ptr
;
1113 linebuf_newbuf(&linebuf
);
1115 va_start(args
, pattern
);
1116 linebuf_putmsg(&linebuf
, pattern
, &args
,
1117 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1120 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1122 client_p
= ptr
->data
;
1124 /* If we're sending it to opers and theyre an admin, skip.
1125 * If we're sending it to admins, and theyre not, skip.
1127 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1128 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1131 if(client_p
->snomask
& flags
)
1132 _send_linebuf(client_p
, &linebuf
);
1135 linebuf_donebuf(&linebuf
);
1139 * sendto_wallops_flags
1141 * inputs - flag types of messages to show to real opers
1142 * - client sending request
1143 * - var args input message
1145 * side effects - Send a wallops to local opers
1148 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1150 struct Client
*client_p
;
1152 dlink_node
*next_ptr
;
1156 linebuf_newbuf(&linebuf
);
1158 va_start(args
, pattern
);
1160 if(IsPerson(source_p
))
1161 linebuf_putmsg(&linebuf
, pattern
, &args
,
1162 ":%s!%s@%s WALLOPS :", source_p
->name
,
1163 source_p
->username
, source_p
->host
);
1165 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1169 DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1171 client_p
= ptr
->data
;
1173 if(client_p
->umodes
& flags
)
1174 _send_linebuf(client_p
, &linebuf
);
1177 linebuf_donebuf(&linebuf
);
1182 * input - client to send kill to, client to kill, va_args
1184 * side effects - we issue a kill for the client
1187 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1192 linebuf_newbuf(&linebuf
);
1194 va_start(args
, pattern
);
1195 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1196 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1199 send_linebuf(target_p
, &linebuf
);
1200 linebuf_donebuf(&linebuf
);
1205 * kill_client_serv_butone
1207 * inputs - pointer to client to not send to
1208 * - pointer to client to kill
1210 * side effects - Send a KILL for the given client
1211 * message to all connected servers
1212 * except the client 'one'. Also deal with
1213 * client being unknown to leaf, as in lazylink...
1216 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1218 static char buf
[BUFSIZE
];
1220 struct Client
*client_p
;
1222 dlink_node
*next_ptr
;
1223 buf_head_t linebuf_id
;
1224 buf_head_t linebuf_name
;
1226 linebuf_newbuf(&linebuf_name
);
1227 linebuf_newbuf(&linebuf_id
);
1229 va_start(args
, pattern
);
1230 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1233 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1234 me
.name
, target_p
->name
, buf
);
1235 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1236 use_id(&me
), use_id(target_p
), buf
);
1238 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1240 client_p
= ptr
->data
;
1242 /* ok, if the client we're supposed to not send to has an
1243 * ID, then we still want to issue the kill there..
1245 if(one
!= NULL
&& (client_p
== one
->from
) &&
1246 (!has_id(client_p
) || !has_id(target_p
)))
1249 if(has_id(client_p
))
1250 _send_linebuf(client_p
, &linebuf_id
);
1252 _send_linebuf(client_p
, &linebuf_name
);
1255 linebuf_donebuf(&linebuf_id
);
1256 linebuf_donebuf(&linebuf_name
);