Various fixes related to channel modes

Bugs unnoticed for so long.
This commit is contained in:
2016-12-30 07:49:10 +01:00
parent eb70bf3fbc
commit 8e668ff31a
3 changed files with 39 additions and 13 deletions

View File

@@ -2360,7 +2360,7 @@ static struct config_schema g_config_server[] =
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on" },
{ .name = "autojoin",
.comment = "Channels to join on start",
.comment = "Channels to join on start (e.g. \"#abc,#def key,#ghi\")",
.type = CONFIG_ITEM_STRING_ARRAY,
.validate = config_validate_nonjunk_string },
{ .name = "command",
@@ -4996,7 +4996,7 @@ on_irc_autojoin_timeout (void *user_data)
cstr_split (autojoin, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
irc_send (s, "JOIN :%s", v.vector[i]);
irc_send (s, "JOIN %s", v.vector[i]);
str_map_set (&joins_sent, v.vector[i], (void *) 1);
}
str_vector_free (&v);
@@ -5007,9 +5007,21 @@ on_irc_autojoin_timeout (void *user_data)
str_map_iter_init (&iter, &s->irc_channels);
struct channel *channel;
while ((channel = str_map_iter_next (&iter)))
{
struct str target;
str_init (&target);
str_append (&target, channel->name);
const char *key;
if ((key = str_map_find (&channel->param_modes, "k")))
str_append_printf (&target, " %s", key);
// When a channel is both autojoined and rejoined, both keys are tried
if (!channel->left_manually
&& !str_map_find (&joins_sent, channel->name))
irc_send (s, "JOIN :%s", channel->name);
&& !str_map_find (&joins_sent, target.str))
irc_send (s, "JOIN %s", target.str);
str_free (&target);
}
str_map_free (&joins_sent);
}
@@ -5912,7 +5924,9 @@ make_prompt (struct app_context *ctx, struct str *output)
str_append_printf (output, "%d:%s",
buffer_get_index (ctx, buffer), buffer->name);
if (buffer->type == BUFFER_CHANNEL)
// We remember old modes, don't show them while we're not on the channel
if (buffer->type == BUFFER_CHANNEL
&& buffer->channel->users_len)
{
struct str modes;
str_init (&modes);
@@ -5921,8 +5935,7 @@ make_prompt (struct app_context *ctx, struct str *output)
str_append_printf (output, "(+%s)", modes.str);
str_free (&modes);
if (buffer->channel->users_len)
str_append_printf (output, "{%zu}", buffer->channel->users_len);
str_append_printf (output, "{%zu}", buffer->channel->users_len);
}
if (buffer->hide_unimportant)
str_append (output, "<H>");
@@ -6522,8 +6535,16 @@ irc_handle_join (struct server *s, const struct irc_message *msg)
buffer_add (s->ctx, buffer);
buffer_activate (s->ctx, buffer);
}
if (irc_is_this_us (s, msg->prefix))
{
// Reset the field so that we rejoin the channel after reconnecting
channel->left_manually = false;
// Request the channel mode as we don't get it automatically
str_reset (&channel->no_param_modes);
str_map_clear (&channel->param_modes);
irc_send (s, "MODE %s", channel_name);
}
@@ -6531,9 +6552,6 @@ irc_handle_join (struct server *s, const struct irc_message *msg)
if (!channel)
return;
// Reset the field so that we rejoin the channel after reconnecting
channel->left_manually = false;
// Add the user to the channel
char *nickname = irc_cut_nickname (msg->prefix);
irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), "");