]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * send.c: Functions for sending messages. | |
4 | * | |
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 | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
22 | * USA | |
23 | * | |
8aba962d | 24 | * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $ |
212380e3 AC |
25 | */ |
26 | ||
27 | #include "stdinc.h" | |
212380e3 AC |
28 | #include "send.h" |
29 | #include "channel.h" | |
30 | #include "class.h" | |
31 | #include "client.h" | |
32 | #include "common.h" | |
33 | #include "irc_string.h" | |
34 | #include "ircd.h" | |
35 | #include "numeric.h" | |
212380e3 AC |
36 | #include "s_serv.h" |
37 | #include "sprintf_irc.h" | |
38 | #include "s_conf.h" | |
39 | #include "s_newconf.h" | |
4016731b | 40 | #include "logger.h" |
212380e3 | 41 | #include "hook.h" |
8aba962d | 42 | #include "monitor.h" |
212380e3 AC |
43 | |
44 | #define LOG_BUFSIZE 2048 | |
45 | ||
46 | /* send the message to the link the target is attached to */ | |
47 | #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b) | |
48 | ||
3b2ebd04 JT |
49 | static void send_queued_write(rb_fde_t *F, void *data); |
50 | ||
212380e3 AC |
51 | unsigned long current_serial = 0L; |
52 | ||
53 | /* send_linebuf() | |
54 | * | |
55 | * inputs - client to send to, linebuf to attach | |
56 | * outputs - | |
57 | * side effects - linebuf is attached to client | |
58 | */ | |
59 | static int | |
60 | _send_linebuf(struct Client *to, buf_head_t *linebuf) | |
61 | { | |
62 | if(IsMe(to)) | |
63 | { | |
64 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | if(!MyConnect(to) || IsIOError(to)) | |
69 | return 0; | |
70 | ||
3b2ebd04 | 71 | if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) |
212380e3 AC |
72 | { |
73 | if(IsServer(to)) | |
74 | { | |
75 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
76 | "Max SendQ limit exceeded for %s: %u > %lu", | |
77 | get_server_name(to, HIDE_IP), | |
3b2ebd04 | 78 | rb_linebuf_len(&to->localClient->buf_sendq), |
212380e3 AC |
79 | get_sendq(to)); |
80 | ||
81 | ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", | |
82 | log_client_name(to, SHOW_IP), | |
3b2ebd04 | 83 | rb_linebuf_len(&to->localClient->buf_sendq), |
212380e3 AC |
84 | get_sendq(to)); |
85 | } | |
86 | ||
87 | if(IsClient(to)) | |
88 | to->flags |= FLAGS_SENDQEX; | |
89 | ||
90 | dead_link(to); | |
91 | return -1; | |
92 | } | |
93 | else | |
94 | { | |
95 | /* just attach the linebuf to the sendq instead of | |
96 | * generating a new one | |
97 | */ | |
3b2ebd04 | 98 | rb_linebuf_attach(&to->localClient->buf_sendq, linebuf); |
212380e3 AC |
99 | } |
100 | ||
101 | /* | |
102 | ** Update statistics. The following is slightly incorrect | |
103 | ** because it counts messages even if queued, but bytes | |
104 | ** only really sent. Queued bytes get updated in SendQueued. | |
105 | */ | |
106 | to->localClient->sendM += 1; | |
107 | me.localClient->sendM += 1; | |
3b2ebd04 JT |
108 | if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) |
109 | send_queued(to); | |
212380e3 AC |
110 | return 0; |
111 | } | |
112 | ||
113 | /* send_linebuf_remote() | |
114 | * | |
115 | * inputs - client to attach to, sender, linebuf | |
116 | * outputs - | |
117 | * side effects - client has linebuf attached | |
118 | */ | |
119 | static void | |
120 | send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf) | |
121 | { | |
122 | if(to->from) | |
123 | to = to->from; | |
124 | ||
8d0d947d | 125 | /* we assume the caller has already tested for fake direction */ |
212380e3 AC |
126 | |
127 | _send_linebuf(to, linebuf); | |
128 | return; | |
129 | } | |
130 | ||
131 | /* send_queued_write() | |
132 | * | |
133 | * inputs - fd to have queue sent, client we're sending to | |
134 | * outputs - contents of queue | |
135 | * side effects - write is rescheduled if queue isnt emptied | |
136 | */ | |
137 | void | |
3b2ebd04 | 138 | send_queued(struct Client *to) |
212380e3 | 139 | { |
212380e3 | 140 | int retlen; |
212380e3 AC |
141 | #ifdef USE_IODEBUG_HOOKS |
142 | hook_data_int hd; | |
143 | #endif | |
3b2ebd04 | 144 | rb_fde_t *F = to->localClient->F; |
5cd74a3b AC |
145 | if (!F) |
146 | return; | |
147 | ||
212380e3 AC |
148 | /* cant write anything to a dead socket. */ |
149 | if(IsIOError(to)) | |
150 | return; | |
151 | ||
152 | #ifdef USE_IODEBUG_HOOKS | |
153 | hd.client = to; | |
154 | if(to->localClient->buf_sendq.list.head) | |
155 | hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf + | |
156 | to->localClient->buf_sendq.writeofs; | |
157 | #endif | |
158 | ||
3b2ebd04 | 159 | if(rb_linebuf_len(&to->localClient->buf_sendq)) |
212380e3 AC |
160 | { |
161 | while ((retlen = | |
3b2ebd04 | 162 | rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0) |
212380e3 AC |
163 | { |
164 | /* We have some data written .. update counters */ | |
165 | #ifdef USE_IODEBUG_HOOKS | |
166 | hd.arg2 = retlen; | |
167 | call_hook(h_iosend_id, &hd); | |
168 | ||
169 | if(to->localClient->buf_sendq.list.head) | |
170 | hd.arg1 = | |
171 | ((buf_line_t *) to->localClient->buf_sendq.list.head-> | |
172 | data)->buf + to->localClient->buf_sendq.writeofs; | |
173 | #endif | |
174 | ||
175 | ||
176 | to->localClient->sendB += retlen; | |
177 | me.localClient->sendB += retlen; | |
178 | if(to->localClient->sendB > 1023) | |
179 | { | |
180 | to->localClient->sendK += (to->localClient->sendB >> 10); | |
181 | to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ | |
182 | } | |
183 | else if(me.localClient->sendB > 1023) | |
184 | { | |
185 | me.localClient->sendK += (me.localClient->sendB >> 10); | |
186 | me.localClient->sendB &= 0x03ff; | |
187 | } | |
188 | } | |
189 | ||
3b2ebd04 | 190 | if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) |
212380e3 AC |
191 | { |
192 | dead_link(to); | |
193 | return; | |
194 | } | |
195 | } | |
3b2ebd04 JT |
196 | if(rb_linebuf_len(&to->localClient->buf_sendq)) |
197 | rb_setselect(to->localClient->F, RB_SELECT_WRITE, | |
198 | send_queued_write, to); | |
199 | } | |
200 | ||
201 | /* send_queued_write() | |
202 | * | |
203 | * inputs - fd to have queue sent, client we're sending to | |
204 | * outputs - contents of queue | |
205 | * side effects - write is scheduled if queue isnt emptied | |
206 | */ | |
207 | static void | |
208 | send_queued_write(rb_fde_t *F, void *data) | |
209 | { | |
210 | struct Client *to = data; | |
211 | /*ClearFlush(to);*/ | |
212 | send_queued(to); | |
212380e3 AC |
213 | } |
214 | ||
215 | /* send_queued_slink_write() | |
216 | * | |
217 | * inputs - fd to have queue sent, client we're sending to | |
218 | * outputs - contents of queue | |
219 | * side effects - write is rescheduled if queue isnt emptied | |
220 | */ | |
221 | void | |
8c689f96 | 222 | send_queued_slink_write(rb_fde_t *F, void *data) |
212380e3 AC |
223 | { |
224 | struct Client *to = data; | |
225 | int retlen; | |
226 | ||
227 | /* | |
228 | ** Once socket is marked dead, we cannot start writing to it, | |
229 | ** even if the error is removed... | |
230 | */ | |
231 | if(IsIOError(to)) | |
232 | return; | |
233 | ||
234 | /* Next, lets try to write some data */ | |
235 | if(to->localClient->slinkq) | |
236 | { | |
8c689f96 | 237 | retlen = rb_write(to->localClient->ctrlF, |
212380e3 | 238 | to->localClient->slinkq + to->localClient->slinkq_ofs, |
8c689f96 | 239 | to->localClient->slinkq_len); |
212380e3 AC |
240 | |
241 | if(retlen < 0) | |
242 | { | |
243 | /* If we have a fatal error */ | |
3b2ebd04 | 244 | if(!rb_ignore_errno(errno)) |
212380e3 AC |
245 | { |
246 | dead_link(to); | |
247 | return; | |
248 | } | |
249 | } | |
250 | /* 0 bytes is an EOF .. */ | |
251 | else if(retlen == 0) | |
252 | { | |
253 | dead_link(to); | |
254 | return; | |
255 | } | |
256 | else | |
257 | { | |
258 | to->localClient->slinkq_len -= retlen; | |
259 | ||
260 | s_assert(to->localClient->slinkq_len >= 0); | |
261 | if(to->localClient->slinkq_len) | |
262 | to->localClient->slinkq_ofs += retlen; | |
263 | else | |
264 | { | |
265 | to->localClient->slinkq_ofs = 0; | |
637c4932 | 266 | rb_free(to->localClient->slinkq); |
212380e3 AC |
267 | to->localClient->slinkq = NULL; |
268 | } | |
269 | } | |
270 | } | |
271 | ||
272 | /* if we have any more data, reschedule a write */ | |
8c689f96 JT |
273 | if(to->localClient->slinkq_len) |
274 | rb_setselect(to->localClient->ctrlF, | |
275 | RB_SELECT_WRITE, send_queued_slink_write, to); | |
212380e3 AC |
276 | } |
277 | ||
278 | /* sendto_one() | |
279 | * | |
280 | * inputs - client to send to, va_args | |
281 | * outputs - client has message put into its queue | |
282 | * side effects - | |
283 | */ | |
284 | void | |
285 | sendto_one(struct Client *target_p, const char *pattern, ...) | |
286 | { | |
287 | va_list args; | |
288 | buf_head_t linebuf; | |
289 | ||
290 | /* send remote if to->from non NULL */ | |
291 | if(target_p->from != NULL) | |
292 | target_p = target_p->from; | |
293 | ||
294 | if(IsIOError(target_p)) | |
295 | return; | |
296 | ||
3b2ebd04 | 297 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
298 | |
299 | va_start(args, pattern); | |
3b2ebd04 | 300 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
301 | va_end(args); |
302 | ||
303 | _send_linebuf(target_p, &linebuf); | |
304 | ||
3b2ebd04 | 305 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
306 | |
307 | } | |
308 | ||
309 | /* sendto_one_prefix() | |
310 | * | |
311 | * inputs - client to send to, va_args | |
312 | * outputs - client has message put into its queue | |
313 | * side effects - source(us)/target is chosen based on TS6 capability | |
314 | */ | |
315 | void | |
316 | sendto_one_prefix(struct Client *target_p, struct Client *source_p, | |
317 | const char *command, const char *pattern, ...) | |
318 | { | |
319 | struct Client *dest_p; | |
320 | va_list args; | |
321 | buf_head_t linebuf; | |
322 | ||
323 | /* send remote if to->from non NULL */ | |
324 | if(target_p->from != NULL) | |
325 | dest_p = target_p->from; | |
326 | else | |
327 | dest_p = target_p; | |
328 | ||
329 | if(IsIOError(dest_p)) | |
330 | return; | |
331 | ||
332 | if(IsMe(dest_p)) | |
333 | { | |
334 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
335 | return; | |
336 | } | |
337 | ||
3b2ebd04 | 338 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 339 | va_start(args, pattern); |
3b2ebd04 | 340 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
341 | ":%s %s %s ", |
342 | get_id(source_p, target_p), | |
343 | command, get_id(target_p, target_p)); | |
344 | va_end(args); | |
345 | ||
346 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 347 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
348 | } |
349 | ||
350 | /* sendto_one_notice() | |
351 | * | |
352 | * inputs - client to send to, va_args | |
353 | * outputs - client has a NOTICE put into its queue | |
354 | * side effects - source(us)/target is chosen based on TS6 capability | |
355 | */ | |
356 | void | |
357 | sendto_one_notice(struct Client *target_p, const char *pattern, ...) | |
358 | { | |
359 | struct Client *dest_p; | |
360 | va_list args; | |
361 | buf_head_t linebuf; | |
5366977b | 362 | char *to; |
212380e3 AC |
363 | |
364 | /* send remote if to->from non NULL */ | |
365 | if(target_p->from != NULL) | |
366 | dest_p = target_p->from; | |
367 | else | |
368 | dest_p = target_p; | |
369 | ||
370 | if(IsIOError(dest_p)) | |
371 | return; | |
372 | ||
373 | if(IsMe(dest_p)) | |
374 | { | |
375 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
376 | return; | |
377 | } | |
378 | ||
3b2ebd04 | 379 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 380 | va_start(args, pattern); |
3b2ebd04 | 381 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 | 382 | ":%s NOTICE %s ", |
5366977b | 383 | get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); |
212380e3 AC |
384 | va_end(args); |
385 | ||
386 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 387 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
388 | } |
389 | ||
390 | ||
391 | /* sendto_one_numeric() | |
392 | * | |
393 | * inputs - client to send to, va_args | |
394 | * outputs - client has message put into its queue | |
395 | * side effects - source/target is chosen based on TS6 capability | |
396 | */ | |
397 | void | |
398 | sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...) | |
399 | { | |
400 | struct Client *dest_p; | |
401 | va_list args; | |
402 | buf_head_t linebuf; | |
5366977b | 403 | char *to; |
212380e3 AC |
404 | |
405 | /* send remote if to->from non NULL */ | |
406 | if(target_p->from != NULL) | |
407 | dest_p = target_p->from; | |
408 | else | |
409 | dest_p = target_p; | |
410 | ||
411 | if(IsIOError(dest_p)) | |
412 | return; | |
413 | ||
414 | if(IsMe(dest_p)) | |
415 | { | |
416 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
417 | return; | |
418 | } | |
419 | ||
3b2ebd04 | 420 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 421 | va_start(args, pattern); |
3b2ebd04 | 422 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
423 | ":%s %03d %s ", |
424 | get_id(&me, target_p), | |
5366977b | 425 | numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); |
212380e3 AC |
426 | va_end(args); |
427 | ||
428 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 429 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
430 | } |
431 | ||
432 | /* | |
433 | * sendto_server | |
434 | * | |
435 | * inputs - pointer to client to NOT send to | |
436 | * - caps or'd together which must ALL be present | |
437 | * - caps or'd together which must ALL NOT be present | |
438 | * - printf style format string | |
439 | * - args to format string | |
440 | * output - NONE | |
441 | * side effects - Send a message to all connected servers, except the | |
442 | * client 'one' (if non-NULL), as long as the servers | |
443 | * support ALL capabs in 'caps', and NO capabs in 'nocaps'. | |
444 | * | |
445 | * This function was written in an attempt to merge together the other | |
446 | * billion sendto_*serv*() functions, which sprung up with capabs, uids etc | |
447 | * -davidt | |
448 | */ | |
449 | void | |
450 | sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps, | |
451 | unsigned long nocaps, const char *format, ...) | |
452 | { | |
453 | va_list args; | |
454 | struct Client *target_p; | |
330fc5c1 | 455 | rb_dlink_node *ptr; |
637c4932 | 456 | rb_dlink_node *next_ptr; |
212380e3 AC |
457 | buf_head_t linebuf; |
458 | ||
459 | /* noone to send to.. */ | |
330fc5c1 | 460 | if(rb_dlink_list_length(&serv_list) == 0) |
212380e3 AC |
461 | return; |
462 | ||
463 | if(chptr != NULL && *chptr->chname != '#') | |
464 | return; | |
465 | ||
3b2ebd04 | 466 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 467 | va_start(args, format); |
3b2ebd04 | 468 | rb_linebuf_putmsg(&linebuf, format, &args, NULL); |
212380e3 AC |
469 | va_end(args); |
470 | ||
637c4932 | 471 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) |
212380e3 AC |
472 | { |
473 | target_p = ptr->data; | |
474 | ||
475 | /* check against 'one' */ | |
476 | if(one != NULL && (target_p == one->from)) | |
477 | continue; | |
478 | ||
479 | /* check we have required capabs */ | |
480 | if(!IsCapable(target_p, caps)) | |
481 | continue; | |
482 | ||
483 | /* check we don't have any forbidden capabs */ | |
484 | if(!NotCapable(target_p, nocaps)) | |
485 | continue; | |
486 | ||
487 | _send_linebuf(target_p, &linebuf); | |
488 | } | |
489 | ||
3b2ebd04 | 490 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
491 | |
492 | } | |
493 | ||
494 | /* sendto_channel_flags() | |
495 | * | |
496 | * inputs - server not to send to, flags needed, source, channel, va_args | |
497 | * outputs - message is sent to channel members | |
498 | * side effects - | |
499 | */ | |
500 | void | |
501 | sendto_channel_flags(struct Client *one, int type, struct Client *source_p, | |
502 | struct Channel *chptr, const char *pattern, ...) | |
503 | { | |
504 | static char buf[BUFSIZE]; | |
505 | va_list args; | |
3b2ebd04 JT |
506 | buf_head_t rb_linebuf_local; |
507 | buf_head_t rb_linebuf_name; | |
508 | buf_head_t rb_linebuf_id; | |
212380e3 AC |
509 | struct Client *target_p; |
510 | struct membership *msptr; | |
330fc5c1 | 511 | rb_dlink_node *ptr; |
637c4932 | 512 | rb_dlink_node *next_ptr; |
212380e3 | 513 | |
3b2ebd04 JT |
514 | rb_linebuf_newbuf(&rb_linebuf_local); |
515 | rb_linebuf_newbuf(&rb_linebuf_name); | |
516 | rb_linebuf_newbuf(&rb_linebuf_id); | |
212380e3 AC |
517 | |
518 | current_serial++; | |
519 | ||
520 | va_start(args, pattern); | |
3b2ebd04 | 521 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
522 | va_end(args); |
523 | ||
524 | if(IsServer(source_p)) | |
3b2ebd04 | 525 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
526 | ":%s %s", source_p->name, buf); |
527 | else | |
3b2ebd04 | 528 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
529 | ":%s!%s@%s %s", |
530 | source_p->name, source_p->username, | |
531 | source_p->host, buf); | |
532 | ||
3b2ebd04 JT |
533 | rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s %s", source_p->name, buf); |
534 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); | |
212380e3 | 535 | |
637c4932 | 536 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) |
212380e3 AC |
537 | { |
538 | msptr = ptr->data; | |
539 | target_p = msptr->client_p; | |
540 | ||
541 | if(IsIOError(target_p->from) || target_p->from == one) | |
542 | continue; | |
543 | ||
544 | if(type && ((msptr->flags & type) == 0)) | |
545 | continue; | |
546 | ||
547 | if(IsDeaf(target_p)) | |
548 | continue; | |
549 | ||
550 | if(!MyClient(target_p)) | |
551 | { | |
552 | /* if we've got a specific type, target must support | |
553 | * CHW.. --fl | |
554 | */ | |
555 | if(type && NotCapable(target_p->from, CAP_CHW)) | |
556 | continue; | |
557 | ||
558 | if(target_p->from->serial != current_serial) | |
559 | { | |
560 | if(has_id(target_p->from)) | |
3b2ebd04 | 561 | send_linebuf_remote(target_p, source_p, &rb_linebuf_id); |
212380e3 | 562 | else |
3b2ebd04 | 563 | send_linebuf_remote(target_p, source_p, &rb_linebuf_name); |
212380e3 AC |
564 | |
565 | target_p->from->serial = current_serial; | |
566 | } | |
567 | } | |
568 | else | |
3b2ebd04 | 569 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
570 | } |
571 | ||
3b2ebd04 JT |
572 | rb_linebuf_donebuf(&rb_linebuf_local); |
573 | rb_linebuf_donebuf(&rb_linebuf_name); | |
574 | rb_linebuf_donebuf(&rb_linebuf_id); | |
212380e3 AC |
575 | } |
576 | ||
577 | ||
578 | /* sendto_channel_local() | |
579 | * | |
580 | * inputs - flags to send to, channel to send to, va_args | |
581 | * outputs - message to local channel members | |
582 | * side effects - | |
583 | */ | |
584 | void | |
585 | sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...) | |
586 | { | |
587 | va_list args; | |
588 | buf_head_t linebuf; | |
589 | struct membership *msptr; | |
590 | struct Client *target_p; | |
330fc5c1 | 591 | rb_dlink_node *ptr; |
637c4932 | 592 | rb_dlink_node *next_ptr; |
212380e3 | 593 | |
3b2ebd04 | 594 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
595 | |
596 | va_start(args, pattern); | |
3b2ebd04 | 597 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
598 | va_end(args); |
599 | ||
637c4932 | 600 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) |
212380e3 AC |
601 | { |
602 | msptr = ptr->data; | |
603 | target_p = msptr->client_p; | |
604 | ||
605 | if(IsIOError(target_p)) | |
606 | continue; | |
607 | ||
608 | if(type && ((msptr->flags & type) == 0)) | |
609 | continue; | |
610 | ||
611 | _send_linebuf(target_p, &linebuf); | |
612 | } | |
613 | ||
3b2ebd04 | 614 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
615 | } |
616 | ||
617 | /* sendto_channel_local_butone() | |
618 | * | |
619 | * inputs - flags to send to, channel to send to, va_args | |
620 | * - user to ignore when sending | |
621 | * outputs - message to local channel members | |
622 | * side effects - | |
623 | */ | |
624 | void | |
625 | sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...) | |
626 | { | |
627 | va_list args; | |
628 | buf_head_t linebuf; | |
629 | struct membership *msptr; | |
630 | struct Client *target_p; | |
330fc5c1 | 631 | rb_dlink_node *ptr; |
637c4932 | 632 | rb_dlink_node *next_ptr; |
212380e3 | 633 | |
3b2ebd04 | 634 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
635 | |
636 | va_start(args, pattern); | |
3b2ebd04 | 637 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
638 | va_end(args); |
639 | ||
637c4932 | 640 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) |
212380e3 AC |
641 | { |
642 | msptr = ptr->data; | |
643 | target_p = msptr->client_p; | |
644 | ||
645 | if(target_p == one) | |
646 | continue; | |
647 | ||
648 | if(IsIOError(target_p)) | |
649 | continue; | |
650 | ||
651 | if(type && ((msptr->flags & type) == 0)) | |
652 | continue; | |
653 | ||
654 | _send_linebuf(target_p, &linebuf); | |
655 | } | |
656 | ||
3b2ebd04 | 657 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
658 | } |
659 | ||
660 | /* | |
661 | * sendto_common_channels_local() | |
662 | * | |
663 | * inputs - pointer to client | |
664 | * - pattern to send | |
665 | * output - NONE | |
666 | * side effects - Sends a message to all people on local server who are | |
667 | * in same channel with user. | |
668 | * used by m_nick.c and exit_one_client. | |
669 | */ | |
670 | void | |
671 | sendto_common_channels_local(struct Client *user, const char *pattern, ...) | |
672 | { | |
673 | va_list args; | |
330fc5c1 | 674 | rb_dlink_node *ptr; |
637c4932 | 675 | rb_dlink_node *next_ptr; |
330fc5c1 AC |
676 | rb_dlink_node *uptr; |
677 | rb_dlink_node *next_uptr; | |
212380e3 AC |
678 | struct Channel *chptr; |
679 | struct Client *target_p; | |
680 | struct membership *msptr; | |
681 | struct membership *mscptr; | |
682 | buf_head_t linebuf; | |
683 | ||
3b2ebd04 | 684 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 685 | va_start(args, pattern); |
3b2ebd04 | 686 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
687 | va_end(args); |
688 | ||
689 | ++current_serial; | |
690 | ||
637c4932 | 691 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) |
212380e3 AC |
692 | { |
693 | mscptr = ptr->data; | |
694 | chptr = mscptr->chptr; | |
695 | ||
5cefa1d6 | 696 | RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) |
212380e3 AC |
697 | { |
698 | msptr = uptr->data; | |
699 | target_p = msptr->client_p; | |
700 | ||
701 | if(IsIOError(target_p) || | |
702 | target_p->serial == current_serial) | |
703 | continue; | |
704 | ||
705 | target_p->serial = current_serial; | |
706 | send_linebuf(target_p, &linebuf); | |
707 | } | |
708 | } | |
709 | ||
710 | /* this can happen when the user isnt in any channels, but we still | |
711 | * need to send them the data, ie a nick change | |
712 | */ | |
713 | if(MyConnect(user) && (user->serial != current_serial)) | |
714 | send_linebuf(user, &linebuf); | |
715 | ||
3b2ebd04 | 716 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
717 | } |
718 | ||
719 | /* | |
720 | * sendto_common_channels_local_butone() | |
721 | * | |
722 | * inputs - pointer to client | |
723 | * - pattern to send | |
724 | * output - NONE | |
725 | * side effects - Sends a message to all people on local server who are | |
726 | * in same channel with user, except for user itself. | |
727 | */ | |
728 | void | |
729 | sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...) | |
730 | { | |
731 | va_list args; | |
330fc5c1 | 732 | rb_dlink_node *ptr; |
637c4932 | 733 | rb_dlink_node *next_ptr; |
330fc5c1 AC |
734 | rb_dlink_node *uptr; |
735 | rb_dlink_node *next_uptr; | |
212380e3 AC |
736 | struct Channel *chptr; |
737 | struct Client *target_p; | |
738 | struct membership *msptr; | |
739 | struct membership *mscptr; | |
740 | buf_head_t linebuf; | |
741 | ||
3b2ebd04 | 742 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 743 | va_start(args, pattern); |
3b2ebd04 | 744 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
745 | va_end(args); |
746 | ||
747 | ++current_serial; | |
748 | /* Skip them -- jilles */ | |
749 | user->serial = current_serial; | |
750 | ||
637c4932 | 751 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) |
212380e3 AC |
752 | { |
753 | mscptr = ptr->data; | |
754 | chptr = mscptr->chptr; | |
755 | ||
5cefa1d6 | 756 | RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) |
212380e3 AC |
757 | { |
758 | msptr = uptr->data; | |
759 | target_p = msptr->client_p; | |
760 | ||
761 | if(IsIOError(target_p) || | |
762 | target_p->serial == current_serial) | |
763 | continue; | |
764 | ||
765 | target_p->serial = current_serial; | |
766 | send_linebuf(target_p, &linebuf); | |
767 | } | |
768 | } | |
769 | ||
3b2ebd04 | 770 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
771 | } |
772 | ||
773 | /* sendto_match_butone() | |
774 | * | |
775 | * inputs - server not to send to, source, mask, type of mask, va_args | |
776 | * output - | |
777 | * side effects - message is sent to matching clients | |
778 | */ | |
779 | void | |
780 | sendto_match_butone(struct Client *one, struct Client *source_p, | |
781 | const char *mask, int what, const char *pattern, ...) | |
782 | { | |
783 | static char buf[BUFSIZE]; | |
784 | va_list args; | |
785 | struct Client *target_p; | |
330fc5c1 | 786 | rb_dlink_node *ptr; |
637c4932 | 787 | rb_dlink_node *next_ptr; |
3b2ebd04 JT |
788 | buf_head_t rb_linebuf_local; |
789 | buf_head_t rb_linebuf_name; | |
790 | buf_head_t rb_linebuf_id; | |
212380e3 | 791 | |
3b2ebd04 JT |
792 | rb_linebuf_newbuf(&rb_linebuf_local); |
793 | rb_linebuf_newbuf(&rb_linebuf_name); | |
794 | rb_linebuf_newbuf(&rb_linebuf_id); | |
212380e3 AC |
795 | |
796 | va_start(args, pattern); | |
3b2ebd04 | 797 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
798 | va_end(args); |
799 | ||
800 | if(IsServer(source_p)) | |
3b2ebd04 | 801 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
802 | ":%s %s", source_p->name, buf); |
803 | else | |
3b2ebd04 | 804 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
805 | ":%s!%s@%s %s", |
806 | source_p->name, source_p->username, | |
807 | source_p->host, buf); | |
808 | ||
3b2ebd04 JT |
809 | rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s %s", source_p->name, buf); |
810 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); | |
212380e3 AC |
811 | |
812 | if(what == MATCH_HOST) | |
813 | { | |
637c4932 | 814 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) |
212380e3 AC |
815 | { |
816 | target_p = ptr->data; | |
817 | ||
818 | if(match(mask, target_p->host)) | |
3b2ebd04 | 819 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
820 | } |
821 | } | |
822 | /* what = MATCH_SERVER, if it doesnt match us, just send remote */ | |
823 | else if(match(mask, me.name)) | |
824 | { | |
637c4932 | 825 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) |
212380e3 AC |
826 | { |
827 | target_p = ptr->data; | |
3b2ebd04 | 828 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
829 | } |
830 | } | |
831 | ||
5cefa1d6 | 832 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
833 | { |
834 | target_p = ptr->data; | |
835 | ||
836 | if(target_p == one) | |
837 | continue; | |
838 | ||
839 | if(has_id(target_p)) | |
3b2ebd04 | 840 | send_linebuf_remote(target_p, source_p, &rb_linebuf_id); |
212380e3 | 841 | else |
3b2ebd04 | 842 | send_linebuf_remote(target_p, source_p, &rb_linebuf_name); |
212380e3 AC |
843 | } |
844 | ||
3b2ebd04 JT |
845 | rb_linebuf_donebuf(&rb_linebuf_local); |
846 | rb_linebuf_donebuf(&rb_linebuf_id); | |
847 | rb_linebuf_donebuf(&rb_linebuf_name); | |
212380e3 AC |
848 | } |
849 | ||
850 | /* sendto_match_servs() | |
851 | * | |
852 | * inputs - source, mask to send to, caps needed, va_args | |
853 | * outputs - | |
854 | * side effects - message is sent to matching servers with caps. | |
855 | */ | |
856 | void | |
857 | sendto_match_servs(struct Client *source_p, const char *mask, int cap, | |
858 | int nocap, const char *pattern, ...) | |
859 | { | |
860 | static char buf[BUFSIZE]; | |
861 | va_list args; | |
330fc5c1 | 862 | rb_dlink_node *ptr; |
212380e3 | 863 | struct Client *target_p; |
3b2ebd04 JT |
864 | buf_head_t rb_linebuf_id; |
865 | buf_head_t rb_linebuf_name; | |
212380e3 AC |
866 | |
867 | if(EmptyString(mask)) | |
868 | return; | |
869 | ||
3b2ebd04 JT |
870 | rb_linebuf_newbuf(&rb_linebuf_id); |
871 | rb_linebuf_newbuf(&rb_linebuf_name); | |
212380e3 AC |
872 | |
873 | va_start(args, pattern); | |
3b2ebd04 | 874 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
875 | va_end(args); |
876 | ||
3b2ebd04 | 877 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, |
212380e3 | 878 | ":%s %s", use_id(source_p), buf); |
3b2ebd04 | 879 | rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, |
212380e3 AC |
880 | ":%s %s", source_p->name, buf); |
881 | ||
882 | current_serial++; | |
883 | ||
5cefa1d6 | 884 | RB_DLINK_FOREACH(ptr, global_serv_list.head) |
212380e3 AC |
885 | { |
886 | target_p = ptr->data; | |
887 | ||
888 | /* dont send to ourselves, or back to where it came from.. */ | |
889 | if(IsMe(target_p) || target_p->from == source_p->from) | |
890 | continue; | |
891 | ||
892 | if(target_p->from->serial == current_serial) | |
893 | continue; | |
894 | ||
895 | if(match(mask, target_p->name)) | |
896 | { | |
897 | /* if we set the serial here, then we'll never do | |
898 | * a match() again if !IsCapable() | |
899 | */ | |
900 | target_p->from->serial = current_serial; | |
901 | ||
902 | if(cap && !IsCapable(target_p->from, cap)) | |
903 | continue; | |
904 | ||
905 | if(nocap && !NotCapable(target_p->from, nocap)) | |
906 | continue; | |
907 | ||
908 | if(has_id(target_p->from)) | |
3b2ebd04 | 909 | _send_linebuf(target_p->from, &rb_linebuf_id); |
212380e3 | 910 | else |
3b2ebd04 | 911 | _send_linebuf(target_p->from, &rb_linebuf_name); |
212380e3 AC |
912 | } |
913 | } | |
914 | ||
3b2ebd04 JT |
915 | rb_linebuf_donebuf(&rb_linebuf_id); |
916 | rb_linebuf_donebuf(&rb_linebuf_name); | |
212380e3 AC |
917 | } |
918 | ||
8aba962d JT |
919 | /* sendto_monitor() |
920 | * | |
921 | * inputs - monitor nick to send to, format, va_args | |
922 | * outputs - message to local users monitoring the given nick | |
923 | * side effects - | |
924 | */ | |
925 | void | |
926 | sendto_monitor(struct monitor *monptr, const char *pattern, ...) | |
927 | { | |
928 | va_list args; | |
929 | buf_head_t linebuf; | |
930 | struct Client *target_p; | |
330fc5c1 | 931 | rb_dlink_node *ptr; |
637c4932 | 932 | rb_dlink_node *next_ptr; |
8aba962d | 933 | |
3b2ebd04 | 934 | rb_linebuf_newbuf(&linebuf); |
8aba962d JT |
935 | |
936 | va_start(args, pattern); | |
3b2ebd04 | 937 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
8aba962d JT |
938 | va_end(args); |
939 | ||
637c4932 | 940 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head) |
8aba962d JT |
941 | { |
942 | target_p = ptr->data; | |
943 | ||
944 | if(IsIOError(target_p)) | |
945 | continue; | |
946 | ||
947 | _send_linebuf(target_p, &linebuf); | |
948 | } | |
949 | ||
3b2ebd04 | 950 | rb_linebuf_donebuf(&linebuf); |
8aba962d JT |
951 | } |
952 | ||
212380e3 AC |
953 | /* sendto_anywhere() |
954 | * | |
955 | * inputs - target, source, va_args | |
956 | * outputs - | |
957 | * side effects - client is sent message with correct prefix. | |
958 | */ | |
959 | void | |
960 | sendto_anywhere(struct Client *target_p, struct Client *source_p, | |
961 | const char *command, const char *pattern, ...) | |
962 | { | |
963 | va_list args; | |
964 | buf_head_t linebuf; | |
965 | ||
3b2ebd04 | 966 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
967 | |
968 | va_start(args, pattern); | |
969 | ||
970 | if(MyClient(target_p)) | |
971 | { | |
972 | if(IsServer(source_p)) | |
3b2ebd04 | 973 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", |
212380e3 AC |
974 | source_p->name, command, |
975 | target_p->name); | |
976 | else | |
3b2ebd04 | 977 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
978 | ":%s!%s@%s %s %s ", |
979 | source_p->name, source_p->username, | |
980 | source_p->host, command, | |
981 | target_p->name); | |
982 | } | |
983 | else | |
3b2ebd04 | 984 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", |
212380e3 AC |
985 | get_id(source_p, target_p), command, |
986 | get_id(target_p, target_p)); | |
987 | va_end(args); | |
988 | ||
989 | if(MyClient(target_p)) | |
990 | _send_linebuf(target_p, &linebuf); | |
991 | else | |
992 | send_linebuf_remote(target_p, source_p, &linebuf); | |
993 | ||
3b2ebd04 | 994 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
995 | } |
996 | ||
997 | /* sendto_realops_flags() | |
998 | * | |
999 | * inputs - umode needed, level (opers/admin), va_args | |
1000 | * output - | |
1001 | * side effects - message is sent to opers with matching umodes | |
1002 | */ | |
1003 | void | |
1004 | sendto_realops_flags(int flags, int level, const char *pattern, ...) | |
1005 | { | |
1006 | struct Client *client_p; | |
330fc5c1 | 1007 | rb_dlink_node *ptr; |
637c4932 | 1008 | rb_dlink_node *next_ptr; |
212380e3 AC |
1009 | va_list args; |
1010 | buf_head_t linebuf; | |
1011 | ||
3b2ebd04 | 1012 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1013 | |
1014 | va_start(args, pattern); | |
3b2ebd04 | 1015 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1016 | ":%s NOTICE * :*** Notice -- ", me.name); |
1017 | va_end(args); | |
1018 | ||
637c4932 | 1019 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) |
212380e3 AC |
1020 | { |
1021 | client_p = ptr->data; | |
1022 | ||
1023 | /* If we're sending it to opers and theyre an admin, skip. | |
1024 | * If we're sending it to admins, and theyre not, skip. | |
1025 | */ | |
1026 | if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || | |
1027 | ((level == L_OPER) && IsOperAdmin(client_p))) | |
1028 | continue; | |
1029 | ||
1030 | if(client_p->umodes & flags) | |
1031 | _send_linebuf(client_p, &linebuf); | |
1032 | } | |
1033 | ||
3b2ebd04 | 1034 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1035 | } |
1036 | ||
1037 | /* sendto_realops_snomask() | |
1038 | * | |
1039 | * inputs - snomask needed, level (opers/admin), va_args | |
1040 | * output - | |
1041 | * side effects - message is sent to opers with matching snomasks | |
1042 | */ | |
1043 | void | |
1044 | sendto_realops_snomask(int flags, int level, const char *pattern, ...) | |
1045 | { | |
1046 | static char buf[BUFSIZE]; | |
1047 | char *snobuf; | |
1048 | struct Client *client_p; | |
330fc5c1 | 1049 | rb_dlink_node *ptr; |
637c4932 | 1050 | rb_dlink_node *next_ptr; |
212380e3 AC |
1051 | va_list args; |
1052 | buf_head_t linebuf; | |
1053 | ||
3b2ebd04 | 1054 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1055 | |
1056 | /* Be very sure not to do things like "Trying to send to myself" | |
1057 | * L_NETWIDE, otherwise infinite recursion may result! -- jilles */ | |
1058 | if (level & L_NETWIDE && ConfigFileEntry.global_snotices) | |
1059 | { | |
1060 | /* rather a lot of copying around, oh well -- jilles */ | |
1061 | va_start(args, pattern); | |
3b2ebd04 | 1062 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 | 1063 | va_end(args); |
3b2ebd04 | 1064 | rb_linebuf_putmsg(&linebuf, pattern, NULL, |
212380e3 AC |
1065 | ":%s NOTICE * :*** Notice -- %s", me.name, buf); |
1066 | snobuf = construct_snobuf(flags); | |
1067 | if (snobuf[1] != '\0') | |
1068 | { | |
1069 | sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, | |
1070 | ":%s ENCAP * SNOTE %c :%s", | |
1071 | me.id, snobuf[1], buf); | |
1072 | sendto_server(NULL, NULL, CAP_ENCAP, CAP_TS6, | |
1073 | ":%s ENCAP * SNOTE %c :%s", | |
1074 | me.name, snobuf[1], buf); | |
1075 | } | |
1076 | } | |
1077 | else | |
1078 | { | |
1079 | va_start(args, pattern); | |
3b2ebd04 | 1080 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1081 | ":%s NOTICE * :*** Notice -- ", me.name); |
1082 | va_end(args); | |
1083 | } | |
1084 | level &= ~L_NETWIDE; | |
1085 | ||
637c4932 | 1086 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) |
212380e3 AC |
1087 | { |
1088 | client_p = ptr->data; | |
1089 | ||
1090 | /* If we're sending it to opers and theyre an admin, skip. | |
1091 | * If we're sending it to admins, and theyre not, skip. | |
1092 | */ | |
1093 | if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || | |
1094 | ((level == L_OPER) && IsOperAdmin(client_p))) | |
1095 | continue; | |
1096 | ||
1097 | if(client_p->snomask & flags) | |
1098 | _send_linebuf(client_p, &linebuf); | |
1099 | } | |
1100 | ||
3b2ebd04 | 1101 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1102 | } |
1103 | /* sendto_realops_snomask_from() | |
1104 | * | |
1105 | * inputs - snomask needed, level (opers/admin), source server, va_args | |
1106 | * output - | |
1107 | * side effects - message is sent to opers with matching snomask | |
1108 | */ | |
1109 | void | |
1110 | sendto_realops_snomask_from(int flags, int level, struct Client *source_p, | |
1111 | const char *pattern, ...) | |
1112 | { | |
1113 | struct Client *client_p; | |
330fc5c1 | 1114 | rb_dlink_node *ptr; |
637c4932 | 1115 | rb_dlink_node *next_ptr; |
212380e3 AC |
1116 | va_list args; |
1117 | buf_head_t linebuf; | |
1118 | ||
3b2ebd04 | 1119 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1120 | |
1121 | va_start(args, pattern); | |
3b2ebd04 | 1122 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1123 | ":%s NOTICE * :*** Notice -- ", source_p->name); |
1124 | va_end(args); | |
1125 | ||
637c4932 | 1126 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) |
212380e3 AC |
1127 | { |
1128 | client_p = ptr->data; | |
1129 | ||
1130 | /* If we're sending it to opers and theyre an admin, skip. | |
1131 | * If we're sending it to admins, and theyre not, skip. | |
1132 | */ | |
1133 | if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || | |
1134 | ((level == L_OPER) && IsOperAdmin(client_p))) | |
1135 | continue; | |
1136 | ||
1137 | if(client_p->snomask & flags) | |
1138 | _send_linebuf(client_p, &linebuf); | |
1139 | } | |
1140 | ||
3b2ebd04 | 1141 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1142 | } |
1143 | ||
1144 | /* | |
1145 | * sendto_wallops_flags | |
1146 | * | |
1147 | * inputs - flag types of messages to show to real opers | |
1148 | * - client sending request | |
1149 | * - var args input message | |
1150 | * output - NONE | |
1151 | * side effects - Send a wallops to local opers | |
1152 | */ | |
1153 | void | |
1154 | sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...) | |
1155 | { | |
1156 | struct Client *client_p; | |
330fc5c1 | 1157 | rb_dlink_node *ptr; |
637c4932 | 1158 | rb_dlink_node *next_ptr; |
212380e3 AC |
1159 | va_list args; |
1160 | buf_head_t linebuf; | |
1161 | ||
3b2ebd04 | 1162 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1163 | |
1164 | va_start(args, pattern); | |
1165 | ||
1166 | if(IsPerson(source_p)) | |
3b2ebd04 | 1167 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1168 | ":%s!%s@%s WALLOPS :", source_p->name, |
1169 | source_p->username, source_p->host); | |
1170 | else | |
3b2ebd04 | 1171 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name); |
212380e3 AC |
1172 | |
1173 | va_end(args); | |
1174 | ||
637c4932 | 1175 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head) |
212380e3 AC |
1176 | { |
1177 | client_p = ptr->data; | |
1178 | ||
1179 | if(client_p->umodes & flags) | |
1180 | _send_linebuf(client_p, &linebuf); | |
1181 | } | |
1182 | ||
3b2ebd04 | 1183 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1184 | } |
1185 | ||
1186 | /* kill_client() | |
1187 | * | |
1188 | * input - client to send kill to, client to kill, va_args | |
1189 | * output - | |
1190 | * side effects - we issue a kill for the client | |
1191 | */ | |
1192 | void | |
1193 | kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...) | |
1194 | { | |
1195 | va_list args; | |
1196 | buf_head_t linebuf; | |
1197 | ||
3b2ebd04 | 1198 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1199 | |
1200 | va_start(args, pattern); | |
3b2ebd04 | 1201 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :", |
212380e3 AC |
1202 | get_id(&me, target_p), get_id(diedie, target_p)); |
1203 | va_end(args); | |
1204 | ||
1205 | send_linebuf(target_p, &linebuf); | |
3b2ebd04 | 1206 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1207 | } |
1208 | ||
1209 | ||
1210 | /* | |
1211 | * kill_client_serv_butone | |
1212 | * | |
1213 | * inputs - pointer to client to not send to | |
1214 | * - pointer to client to kill | |
1215 | * output - NONE | |
1216 | * side effects - Send a KILL for the given client | |
1217 | * message to all connected servers | |
1218 | * except the client 'one'. Also deal with | |
1219 | * client being unknown to leaf, as in lazylink... | |
1220 | */ | |
1221 | void | |
1222 | kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...) | |
1223 | { | |
1224 | static char buf[BUFSIZE]; | |
1225 | va_list args; | |
1226 | struct Client *client_p; | |
330fc5c1 | 1227 | rb_dlink_node *ptr; |
637c4932 | 1228 | rb_dlink_node *next_ptr; |
3b2ebd04 JT |
1229 | buf_head_t rb_linebuf_id; |
1230 | buf_head_t rb_linebuf_name; | |
212380e3 | 1231 | |
3b2ebd04 JT |
1232 | rb_linebuf_newbuf(&rb_linebuf_name); |
1233 | rb_linebuf_newbuf(&rb_linebuf_id); | |
212380e3 AC |
1234 | |
1235 | va_start(args, pattern); | |
3b2ebd04 | 1236 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
1237 | va_end(args); |
1238 | ||
3b2ebd04 | 1239 | rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s KILL %s :%s", |
212380e3 | 1240 | me.name, target_p->name, buf); |
3b2ebd04 | 1241 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s", |
212380e3 AC |
1242 | use_id(&me), use_id(target_p), buf); |
1243 | ||
637c4932 | 1244 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) |
212380e3 AC |
1245 | { |
1246 | client_p = ptr->data; | |
1247 | ||
1248 | /* ok, if the client we're supposed to not send to has an | |
1249 | * ID, then we still want to issue the kill there.. | |
1250 | */ | |
1251 | if(one != NULL && (client_p == one->from) && | |
1252 | (!has_id(client_p) || !has_id(target_p))) | |
1253 | continue; | |
1254 | ||
1255 | if(has_id(client_p)) | |
3b2ebd04 | 1256 | _send_linebuf(client_p, &rb_linebuf_id); |
212380e3 | 1257 | else |
3b2ebd04 | 1258 | _send_linebuf(client_p, &rb_linebuf_name); |
212380e3 AC |
1259 | } |
1260 | ||
3b2ebd04 JT |
1261 | rb_linebuf_donebuf(&rb_linebuf_id); |
1262 | rb_linebuf_donebuf(&rb_linebuf_name); | |
212380e3 | 1263 | } |