degesch: fix /join, /part, /cycle
Cycle now remembers the channel key.
This commit is contained in:
parent
86f4578d12
commit
690e29c78e
80
degesch.c
80
degesch.c
|
@ -6170,21 +6170,23 @@ handle_command_join (struct app_context *ctx, char *arguments)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
struct server *s = ctx->current_buffer->server;
|
struct server *s = ctx->current_buffer->server;
|
||||||
if (*arguments)
|
// XXX: send the last known channel key?
|
||||||
// TODO: check if the arguments are in the form of
|
if (irc_is_channel (s, arguments))
|
||||||
// "channel(,channel)* key(,key)*"
|
// XXX: we may want to split the list of channels
|
||||||
irc_send (s, "JOIN %s", arguments);
|
irc_send (s, "JOIN %s", arguments);
|
||||||
else if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
else if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't join",
|
"%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
|
// TODO: have a better way of checking if we're on the channel
|
||||||
else if (ctx->current_buffer->channel->users)
|
else if (ctx->current_buffer->channel->users)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't join",
|
"%s: %s", "Can't join",
|
||||||
"you already are on the channel");
|
"you already are on the channel");
|
||||||
|
else if (*arguments)
|
||||||
|
irc_send (s, "JOIN %s :%s",
|
||||||
|
ctx->current_buffer->channel->name, arguments);
|
||||||
else
|
else
|
||||||
// TODO: send the key if known
|
|
||||||
irc_send (s, "JOIN %s", ctx->current_buffer->channel->name);
|
irc_send (s, "JOIN %s", ctx->current_buffer->channel->name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6196,28 +6198,56 @@ handle_command_part (struct app_context *ctx, char *arguments)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
struct server *s = ctx->current_buffer->server;
|
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)
|
if (*arguments)
|
||||||
irc_send (s, "PART %s :%s", channels, arguments);
|
irc_send (s, "PART %s :%s", v.vector[i], arguments);
|
||||||
else
|
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)
|
else if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't part",
|
"%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
|
// TODO: have a better way of checking if we're on the channel
|
||||||
else if (!ctx->current_buffer->channel->users)
|
else if (!ctx->current_buffer->channel->users)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't part", "you're not on the channel");
|
"%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
|
else
|
||||||
irc_send (s, "PART %s", ctx->current_buffer->channel->name);
|
irc_send (s, "PART %s", ctx->current_buffer->channel->name);
|
||||||
return true;
|
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
|
static bool
|
||||||
handle_command_cycle (struct app_context *ctx, char *arguments)
|
handle_command_cycle (struct app_context *ctx, char *arguments)
|
||||||
{
|
{
|
||||||
|
@ -6225,31 +6255,27 @@ handle_command_cycle (struct app_context *ctx, char *arguments)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
struct server *s = ctx->current_buffer->server;
|
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)*"
|
struct str_vector v;
|
||||||
char *channels = cut_word (&arguments);
|
str_vector_init (&v);
|
||||||
if (*arguments)
|
split_str_ignore_empty (cut_word (&arguments), ' ', &v);
|
||||||
irc_send (s, "PART %s :%s", channels, arguments);
|
for (size_t i = 0; i < v.len; i++)
|
||||||
else
|
cycle_channel (s, v.vector[i], *arguments ? arguments : NULL);
|
||||||
irc_send (s, "PART %s", channels);
|
str_vector_free (&v);
|
||||||
// TODO: send the key if known
|
|
||||||
irc_send (s, "JOIN %s", channels);
|
|
||||||
}
|
}
|
||||||
else if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
else if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't cycle",
|
"%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
|
// TODO: have a better way of checking if we're on the channel
|
||||||
else if (!ctx->current_buffer->channel->users)
|
else if (!ctx->current_buffer->channel->users)
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't cycle", "you're not on the channel");
|
"%s: %s", "Can't cycle", "you're not on the channel");
|
||||||
|
else if (*arguments)
|
||||||
|
cycle_channel (s, ctx->current_buffer->channel->name, arguments);
|
||||||
else
|
else
|
||||||
{
|
cycle_channel (s, ctx->current_buffer->channel->name, NULL);
|
||||||
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);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6789,7 +6815,7 @@ g_command_handlers[] =
|
||||||
handle_command_me },
|
handle_command_me },
|
||||||
|
|
||||||
{ "join", "Join channels",
|
{ "join", "Join channels",
|
||||||
"[<channel>[,<channel>...]]",
|
"[<channel>[,<channel>...]] [<key>[,<key>...]]",
|
||||||
handle_command_join },
|
handle_command_join },
|
||||||
{ "part", "Leave channels",
|
{ "part", "Leave channels",
|
||||||
"[<channel>[,<channel>...]] [<reason>]",
|
"[<channel>[,<channel>...]] [<reason>]",
|
||||||
|
|
Loading…
Reference in New Issue