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.
This commit is contained in:
Simon Arlott 2016-11-23 21:43:33 +00:00
parent 2d8d5b058b
commit e2d5ffd5dd
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
3 changed files with 47 additions and 11 deletions

View file

@ -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);

View file

@ -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

View file

@ -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)
{