degesch: cleanup

This commit is contained in:
Přemysl Eric Janouch 2015-06-18 08:20:47 +02:00
parent f09313f08b
commit 87a44fb807
1 changed files with 16 additions and 36 deletions

View File

@ -6320,48 +6320,28 @@ handle_command_mode (struct app_context *ctx, char *arguments)
// Channel names prefixed by "+" collide with mode strings,
// so we just disallow specifying these channels
char *channel_name = NULL;
char *nickname = NULL;
if (*arguments != '+')
channel_name = maybe_cut_word (&arguments, validate_channel_name, s);
if (!channel_name
&& !strchr ("+-\0", *arguments))
nickname = cut_word (&arguments);
if (!channel_name
&& !nickname)
char *target = NULL;
if (strchr ("+-\0", *arguments)
|| !(target = maybe_cut_word (&arguments, validate_channel_name, s))
|| !(target = cut_word (&arguments)))
{
if (ctx->current_buffer->type == BUFFER_CHANNEL)
channel_name = ctx->current_buffer->channel->name;
target = ctx->current_buffer->channel->name;
if (ctx->current_buffer->type == BUFFER_PM)
nickname = ctx->current_buffer->user->nickname;
target = ctx->current_buffer->user->nickname;
if (ctx->current_buffer->type == BUFFER_SERVER)
nickname = ctx->current_buffer->server->irc_user->nickname;
}
if (channel_name)
{
if (*arguments)
// XXX: split as necessary using irc_max_modes?
irc_send (s, "MODE %s %s", channel_name, arguments);
else
irc_send (s, "MODE %s", channel_name);
return true;
}
if (nickname)
{
if (*arguments)
irc_send (s, "MODE %s %s", nickname, arguments);
else
irc_send (s, "MODE %s", nickname);
return true;
target = ctx->current_buffer->server->irc_user->nickname;
}
if (!target)
buffer_send_error (ctx, ctx->current_buffer,
"%s: %s", "Can't change mode",
"no target given and this buffer is neither a PM nor a channel");
else if (*arguments)
// XXX: split channel mode params as necessary using irc_max_modes?
irc_send (s, "MODE %s %s", target, arguments);
else
irc_send (s, "MODE %s", target);
return true;
}