From 690e29c78e565b1d0fa864f1d3bcd0b1fcc6c6a2 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 19 Jun 2015 22:12:53 +0200 Subject: degesch: fix /join, /part, /cycle Cycle now remembers the channel key. --- degesch.c | 84 +++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/degesch.c b/degesch.c index 9883599..37fc014 100644 --- a/degesch.c +++ b/degesch.c @@ -6170,21 +6170,23 @@ handle_command_join (struct app_context *ctx, char *arguments) return true; struct server *s = ctx->current_buffer->server; - if (*arguments) - // TODO: check if the arguments are in the form of - // "channel(,channel)* key(,key)*" + // XXX: send the last known channel key? + if (irc_is_channel (s, arguments)) + // XXX: we may want to split the list of channels irc_send (s, "JOIN %s", arguments); else if (ctx->current_buffer->type != BUFFER_CHANNEL) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't join", - "no argument given and this buffer is not a channel"); + "no channel name given and this buffer is not a channel"); // TODO: have a better way of checking if we're on the channel else if (ctx->current_buffer->channel->users) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't join", "you already are on the channel"); + else if (*arguments) + irc_send (s, "JOIN %s :%s", + ctx->current_buffer->channel->name, arguments); else - // TODO: send the key if known irc_send (s, "JOIN %s", ctx->current_buffer->channel->name); return true; } @@ -6196,28 +6198,56 @@ handle_command_part (struct app_context *ctx, char *arguments) return true; struct server *s = ctx->current_buffer->server; - if (*arguments) + if (irc_is_channel (s, arguments)) { - // TODO: check if the arguments are in the form of "channel(,channel)*" - char *channels = cut_word (&arguments); - if (*arguments) - irc_send (s, "PART %s :%s", channels, arguments); - else - irc_send (s, "PART %s", channels); + struct str_vector v; + str_vector_init (&v); + split_str_ignore_empty (cut_word (&arguments), ' ', &v); + for (size_t i = 0; i < v.len; i++) + { + if (*arguments) + irc_send (s, "PART %s :%s", v.vector[i], arguments); + else + irc_send (s, "PART %s", v.vector[i]); + } + str_vector_free (&v); } else if (ctx->current_buffer->type != BUFFER_CHANNEL) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't part", - "no argument given and this buffer is not a channel"); + "no channel name given and this buffer is not a channel"); // TODO: have a better way of checking if we're on the channel else if (!ctx->current_buffer->channel->users) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't part", "you're not on the channel"); + else if (*arguments) + irc_send (s, "PART %s :%s", + ctx->current_buffer->channel->name, arguments); else irc_send (s, "PART %s", ctx->current_buffer->channel->name); return true; } +static void +cycle_channel (struct server *s, const char *channel_name, const char *reason) +{ + // If a channel key is set, we must specify it when rejoining + const char *key = NULL; + struct channel *channel; + if ((channel = str_map_find (&s->irc_channels, channel_name))) + key = str_map_find (&channel->param_modes, "k"); + + if (reason) + irc_send (s, "PART %s :%s", channel_name, reason); + else + irc_send (s, "PART %s", channel_name); + + if (key) + irc_send (s, "JOIN %s :%s", channel_name, key); + else + irc_send (s, "JOIN %s", channel_name); +} + static bool handle_command_cycle (struct app_context *ctx, char *arguments) { @@ -6225,31 +6255,27 @@ handle_command_cycle (struct app_context *ctx, char *arguments) return true; struct server *s = ctx->current_buffer->server; - if (*arguments) + if (irc_is_channel (s, arguments)) { - // TODO: check if the arguments are in the form of "channel(,channel)*" - char *channels = cut_word (&arguments); - if (*arguments) - irc_send (s, "PART %s :%s", channels, arguments); - else - irc_send (s, "PART %s", channels); - // TODO: send the key if known - irc_send (s, "JOIN %s", channels); + struct str_vector v; + str_vector_init (&v); + split_str_ignore_empty (cut_word (&arguments), ' ', &v); + for (size_t i = 0; i < v.len; i++) + cycle_channel (s, v.vector[i], *arguments ? arguments : NULL); + str_vector_free (&v); } else if (ctx->current_buffer->type != BUFFER_CHANNEL) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't cycle", - "no argument given and this buffer is not a channel"); + "no channel name given and this buffer is not a channel"); // TODO: have a better way of checking if we're on the channel else if (!ctx->current_buffer->channel->users) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't cycle", "you're not on the channel"); + else if (*arguments) + cycle_channel (s, ctx->current_buffer->channel->name, arguments); else - { - irc_send (s, "PART %s", ctx->current_buffer->channel->name); - // TODO: send the key if known - irc_send (s, "JOIN %s", ctx->current_buffer->channel->name); - } + cycle_channel (s, ctx->current_buffer->channel->name, NULL); return true; } @@ -6789,7 +6815,7 @@ g_command_handlers[] = handle_command_me }, { "join", "Join channels", - "[[,...]]", + "[[,...]] [[,...]]", handle_command_join }, { "part", "Leave channels", "[[,...]] []", -- cgit v1.2.3-70-g09d2