23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
< |
#include "tools.h" |
26 |
> |
#include "list.h" |
27 |
|
#include "send.h" |
28 |
|
#include "channel.h" |
29 |
|
#include "client.h" |
30 |
– |
#include "common.h" |
30 |
|
#include "dbuf.h" |
31 |
|
#include "irc_string.h" |
32 |
|
#include "ircd.h" |
34 |
– |
#include "handlers.h" |
33 |
|
#include "numeric.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "s_bsd.h" |
36 |
|
#include "s_serv.h" |
37 |
< |
#include "sprintf_irc.h" |
38 |
< |
#include "s_conf.h" |
41 |
< |
#include "list.h" |
42 |
< |
#include "s_log.h" |
37 |
> |
#include "conf.h" |
38 |
> |
#include "log.h" |
39 |
|
#include "memory.h" |
44 |
– |
#include "hook.h" |
45 |
– |
#include "irc_getnameinfo.h" |
40 |
|
#include "packet.h" |
41 |
|
|
48 |
– |
#define LOG_BUFSIZE 2048 |
42 |
|
|
43 |
< |
struct Callback *iosend_cb = NULL; |
51 |
< |
struct Callback *iosendctrl_cb = NULL; |
43 |
> |
static unsigned int current_serial = 0; |
44 |
|
|
53 |
– |
static void send_message(struct Client *, char *, int); |
54 |
– |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
55 |
– |
|
56 |
– |
static unsigned long current_serial = 0L; |
45 |
|
|
46 |
|
/* send_format() |
47 |
|
* |
75 |
|
|
76 |
|
lsendbuf[len++] = '\r'; |
77 |
|
lsendbuf[len++] = '\n'; |
78 |
< |
return (len); |
78 |
> |
return len; |
79 |
|
} |
80 |
|
|
81 |
|
/* |
86 |
|
static void |
87 |
|
send_message(struct Client *to, char *buf, int len) |
88 |
|
{ |
89 |
< |
#ifdef INVARIANTS |
90 |
< |
if (IsMe(to)) |
103 |
< |
{ |
104 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
105 |
< |
"Trying to send message to myself!"); |
106 |
< |
return; |
107 |
< |
} |
108 |
< |
#endif |
89 |
> |
assert(!IsMe(to)); |
90 |
> |
assert(to != &me); |
91 |
|
|
92 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
92 |
> |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs)) |
93 |
|
{ |
94 |
|
if (IsServer(to)) |
95 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
96 |
< |
"Max SendQ limit exceeded for %s: %lu > %lu", |
95 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
96 |
> |
"Max SendQ limit exceeded for %s: %lu > %u", |
97 |
|
get_client_name(to, HIDE_IP), |
98 |
|
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len), |
99 |
< |
get_sendq(to)); |
99 |
> |
get_sendq(&to->localClient->confs)); |
100 |
|
if (IsClient(to)) |
101 |
|
SetSendQExceeded(to); |
102 |
|
dead_link_on_write(to, 0); |
103 |
|
return; |
104 |
|
} |
105 |
< |
|
105 |
> |
|
106 |
|
dbuf_put(&to->localClient->buf_sendq, buf, len); |
107 |
|
|
108 |
|
/* |
135 |
|
{ |
136 |
|
if (!MyConnect(to)) |
137 |
|
{ |
138 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
138 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
139 |
|
"server send message to %s [%s] dropped from %s(Not local server)", |
140 |
|
to->name, to->from->name, from->name); |
141 |
|
return; |
142 |
|
} |
143 |
|
|
162 |
– |
if (ServerInfo.hub && IsCapable(to, CAP_LL)) |
163 |
– |
{ |
164 |
– |
if (((from->lazyLinkClientExists & |
165 |
– |
to->localClient->serverMask) == 0)) |
166 |
– |
client_burst_if_needed(to, from); |
167 |
– |
} |
168 |
– |
|
144 |
|
/* Optimize by checking if (from && to) before everything */ |
145 |
|
/* we set to->from up there.. */ |
146 |
|
|
148 |
|
{ |
149 |
|
if (IsServer(from)) |
150 |
|
{ |
151 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
151 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
152 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
153 |
|
to->name, to->from->name, from->name); |
154 |
|
return; |
155 |
|
} |
156 |
|
|
157 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
157 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
158 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
159 |
|
to->name, to->username, to->host, |
160 |
|
from->name, from->username, from->host, |
161 |
|
to->from->name); |
162 |
|
|
163 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
163 |
> |
sendto_server(NULL, CAP_TS6, NOCAPS, |
164 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
165 |
|
me.id, to->name, me.name, to->name, |
166 |
|
to->username, to->host, to->from->name); |
167 |
< |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
167 |
> |
sendto_server(NULL, NOCAPS, CAP_TS6, |
168 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
169 |
|
me.name, to->name, me.name, to->name, |
170 |
|
to->username, to->host, to->from->name); |
171 |
|
|
172 |
< |
SetKilled(to); |
172 |
> |
AddFlag(to, FLAGS_KILLED); |
173 |
|
|
174 |
|
if (IsClient(from)) |
175 |
|
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
204 |
|
} |
205 |
|
|
206 |
|
/* |
232 |
– |
** slinkq_unblocked |
233 |
– |
** Called when a server control socket is ready for writing. |
234 |
– |
*/ |
235 |
– |
static void |
236 |
– |
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
237 |
– |
{ |
238 |
– |
ClearSlinkqBlocked(client_p); |
239 |
– |
send_queued_slink_write(client_p); |
240 |
– |
} |
241 |
– |
|
242 |
– |
/* |
207 |
|
** send_queued_write |
208 |
|
** This is called when there is a chance that some output would |
209 |
|
** be possible. This attempts to empty the send queue as far as |
245 |
|
errno = EWOULDBLOCK; |
246 |
|
case SSL_ERROR_SYSCALL: |
247 |
|
break; |
248 |
< |
|
248 |
> |
case SSL_ERROR_SSL: |
249 |
> |
if (errno == EAGAIN) |
250 |
> |
break; |
251 |
|
default: |
252 |
|
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
253 |
|
} |
257 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
258 |
|
|
259 |
|
if (retlen <= 0) |
294 |
– |
{ |
295 |
– |
#ifdef _WIN32 |
296 |
– |
errno = WSAGetLastError(); |
297 |
– |
#endif |
260 |
|
break; |
299 |
– |
} |
261 |
|
|
301 |
– |
execute_callback(iosend_cb, to, retlen, first->data); |
262 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
263 |
|
|
264 |
|
/* We have some data written .. update counters */ |
281 |
|
} |
282 |
|
} |
283 |
|
|
324 |
– |
/* |
325 |
– |
** send_queued_slink_write |
326 |
– |
** This is called when there is a chance the some output would |
327 |
– |
** be possible. This attempts to empty the send queue as far as |
328 |
– |
** possible, and then if any data is left, a write is rescheduled. |
329 |
– |
*/ |
330 |
– |
void |
331 |
– |
send_queued_slink_write(struct Client *to) |
332 |
– |
{ |
333 |
– |
int retlen; |
334 |
– |
|
335 |
– |
/* |
336 |
– |
** Once socket is marked dead, we cannot start writing to it, |
337 |
– |
** even if the error is removed... |
338 |
– |
*/ |
339 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
340 |
– |
return; /* no use calling send() now */ |
341 |
– |
|
342 |
– |
/* Next, lets try to write some data */ |
343 |
– |
if (to->localClient->slinkq != NULL) |
344 |
– |
{ |
345 |
– |
retlen = send(to->localClient->ctrlfd.fd, |
346 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
347 |
– |
to->localClient->slinkq_len, 0); |
348 |
– |
if (retlen < 0) |
349 |
– |
{ |
350 |
– |
/* If we have a fatal error */ |
351 |
– |
if (!ignoreErrno(errno)) |
352 |
– |
{ |
353 |
– |
dead_link_on_write(to, errno); |
354 |
– |
return; |
355 |
– |
} |
356 |
– |
} |
357 |
– |
else if (retlen == 0) |
358 |
– |
{ |
359 |
– |
/* 0 bytes is an EOF .. */ |
360 |
– |
dead_link_on_write(to, 0); |
361 |
– |
return; |
362 |
– |
} |
363 |
– |
else |
364 |
– |
{ |
365 |
– |
execute_callback(iosendctrl_cb, to, retlen, |
366 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
367 |
– |
to->localClient->slinkq_len -= retlen; |
368 |
– |
|
369 |
– |
assert(to->localClient->slinkq_len >= 0); |
370 |
– |
if (to->localClient->slinkq_len) |
371 |
– |
to->localClient->slinkq_ofs += retlen; |
372 |
– |
else |
373 |
– |
{ |
374 |
– |
to->localClient->slinkq_ofs = 0; |
375 |
– |
MyFree(to->localClient->slinkq); |
376 |
– |
to->localClient->slinkq = NULL; |
377 |
– |
} |
378 |
– |
} |
379 |
– |
|
380 |
– |
/* Finally, if we have any more data, reschedule a write */ |
381 |
– |
if (to->localClient->slinkq_len) |
382 |
– |
{ |
383 |
– |
SetSlinkqBlocked(to); |
384 |
– |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
385 |
– |
(PF *)slinkq_unblocked, (void *)to, 0); |
386 |
– |
} |
387 |
– |
} |
388 |
– |
} |
389 |
– |
|
284 |
|
/* send_queued_all() |
285 |
|
* |
286 |
|
* input - NONE |
351 |
|
*/ |
352 |
|
void |
353 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
354 |
< |
struct Channel *chptr, const char *command, |
354 |
> |
struct Channel *chptr, unsigned int type, |
355 |
|
const char *pattern, ...) |
356 |
|
{ |
357 |
< |
va_list args; |
357 |
> |
va_list alocal, aremote, auid; |
358 |
|
char local_buf[IRCD_BUFSIZE]; |
359 |
|
char remote_buf[IRCD_BUFSIZE]; |
360 |
|
char uid_buf[IRCD_BUFSIZE]; |
361 |
|
int local_len, remote_len, uid_len; |
362 |
< |
dlink_node *ptr; |
469 |
< |
dlink_node *ptr_next; |
470 |
< |
struct Client *target_p; |
362 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
363 |
|
|
364 |
|
if (IsServer(from)) |
365 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
366 |
< |
from->name, command, chptr->chname); |
365 |
> |
local_len = sprintf(local_buf, ":%s ", |
366 |
> |
from->name); |
367 |
|
else |
368 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
369 |
< |
from->name, from->username, from->host, |
370 |
< |
command, chptr->chname); |
371 |
< |
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
372 |
< |
from->name, command, chptr->chname); |
373 |
< |
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
374 |
< |
ID(from), command, chptr->chname); |
375 |
< |
|
376 |
< |
va_start(args, pattern); |
368 |
> |
local_len = sprintf(local_buf, ":%s!%s@%s ", |
369 |
> |
from->name, from->username, from->host); |
370 |
> |
remote_len = sprintf(remote_buf, ":%s ", |
371 |
> |
from->name); |
372 |
> |
uid_len = sprintf(uid_buf, ":%s ", |
373 |
> |
ID(from)); |
374 |
> |
|
375 |
> |
va_start(alocal, pattern); |
376 |
> |
va_start(aremote, pattern); |
377 |
> |
va_start(auid, pattern); |
378 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
379 |
< |
pattern, args); |
379 |
> |
pattern, alocal); |
380 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
381 |
< |
pattern, args); |
381 |
> |
pattern, aremote); |
382 |
|
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
383 |
< |
args); |
384 |
< |
va_end(args); |
383 |
> |
auid); |
384 |
> |
va_end(auid); |
385 |
> |
va_end(aremote); |
386 |
> |
va_end(alocal); |
387 |
|
|
388 |
|
++current_serial; |
389 |
|
|
390 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
391 |
|
{ |
392 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
393 |
< |
assert(target_p != NULL); |
392 |
> |
struct Membership *ms = ptr->data; |
393 |
> |
struct Client *target_p = ms->client_p; |
394 |
|
|
395 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
395 |
> |
assert(IsClient(target_p)); |
396 |
> |
|
397 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
398 |
> |
continue; |
399 |
> |
|
400 |
> |
if (type != 0 && (ms->flags & type) == 0) |
401 |
|
continue; |
402 |
|
|
403 |
< |
if (MyClient(target_p)) |
403 |
> |
if (MyConnect(target_p)) |
404 |
|
{ |
405 |
< |
if (target_p->serial != current_serial) |
405 |
> |
if (target_p->localClient->serial != current_serial) |
406 |
|
{ |
407 |
|
send_message(target_p, local_buf, local_len); |
408 |
< |
target_p->serial = current_serial; |
408 |
> |
target_p->localClient->serial = current_serial; |
409 |
|
} |
410 |
|
} |
411 |
|
else |
413 |
|
/* Now check whether a message has been sent to this |
414 |
|
* remote link already |
415 |
|
*/ |
416 |
< |
if (target_p->from->serial != current_serial) |
416 |
> |
if (target_p->from->localClient->serial != current_serial) |
417 |
|
{ |
418 |
|
if (IsCapable(target_p->from, CAP_TS6)) |
419 |
|
send_message_remote(target_p->from, from, uid_buf, uid_len); |
420 |
|
else |
421 |
|
send_message_remote(target_p->from, from, remote_buf, remote_len); |
422 |
< |
target_p->from->serial = current_serial; |
422 |
> |
target_p->from->localClient->serial = current_serial; |
423 |
|
} |
424 |
|
} |
425 |
|
} |
428 |
|
/* sendto_server() |
429 |
|
* |
430 |
|
* inputs - pointer to client to NOT send to |
431 |
< |
* - pointer to source client required by LL (if any) |
532 |
< |
* - pointer to channel required by LL (if any) |
431 |
> |
* - pointer to channel |
432 |
|
* - caps or'd together which must ALL be present |
433 |
|
* - caps or'd together which must ALL NOT be present |
535 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
434 |
|
* - printf style format string |
435 |
|
* - args to format string |
436 |
|
* output - NONE |
437 |
|
* side effects - Send a message to all connected servers, except the |
438 |
|
* client 'one' (if non-NULL), as long as the servers |
439 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
542 |
– |
* If the server is a lazylink client, then it must know |
543 |
– |
* about source_p if non-NULL (unless LL_ICLIENT is specified, |
544 |
– |
* when source_p will be introduced where required) and |
545 |
– |
* chptr if non-NULL (unless LL_ICHANNEL is specified, when |
546 |
– |
* chptr will be introduced where required). |
547 |
– |
* Note: nothing will be introduced to a LazyLeaf unless |
548 |
– |
* the message is actually sent. |
440 |
|
* |
441 |
|
* This function was written in an attempt to merge together the other |
442 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
444 |
|
* -davidt |
445 |
|
*/ |
446 |
|
void |
447 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
448 |
< |
struct Channel *chptr, unsigned long caps, |
449 |
< |
unsigned long nocaps, unsigned long llflags, |
447 |
> |
sendto_server(struct Client *one, |
448 |
> |
const unsigned int caps, |
449 |
> |
const unsigned int nocaps, |
450 |
|
const char *format, ...) |
451 |
|
{ |
452 |
|
va_list args; |
453 |
< |
struct Client *client_p; |
563 |
< |
dlink_node *ptr; |
453 |
> |
dlink_node *ptr = NULL; |
454 |
|
char buffer[IRCD_BUFSIZE]; |
455 |
< |
int len; |
566 |
< |
|
567 |
< |
if (chptr != NULL) |
568 |
< |
{ |
569 |
< |
if (chptr->chname[0] != '#') |
570 |
< |
return; |
571 |
< |
} |
455 |
> |
int len = 0; |
456 |
|
|
457 |
|
va_start(args, format); |
458 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
460 |
|
|
461 |
|
DLINK_FOREACH(ptr, serv_list.head) |
462 |
|
{ |
463 |
< |
client_p = ptr->data; |
463 |
> |
struct Client *client_p = ptr->data; |
464 |
|
|
465 |
|
/* If dead already skip */ |
466 |
|
if (IsDead(client_p)) |
475 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
476 |
|
continue; |
477 |
|
|
594 |
– |
if (ServerInfo.hub && IsCapable(client_p, CAP_LL)) |
595 |
– |
{ |
596 |
– |
/* check LL channel */ |
597 |
– |
if (chptr != NULL && |
598 |
– |
((chptr->lazyLinkChannelExists & |
599 |
– |
client_p->localClient->serverMask) == 0)) |
600 |
– |
{ |
601 |
– |
/* Only introduce the channel if we really will send this message */ |
602 |
– |
if (!(llflags & LL_ICLIENT) && source_p && |
603 |
– |
((source_p->lazyLinkClientExists & |
604 |
– |
client_p->localClient->serverMask) == 0)) |
605 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
606 |
– |
|
607 |
– |
if (llflags & LL_ICHAN) |
608 |
– |
burst_channel(client_p, chptr); |
609 |
– |
else |
610 |
– |
continue; /* we can't introduce the unknown chptr, skip */ |
611 |
– |
} |
612 |
– |
/* check LL client */ |
613 |
– |
if (source_p && |
614 |
– |
((source_p->lazyLinkClientExists & |
615 |
– |
client_p->localClient->serverMask) == 0)) |
616 |
– |
{ |
617 |
– |
if (llflags & LL_ICLIENT) |
618 |
– |
client_burst_if_needed(client_p,source_p); |
619 |
– |
else |
620 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
621 |
– |
} |
622 |
– |
} |
478 |
|
send_message(client_p, buffer, len); |
479 |
|
} |
480 |
|
} |
489 |
|
* used by m_nick.c and exit_one_client. |
490 |
|
*/ |
491 |
|
void |
492 |
< |
sendto_common_channels_local(struct Client *user, int touser, |
492 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
493 |
|
const char *pattern, ...) |
494 |
|
{ |
495 |
|
va_list args; |
512 |
|
chptr = ((struct Membership *) cptr->data)->chptr; |
513 |
|
assert(chptr != NULL); |
514 |
|
|
515 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
515 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
516 |
|
{ |
517 |
|
ms = uptr->data; |
518 |
|
target_p = ms->client_p; |
519 |
|
assert(target_p != NULL); |
520 |
|
|
521 |
< |
if (target_p == user || IsDefunct(target_p) || |
522 |
< |
target_p->serial == current_serial) |
521 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
522 |
> |
target_p->localClient->serial == current_serial) |
523 |
> |
continue; |
524 |
> |
|
525 |
> |
if (HasCap(target_p, cap) != cap) |
526 |
|
continue; |
527 |
|
|
528 |
< |
target_p->serial = current_serial; |
528 |
> |
target_p->localClient->serial = current_serial; |
529 |
|
send_message(target_p, buffer, len); |
530 |
|
} |
531 |
|
} |
532 |
|
|
533 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
534 |
< |
user->serial != current_serial) |
535 |
< |
send_message(user, buffer, len); |
534 |
> |
user->localClient->serial != current_serial) |
535 |
> |
if (HasCap(target_p, cap) == cap) |
536 |
> |
send_message(user, buffer, len); |
537 |
|
} |
538 |
|
|
539 |
|
/* sendto_channel_local() |
561 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
562 |
|
va_end(args); |
563 |
|
|
564 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
564 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
565 |
|
{ |
566 |
|
ms = ptr->data; |
567 |
|
target_p = ms->client_p; |
569 |
|
if (type != 0 && (ms->flags & type) == 0) |
570 |
|
continue; |
571 |
|
|
572 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
572 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
573 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
574 |
|
continue; |
575 |
|
|
576 |
|
send_message(target_p, buffer, len); |
590 |
|
* WARNING - +D clients are omitted |
591 |
|
*/ |
592 |
|
void |
593 |
< |
sendto_channel_local_butone(struct Client *one, int type, |
593 |
> |
sendto_channel_local_butone(struct Client *one, int type, unsigned int cap, |
594 |
|
struct Channel *chptr, const char *pattern, ...) |
595 |
|
{ |
596 |
|
va_list args; |
604 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
605 |
|
va_end(args); |
606 |
|
|
607 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
607 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
608 |
|
{ |
609 |
|
ms = ptr->data; |
610 |
|
target_p = ms->client_p; |
612 |
|
if (type != 0 && (ms->flags & type) == 0) |
613 |
|
continue; |
614 |
|
|
615 |
< |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
615 |
> |
if (!MyConnect(target_p) || target_p == one || |
616 |
> |
IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
617 |
|
continue; |
618 |
+ |
|
619 |
+ |
if (HasCap(target_p, cap) != cap) |
620 |
+ |
continue; |
621 |
|
send_message(target_p, buffer, len); |
622 |
|
} |
623 |
|
} |
635 |
|
* remote to this server. |
636 |
|
*/ |
637 |
|
void |
638 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
639 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
638 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
639 |
> |
const unsigned int caps, const unsigned int nocaps, |
640 |
> |
struct Channel *chptr, const char *pattern, ...) |
641 |
|
{ |
642 |
|
va_list args; |
643 |
|
char buffer[IRCD_BUFSIZE]; |
650 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
651 |
|
va_end(args); |
652 |
|
|
653 |
+ |
++current_serial; |
654 |
+ |
|
655 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
656 |
|
{ |
657 |
|
ms = ptr->data; |
668 |
|
((target_p->from->localClient->caps & caps) != caps) || |
669 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
670 |
|
continue; |
671 |
< |
|
672 |
< |
send_message(target_p, buffer, len); |
671 |
> |
if (target_p->from->localClient->serial != current_serial) |
672 |
> |
{ |
673 |
> |
send_message(target_p, buffer, len); |
674 |
> |
target_p->from->localClient->serial = current_serial; |
675 |
> |
} |
676 |
|
} |
677 |
|
} |
678 |
|
|
697 |
|
match_it(const struct Client *one, const char *mask, int what) |
698 |
|
{ |
699 |
|
if (what == MATCH_HOST) |
700 |
< |
return(match(mask, one->host)); |
700 |
> |
return !match(mask, one->host); |
701 |
|
|
702 |
< |
return(match(mask, one->servptr->name)); |
702 |
> |
return !match(mask, one->servptr->name); |
703 |
|
} |
704 |
|
|
705 |
|
/* sendto_match_butone() |
713 |
|
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
714 |
|
int what, const char *pattern, ...) |
715 |
|
{ |
716 |
< |
va_list args; |
716 |
> |
va_list alocal, aremote; |
717 |
|
struct Client *client_p; |
718 |
|
dlink_node *ptr, *ptr_next; |
719 |
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
720 |
< |
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
721 |
< |
from->username, from->host); |
722 |
< |
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
720 |
> |
int local_len = sprintf(local_buf, ":%s!%s@%s ", from->name, |
721 |
> |
from->username, from->host); |
722 |
> |
int remote_len = sprintf(remote_buf, ":%s ", from->name); |
723 |
|
|
724 |
< |
va_start(args, pattern); |
724 |
> |
va_start(alocal, pattern); |
725 |
> |
va_start(aremote, pattern); |
726 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
727 |
< |
pattern, args); |
727 |
> |
pattern, alocal); |
728 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
729 |
< |
pattern, args); |
730 |
< |
va_end(args); |
729 |
> |
pattern, aremote); |
730 |
> |
va_end(aremote); |
731 |
> |
va_end(alocal); |
732 |
|
|
733 |
|
/* scan the local clients */ |
734 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
797 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
798 |
|
va_end(args); |
799 |
|
|
800 |
< |
current_serial++; |
800 |
> |
++current_serial; |
801 |
|
|
802 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
803 |
|
{ |
807 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
808 |
|
continue; |
809 |
|
|
810 |
< |
if (target_p->from->serial == current_serial) |
810 |
> |
if (target_p->from->localClient->serial == current_serial) |
811 |
|
continue; |
812 |
|
|
813 |
< |
if (match(mask, target_p->name)) |
813 |
> |
if (!match(mask, target_p->name)) |
814 |
|
{ |
815 |
|
/* |
816 |
|
* if we set the serial here, then we'll never do a |
817 |
|
* match() again, if !IsCapable() |
818 |
|
*/ |
819 |
< |
target_p->from->serial = current_serial; |
819 |
> |
target_p->from->localClient->serial = current_serial; |
820 |
|
found++; |
821 |
|
|
822 |
|
if (!IsCapable(target_p->from, cap)) |
853 |
|
if (IsServer(from)) |
854 |
|
{ |
855 |
|
if (IsCapable(to, CAP_TS6) && HasID(from)) |
856 |
< |
len = ircsprintf(buffer, ":%s ", from->id); |
856 |
> |
len = sprintf(buffer, ":%s ", from->id); |
857 |
|
else |
858 |
< |
len = ircsprintf(buffer, ":%s ", from->name); |
858 |
> |
len = sprintf(buffer, ":%s ", from->name); |
859 |
|
} |
860 |
|
else |
861 |
< |
len = ircsprintf(buffer, ":%s!%s@%s ", |
861 |
> |
len = sprintf(buffer, ":%s!%s@%s ", |
862 |
|
from->name, from->username, from->host); |
863 |
|
} |
864 |
< |
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
864 |
> |
else len = sprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
865 |
|
|
866 |
|
va_start(args, pattern); |
867 |
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
882 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
883 |
|
*/ |
884 |
|
void |
885 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
885 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
886 |
|
{ |
887 |
< |
struct Client *client_p; |
887 |
> |
const char *ntype = NULL; |
888 |
> |
dlink_node *ptr = NULL; |
889 |
|
char nbuf[IRCD_BUFSIZE]; |
1017 |
– |
dlink_node *ptr; |
890 |
|
va_list args; |
891 |
|
|
892 |
|
va_start(args, pattern); |
893 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
893 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
894 |
|
va_end(args); |
895 |
|
|
896 |
+ |
switch (type) |
897 |
+ |
{ |
898 |
+ |
case SEND_NOTICE: |
899 |
+ |
ntype = "Notice"; |
900 |
+ |
break; |
901 |
+ |
case SEND_GLOBAL: |
902 |
+ |
ntype = "Global"; |
903 |
+ |
break; |
904 |
+ |
case SEND_LOCOPS: |
905 |
+ |
ntype = "LocOps"; |
906 |
+ |
break; |
907 |
+ |
default: |
908 |
+ |
assert(0); |
909 |
+ |
} |
910 |
+ |
|
911 |
|
DLINK_FOREACH(ptr, oper_list.head) |
912 |
|
{ |
913 |
< |
client_p = ptr->data; |
914 |
< |
assert(client_p->umodes & UMODE_OPER); |
913 |
> |
struct Client *client_p = ptr->data; |
914 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
915 |
|
|
916 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
917 |
< |
* If we're sending it to admins, and theyre not, skip. |
916 |
> |
/* |
917 |
> |
* If we're sending it to opers and they're an admin, skip. |
918 |
> |
* If we're sending it to admins, and they're not, skip. |
919 |
|
*/ |
920 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
921 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
920 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
921 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
922 |
|
continue; |
923 |
|
|
924 |
< |
if (client_p->umodes & flags) |
925 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
926 |
< |
me.name, client_p->name, nbuf); |
924 |
> |
if (HasUMode(client_p, flags)) |
925 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
926 |
> |
me.name, client_p->name, ntype, nbuf); |
927 |
|
} |
928 |
|
} |
929 |
|
|
939 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
940 |
|
const char *pattern, ...) |
941 |
|
{ |
942 |
< |
struct Client *client_p; |
1055 |
< |
dlink_node *ptr; |
942 |
> |
dlink_node *ptr = NULL; |
943 |
|
va_list args; |
944 |
|
char buffer[IRCD_BUFSIZE]; |
945 |
|
int len; |
946 |
|
|
947 |
|
if (IsClient(source_p)) |
948 |
< |
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
949 |
< |
source_p->name, source_p->username, source_p->host); |
948 |
> |
len = sprintf(buffer, ":%s!%s@%s WALLOPS :", |
949 |
> |
source_p->name, source_p->username, source_p->host); |
950 |
|
else |
951 |
< |
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
951 |
> |
len = sprintf(buffer, ":%s WALLOPS :", source_p->name); |
952 |
|
|
953 |
|
va_start(args, pattern); |
954 |
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
956 |
|
|
957 |
|
DLINK_FOREACH(ptr, oper_list.head) |
958 |
|
{ |
959 |
< |
client_p = ptr->data; |
959 |
> |
struct Client *client_p = ptr->data; |
960 |
|
assert(client_p->umodes & UMODE_OPER); |
961 |
|
|
962 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
962 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
963 |
|
send_message(client_p, buffer, len); |
964 |
|
} |
965 |
|
} |
975 |
|
ts_warn(const char *pattern, ...) |
976 |
|
{ |
977 |
|
va_list args; |
978 |
< |
char buffer[LOG_BUFSIZE]; |
978 |
> |
char buffer[IRCD_BUFSIZE]; |
979 |
|
static time_t last = 0; |
980 |
|
static int warnings = 0; |
981 |
|
|
998 |
|
} |
999 |
|
|
1000 |
|
va_start(args, pattern); |
1001 |
< |
vsprintf_irc(buffer, pattern, args); |
1001 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
1002 |
|
va_end(args); |
1003 |
|
|
1004 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
1005 |
< |
ilog(L_CRIT, "%s", buffer); |
1004 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
1005 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
1006 |
|
} |
1007 |
|
|
1008 |
|
/* kill_client() |
1026 |
|
if (IsDead(client_p)) |
1027 |
|
return; |
1028 |
|
|
1029 |
< |
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
1030 |
< |
ID_or_name(diedie, client_p)); |
1029 |
> |
len = sprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
1030 |
> |
ID_or_name(diedie, client_p)); |
1031 |
|
|
1032 |
|
va_start(args, pattern); |
1033 |
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
1052 |
|
{ |
1053 |
|
va_list args; |
1054 |
|
int have_uid = 0; |
1055 |
< |
struct Client *client_p; |
1169 |
< |
dlink_node *ptr; |
1055 |
> |
dlink_node *ptr = NULL; |
1056 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1057 |
< |
int len_uid = 0, len_nick; |
1057 |
> |
int len_uid = 0, len_nick = 0; |
1058 |
|
|
1059 |
< |
va_start(args, pattern); |
1174 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1059 |
> |
if (HasID(source_p)) |
1060 |
|
{ |
1061 |
|
have_uid = 1; |
1062 |
< |
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1062 |
> |
va_start(args, pattern); |
1063 |
> |
len_uid = sprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1064 |
|
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1065 |
|
args); |
1066 |
+ |
va_end(args); |
1067 |
|
} |
1068 |
< |
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1068 |
> |
|
1069 |
> |
va_start(args, pattern); |
1070 |
> |
len_nick = sprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1071 |
|
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1072 |
|
args); |
1073 |
|
va_end(args); |
1074 |
|
|
1075 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1076 |
|
{ |
1077 |
< |
client_p = ptr->data; |
1077 |
> |
struct Client *client_p = ptr->data; |
1078 |
|
|
1079 |
|
if (one != NULL && (client_p == one->from)) |
1080 |
|
continue; |
1081 |
|
if (IsDefunct(client_p)) |
1082 |
|
continue; |
1083 |
|
|
1084 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
1085 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
1086 |
< |
!ServerInfo.hub || |
1087 |
< |
(source_p->lazyLinkClientExists & client_p->localClient->serverMask)) |
1199 |
< |
{ |
1200 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1201 |
< |
send_message(client_p, buf_uid, len_uid); |
1202 |
< |
else |
1203 |
< |
send_message(client_p, buf_nick, len_nick); |
1204 |
< |
} |
1084 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1085 |
> |
send_message(client_p, buf_uid, len_uid); |
1086 |
> |
else |
1087 |
> |
send_message(client_p, buf_nick, len_nick); |
1088 |
|
} |
1089 |
|
} |