degesch: add support for IRCv3.2 echo-message

This commit is contained in:
Přemysl Eric Janouch 2015-06-20 21:38:04 +02:00
parent 935d671a57
commit 974ce75a59
1 changed files with 28 additions and 8 deletions

View File

@ -1060,6 +1060,8 @@ struct server
struct str irc_user_mode; ///< Our current user modes
char *irc_user_host; ///< Our current user@host
bool cap_echo_message; ///< Whether the server echos messages
// Server-specific information (from RPL_ISUPPORT):
/// Convert an IRC identifier character to lower-case
@ -3207,6 +3209,7 @@ on_irc_disconnected (struct server *s)
s->irc_user_host = NULL;
// TODO: reset RPL_ISUPPORT information
s->cap_echo_message = false;
// Take any relevant actions
if (s->ctx->quitting)
@ -3830,14 +3833,17 @@ irc_get_buffer_for_message (struct server *s,
}
else if (!buffer)
{
// Implying that the target is us
// Don't make user buffers for servers (they can send NOTICEs)
if (!irc_find_userhost (msg->prefix))
return s->buffer;
char *nickname = irc_cut_nickname (msg->prefix);
buffer = irc_get_or_make_user_buffer (s, nickname);
if (irc_is_this_us (s, target))
buffer = irc_get_or_make_user_buffer (s, nickname);
// With the IRCv3.2 echo-message capability, we can receive messages
// as they are delivired to the target; in that case, check the origin
else if (soft_assert (irc_is_this_us (s, nickname)))
buffer = irc_get_or_make_user_buffer (s, target);
free (nickname);
}
return buffer;
@ -4066,12 +4072,24 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
split_str_ignore_empty (msg->params.vector[2], ' ', &v);
const char *subcommand = msg->params.vector[1];
if (!strcasecmp_ascii (subcommand, "ACK")
|| !strcasecmp_ascii (subcommand, "NAK"))
if (!strcasecmp_ascii (subcommand, "ACK"))
{
// So far we don't need to take any other actions
for (size_t i = 0; i < v.len; i++)
{
const char *cap = v.vector[i];
bool active = true;
if (*cap == '-')
{
active = false;
cap++;
}
if (!strcasecmp_ascii (cap, "echo-message"))
s->cap_echo_message = active;
}
irc_send (s, "CAP END");
}
else if (!strcasecmp_ascii (subcommand, "NAK"))
irc_send (s, "CAP END");
else if (!strcasecmp_ascii (subcommand, "LS"))
{
struct str_vector chosen;
@ -4082,7 +4100,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
{
const char *cap = v.vector[i];
if (!strcasecmp_ascii (cap, "multi-prefix")
|| !strcasecmp_ascii (cap, "invite-notify"))
|| !strcasecmp_ascii (cap, "invite-notify")
|| !strcasecmp_ascii (cap, "echo-message"))
str_vector_add (&chosen, cap);
}
@ -5475,7 +5494,8 @@ send_autosplit_message (struct server *s, struct send_autosplit_args a)
{
irc_send (s, "%s %s :%s%s%s", a.command, a.target,
a.prefix, lines.vector[i], a.suffix);
a.logger (s, &a, buffer, lines.vector[i]);
if (!s->cap_echo_message)
a.logger (s, &a, buffer, lines.vector[i]);
}
end:
str_vector_free (&lines);