degesch: further cleanups

This commit is contained in:
Přemysl Eric Janouch 2015-06-20 20:13:37 +02:00
parent 5d9b080d83
commit 0875bbfba7
1 changed files with 29 additions and 40 deletions

View File

@ -6192,6 +6192,15 @@ handle_command_join (struct app_context *ctx, struct handler_args *a)
return true; return true;
} }
static void
part_channel (struct server *s, const char *channel_name, const char *reason)
{
if (*reason)
irc_send (s, "PART %s :%s", channel_name, reason);
else
irc_send (s, "PART %s", channel_name);
}
static bool static bool
handle_command_part (struct app_context *ctx, struct handler_args *a) handle_command_part (struct app_context *ctx, struct handler_args *a)
{ {
@ -6201,13 +6210,7 @@ handle_command_part (struct app_context *ctx, struct handler_args *a)
str_vector_init (&v); str_vector_init (&v);
split_str_ignore_empty (cut_word (&a->arguments), ' ', &v); split_str_ignore_empty (cut_word (&a->arguments), ' ', &v);
for (size_t i = 0; i < v.len; i++) for (size_t i = 0; i < v.len; i++)
{ part_channel (a->s, v.vector[i], a->arguments);
// TODO: move this out
if (*a->arguments)
irc_send (a->s, "PART %s :%s", v.vector[i], a->arguments);
else
irc_send (a->s, "PART %s", v.vector[i]);
}
str_vector_free (&v); str_vector_free (&v);
} }
else if (a->buffer->type != BUFFER_CHANNEL) else if (a->buffer->type != BUFFER_CHANNEL)
@ -6218,10 +6221,8 @@ handle_command_part (struct app_context *ctx, struct handler_args *a)
else if (!a->buffer->channel->users) else if (!a->buffer->channel->users)
buffer_send_error (ctx, a->buffer, buffer_send_error (ctx, a->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 (*a->arguments)
irc_send (a->s, "PART %s :%s", a->buffer->channel->name, a->arguments);
else else
irc_send (a->s, "PART %s", a->buffer->channel->name); part_channel (a->s, a->buffer->channel->name, a->arguments);
return true; return true;
} }
@ -6234,7 +6235,7 @@ cycle_channel (struct server *s, const char *channel_name, const char *reason)
if ((channel = str_map_find (&s->irc_channels, channel_name))) if ((channel = str_map_find (&s->irc_channels, channel_name)))
key = str_map_find (&channel->param_modes, "k"); key = str_map_find (&channel->param_modes, "k");
if (reason) if (*reason)
irc_send (s, "PART %s :%s", channel_name, reason); irc_send (s, "PART %s :%s", channel_name, reason);
else else
irc_send (s, "PART %s", channel_name); irc_send (s, "PART %s", channel_name);
@ -6254,9 +6255,7 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a)
str_vector_init (&v); str_vector_init (&v);
split_str_ignore_empty (cut_word (&a->arguments), ' ', &v); split_str_ignore_empty (cut_word (&a->arguments), ' ', &v);
for (size_t i = 0; i < v.len; i++) for (size_t i = 0; i < v.len; i++)
// TODO: just send the arguments, also elsewhere cycle_channel (a->s, v.vector[i], a->arguments);
cycle_channel (a->s, v.vector[i],
*a->arguments ? a->arguments : NULL);
str_vector_free (&v); str_vector_free (&v);
} }
else if (a->buffer->type != BUFFER_CHANNEL) else if (a->buffer->type != BUFFER_CHANNEL)
@ -6267,10 +6266,8 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a)
else if (!a->buffer->channel->users) else if (!a->buffer->channel->users)
buffer_send_error (ctx, a->buffer, buffer_send_error (ctx, a->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 (*a->arguments)
cycle_channel (a->s, a->buffer->channel->name, a->arguments);
else else
cycle_channel (a->s, a->buffer->channel->name, NULL); cycle_channel (a->s, a->buffer->channel->name, a->arguments);
return true; return true;
} }
@ -6448,25 +6445,31 @@ handle_command_invite (struct app_context *ctx, struct handler_args *a)
return result; return result;
} }
static bool static struct server *
handle_command_connect (struct app_context *ctx, struct handler_args *a) resolve_server (struct app_context *ctx, struct handler_args *a,
const char *command_name)
{ {
struct server *s = NULL; struct server *s = NULL;
if (*a->arguments) if (*a->arguments)
{ {
char *server_name = cut_word (&a->arguments); char *server_name = cut_word (&a->arguments);
if (!(s = str_map_find (&ctx->servers, server_name))) if (!(s = str_map_find (&ctx->servers, server_name)))
buffer_send_error (ctx, ctx->global_buffer, "%s: %s: %s", buffer_send_error (ctx, ctx->global_buffer, "/%s: %s: %s",
"Can't connect", "no such server", server_name); command_name, "no such server", server_name);
} }
else if (a->buffer->type == BUFFER_GLOBAL) else if (a->buffer->type == BUFFER_GLOBAL)
buffer_send_error (ctx, a->buffer, buffer_send_error (ctx, a->buffer, "/%s: %s",
"%s: %s", "Can't connect", command_name, "no server name given and this buffer is global");
"no server name given and this buffer is global");
else else
s = a->buffer->server; s = a->buffer->server;
return s;
}
if (!s) static bool
handle_command_connect (struct app_context *ctx, struct handler_args *a)
{
struct server *s = NULL;
if (!(s = resolve_server (ctx, a, "connect")))
return true; return true;
if (irc_is_connected (s)) if (irc_is_connected (s))
@ -6486,21 +6489,7 @@ static bool
handle_command_disconnect (struct app_context *ctx, struct handler_args *a) handle_command_disconnect (struct app_context *ctx, struct handler_args *a)
{ {
struct server *s = NULL; struct server *s = NULL;
if (*a->arguments) if (!(s = resolve_server (ctx, a, "disconnect")))
{
char *server_name = cut_word (&a->arguments);
if (!(s = str_map_find (&ctx->servers, server_name)))
buffer_send_error (ctx, a->buffer, "%s: %s: %s",
"Can't disconnect", "no such server", server_name);
}
else if (a->buffer->type == BUFFER_GLOBAL)
buffer_send_error (ctx, a->buffer,
"%s: %s", "Can't disconnect",
"no server name given and this buffer is global");
else
s = a->buffer->server;
if (!s)
return true; return true;
if (s->state == IRC_CONNECTING) if (s->state == IRC_CONNECTING)