degesch: fix /join, /part, /cycle

Cycle now remembers the channel key.
This commit is contained in:
Přemysl Eric Janouch 2015-06-19 22:12:53 +02:00
parent 86f4578d12
commit 690e29c78e
1 changed files with 55 additions and 29 deletions

View File

@ -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))
{
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++)
{
// 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);
irc_send (s, "PART %s :%s", v.vector[i], arguments);
else
irc_send (s, "PART %s", channels);
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",
"[<channel>[,<channel>...]]",
"[<channel>[,<channel>...]] [<key>[,<key>...]]",
handle_command_join },
{ "part", "Leave channels",
"[<channel>[,<channel>...]] [<reason>]",