From 984d80c98804178206fec4787f53d98342cfb82b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 1 Mar 2015 00:44:34 -0600 Subject: [PATCH] cap-notify: add sendto_local_clients_with_capability() (ref #84) --- include/send.h | 1 + src/send.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/send.h b/include/send.h index b799a0bf..5b1a0772 100644 --- a/include/send.h +++ b/include/send.h @@ -81,6 +81,7 @@ extern void sendto_monitor(struct monitor *monptr, const char *, ...) AFP(2, 3); extern void sendto_anywhere(struct Client *, struct Client *, const char *, const char *, ...) AFP(4, 5); +extern void sendto_local_clients_with_capability(int cap, const char *pattern, ...) AFP(2, 3); extern void sendto_realops_snomask(int, int, const char *, ...) AFP(3, 4); extern void sendto_realops_snomask_from(int, int, struct Client *, const char *, ...) AFP(4, 5); diff --git a/src/send.c b/src/send.c index 062150c1..cbc4575f 100644 --- a/src/send.c +++ b/src/send.c @@ -1021,6 +1021,44 @@ sendto_match_servs(struct Client *source_p, const char *mask, int cap, rb_linebuf_donebuf(&rb_linebuf_id); } +/* sendto_local_clients_with_capability() + * + * inputs - caps needed, pattern, va_args + * outputs - + * side effects - message is sent to matching local clients with caps. + */ +void +sendto_local_clients_with_capability(int cap, const char *pattern, ...) +{ + va_list args; + rb_dlink_node *ptr; + struct Client *target_p; + buf_head_t linebuf; + + rb_linebuf_newbuf(&linebuf); + + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); + + current_serial++; + + RB_DLINK_FOREACH(ptr, lclient_list.head) + { + target_p = ptr->data; + + if(IsIOError(target_p) || + target_p->serial == current_serial || + !IsCapable(target_p, cap)) + continue; + + target_p->serial = current_serial; + send_linebuf(target_p, &linebuf); + } + + rb_linebuf_donebuf(&linebuf); +} + /* sendto_monitor() * * inputs - monitor nick to send to, format, va_args