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