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