degesch: send after-connect joins more cleverly

This commit is contained in:
Přemysl Eric Janouch 2015-08-10 07:32:03 +02:00
parent 628facf286
commit 5dda5661ae
1 changed files with 26 additions and 4 deletions

View File

@ -3897,18 +3897,40 @@ on_irc_autojoin_timeout (void *user_data)
{ {
struct server *s = user_data; struct server *s = user_data;
// TODO: split autojoin at commas and make a joined set with regular rejoins // Since we may not have information from RPL_ISUPPORT yet,
// it's our safest bet to send the channels one at a time
struct str_map joins_sent;
str_map_init (&joins_sent);
// We don't know the casemapping yet either, however ASCII should do
joins_sent.key_xfrm = tolower_ascii_strxfrm;
// First join autojoin channels in their given order
const char *autojoin = get_config_string (s->config, "autojoin"); const char *autojoin = get_config_string (s->config, "autojoin");
if (autojoin) if (autojoin)
irc_send (s, "JOIN :%s", autojoin); {
struct str_vector v;
str_vector_init (&v);
split_str (autojoin, ',', &v);
for (size_t i = 0; i < v.len; i++)
{
irc_send (s, "JOIN :%s", v.vector[i]);
str_map_set (&joins_sent, v.vector[i], (void *) 1);
}
str_vector_free (&v);
}
// Then also rejoin any channels from the last disconnect
struct str_map_iter iter; struct str_map_iter iter;
str_map_iter_init (&iter, &s->irc_channels); str_map_iter_init (&iter, &s->irc_channels);
struct channel *channel; struct channel *channel;
while ((channel = str_map_iter_next (&iter))) while ((channel = str_map_iter_next (&iter)))
if (!channel->left_manually) if (!channel->left_manually
&& !str_map_find (&joins_sent, channel->name))
irc_send (s, "JOIN :%s", channel->name); irc_send (s, "JOIN :%s", channel->name);
str_map_free (&joins_sent);
} }
// --- Server I/O -------------------------------------------------------------- // --- Server I/O --------------------------------------------------------------