From e2d5ffd5ddf2495e0cb019183a4f1fa2bd3aca58 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Wed, 23 Nov 2016 21:43:33 +0000 Subject: [PATCH] echo-message should work for privmsg/notice to another user Build the same message but send it to the local client first, so that the echo-message capability works. But don't do it when sending a message to yourself. --- include/send.h | 2 ++ ircd/send.c | 53 +++++++++++++++++++++++++++++++--------- modules/core/m_message.c | 3 +++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/send.h b/include/send.h index 695ec563..4af7dab9 100644 --- a/include/send.h +++ b/include/send.h @@ -78,6 +78,8 @@ 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_anywhere_echo(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); diff --git a/ircd/send.c b/ircd/send.c index 4e593a26..adb2dc20 100644 --- a/ircd/send.c +++ b/ircd/send.c @@ -30,6 +30,7 @@ #include "match.h" #include "ircd.h" #include "numeric.h" +#include "s_assert.h" #include "s_serv.h" #include "s_conf.h" #include "s_newconf.h" @@ -1176,15 +1177,16 @@ sendto_monitor(struct monitor *monptr, const char *pattern, ...) rb_linebuf_donebuf(&linebuf); } -/* sendto_anywhere() +/* _sendto_anywhere() * - * inputs - target, source, va_args + * inputs - real_target, target, source, va_args * outputs - - * side effects - client is sent message with correct prefix. + * side effects - client is sent message/own message with correct prefix. */ -void -sendto_anywhere(struct Client *target_p, struct Client *source_p, - const char *command, const char *pattern, ...) +static void +_sendto_anywhere(struct Client *dest_p, struct Client *target_p, + struct Client *source_p, const char *command, + const char *pattern, ...) { va_list args; buf_head_t linebuf; @@ -1193,7 +1195,7 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p, va_start(args, pattern); - if(MyClient(target_p)) + if(MyClient(dest_p)) { if(IsServer(source_p)) rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", @@ -1206,7 +1208,7 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p, build_msgbuf_from(&msgbuf, source_p, command); msgbuf.target = target_p->name; - linebuf_put_msgvbuf(&msgbuf, &linebuf, target_p->localClient->caps, pattern, &args); + linebuf_put_msgvbuf(&msgbuf, &linebuf, dest_p->localClient->caps, pattern, &args); } } else @@ -1215,14 +1217,43 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p, get_id(target_p, target_p)); va_end(args); - if(MyClient(target_p)) - _send_linebuf(target_p, &linebuf); + if(MyClient(dest_p)) + _send_linebuf(dest_p, &linebuf); else - send_linebuf_remote(target_p, source_p, &linebuf); + send_linebuf_remote(dest_p, source_p, &linebuf); rb_linebuf_donebuf(&linebuf); } +/* sendto_anywhere() + * + * inputs - target, source, va_args + * outputs - + * side effects - client is sent message with correct prefix. + */ +void +sendto_anywhere(struct Client *target_p, struct Client *source_p, + const char *command, const char *pattern, ...) +{ + _sendto_anywhere(target_p, target_p, source_p, command, pattern); +} + +/* sendto_anywhere_echo() + * + * inputs - target, source, va_args + * outputs - + * side effects - client is sent own message with correct prefix. + */ +void +sendto_anywhere_echo(struct Client *target_p, struct Client *source_p, + const char *command, const char *pattern, ...) +{ + s_assert(MyClient(source_p)); + s_assert(!IsServer(source_p)); + + _sendto_anywhere(source_p, target_p, source_p, command, pattern); +} + /* sendto_realops_snomask() * * inputs - snomask needed, level (opers/admin), va_args diff --git a/modules/core/m_message.c b/modules/core/m_message.c index afc8e04f..3f188d46 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -776,6 +776,9 @@ msg_client(enum message_type msgtype, if (do_floodcount && flood_attack_client(msgtype, source_p, target_p)) return; + + if (IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p != source_p) + sendto_anywhere_echo(target_p, source_p, cmdname[msgtype], ":%s", text); } else if(source_p->from == target_p->from) {