degesch; fix handling of CTCP requests

This commit is contained in:
Přemysl Eric Janouch 2015-08-06 23:00:16 +02:00
parent 955b3728a3
commit 1dd464f35c
1 changed files with 13 additions and 9 deletions

View File

@ -5471,27 +5471,31 @@ irc_handle_ctcp_request (struct server *s,
{
const char *target = msg->params.vector[0];
if (irc_is_this_us (s, msg->prefix))
log_ctcp_query (s, target, chunk->tag.str);
{
if (s->cap_echo_message)
log_ctcp_query (s, target, chunk->tag.str);
if (!irc_is_this_us (s, target))
return;
}
// TODO: eventually "requested by #n (to ##channel)"
log_server_status (s, s->buffer,
"CTCP requested by #n: #S", msg->prefix, chunk->tag.str);
char *recipient = irc_is_channel (s, target)
? irc_cut_nickname (msg->prefix)
: xstrdup (target);
char *nickname = irc_cut_nickname (msg->prefix);
if (!strcmp (chunk->tag.str, "CLIENTINFO"))
irc_send_ctcp_reply (s, recipient, "CLIENTINFO %s %s %s %s",
irc_send_ctcp_reply (s, nickname, "CLIENTINFO %s %s %s %s",
"PING", "VERSION", "TIME", "CLIENTINFO");
else if (!strcmp (chunk->tag.str, "PING"))
irc_send_ctcp_reply (s, recipient, "PING %s", chunk->text.str);
irc_send_ctcp_reply (s, nickname, "PING %s", chunk->text.str);
else if (!strcmp (chunk->tag.str, "VERSION"))
{
struct utsname info;
if (uname (&info))
LOG_LIBC_FAILURE ("uname");
else
irc_send_ctcp_reply (s, recipient, "VERSION %s %s on %s %s",
irc_send_ctcp_reply (s, nickname, "VERSION %s %s on %s %s",
PROGRAM_NAME, PROGRAM_VERSION, info.sysname, info.machine);
}
else if (!strcmp (chunk->tag.str, "TIME"))
@ -5500,10 +5504,10 @@ irc_handle_ctcp_request (struct server *s,
if (!ctime_now (buf))
LOG_LIBC_FAILURE ("asctime_r");
else
irc_send_ctcp_reply (s, recipient, "TIME %s", buf);
irc_send_ctcp_reply (s, nickname, "TIME %s", buf);
}
free (recipient);
free (nickname);
}
static void