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