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