degesch: halfplement RPL_NAMES processing

This commit is contained in:
Přemysl Eric Janouch 2015-05-24 21:56:46 +02:00
parent 4b02030c80
commit 11977cb0b0
1 changed files with 49 additions and 13 deletions

View File

@ -4386,6 +4386,50 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
str_vector_free (&v); str_vector_free (&v);
} }
static void
irc_handle_rpl_namreply (struct server *s, const struct irc_message *msg)
{
if (msg->params.len < 4)
return;
const char *channel_name = msg->params.vector[2];
const char *nicks = msg->params.vector[3];
// Just push the nicknames to a string vector for later processing
struct channel *channel = str_map_find (&s->irc_channels, channel_name);
if (channel)
split_str_ignore_empty (nicks, ' ', &channel->names_buf);
}
static void
irc_process_names (struct server *s, struct channel *channel)
{
// TODO: overwrite users with "channel->names_buf", which contains
// [@+]-prefixed nicknames; take care to combine channel user modes
str_vector_reset (&channel->names_buf);
}
static void
irc_handle_rpl_endofnames (struct server *s, const struct irc_message *msg)
{
if (msg->params.len < 2)
return;
const char *channel_name = msg->params.vector[1];
struct channel *channel = str_map_find (&s->irc_channels, channel_name);
if (!strcmp (channel_name, "*"))
{
struct str_map_iter iter;
str_map_iter_init (&iter, &s->irc_channels);
struct channel *channel;
while ((channel = str_map_iter_next (&iter)))
irc_process_names (s, channel);
}
else if (channel)
irc_process_names (s, channel);
}
static void static void
irc_process_numeric (struct server *s, irc_process_numeric (struct server *s,
const struct irc_message *msg, unsigned long numeric) const struct irc_message *msg, unsigned long numeric)
@ -4425,16 +4469,11 @@ irc_process_numeric (struct server *s,
// TODO: initialize key_strxfrm according to server properties; // TODO: initialize key_strxfrm according to server properties;
// note that collisions may arise on reconnecting // note that collisions may arise on reconnecting
break; break;
case IRC_RPL_USERHOST:
irc_handle_rpl_userhost (s, msg); case IRC_RPL_USERHOST: irc_handle_rpl_userhost (s, msg); break;
break; case IRC_RPL_NAMREPLY: irc_handle_rpl_namreply (s, msg); break;
case IRC_RPL_NAMREPLY: case IRC_RPL_ENDOFNAMES: irc_handle_rpl_endofnames (s, msg); break;
// TODO: find the channel and if found, push nicks to names_buf
break;
case IRC_RPL_ENDOFNAMES:
// TODO: find the channel and if found, overwrite users;
// however take care to combine channel user modes
break;
case IRC_ERR_NICKNAMEINUSE: case IRC_ERR_NICKNAMEINUSE:
// TODO: if (state == IRC_CONNECTED), use a different nick; // TODO: if (state == IRC_CONNECTED), use a different nick;
// either use a number suffix, or accept commas in "nickname" config // either use a number suffix, or accept commas in "nickname" config
@ -5786,9 +5825,6 @@ g_command_handlers[] =
{ "list", "List channels and their topic", { "list", "List channels and their topic",
"[<channel>[,<channel>...]] [<server>]", "[<channel>[,<channel>...]] [<server>]",
handle_command_list }, handle_command_list },
// XXX: for NAMES with no arguments, how do we tell the end of it all?
// Maybe we just surf through all channels and process the lists
// as they are.
{ "names", "List users on channel", { "names", "List users on channel",
"[<channel>[,<channel>...]]", "[<channel>[,<channel>...]]",
handle_command_names }, handle_command_names },