degesch: fix /ban, add /unban
This commit is contained in:
parent
782bc85336
commit
27ef5c2ea3
117
degesch.c
117
degesch.c
@ -6253,6 +6253,31 @@ handle_command_cycle (struct app_context *ctx, char *arguments)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mass_channel_mode (struct server *s, const char *channel_name,
|
||||||
|
bool adding, char mode_char, struct str_vector *v)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
for (size_t i = 0; i < v->len; i += n)
|
||||||
|
{
|
||||||
|
struct str modes; str_init (&modes);
|
||||||
|
struct str params; str_init (¶ms);
|
||||||
|
|
||||||
|
n = MIN (v->len - i, s->irc_max_modes);
|
||||||
|
str_append_printf (&modes, "MODE %s %c", channel_name, "-+"[adding]);
|
||||||
|
for (size_t k = 0; k < n; k++)
|
||||||
|
{
|
||||||
|
str_append_c (&modes, mode_char);
|
||||||
|
str_append_printf (¶ms, " %s", v->vector[i + k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
irc_send (s, "%s%s", modes.str, params.str);
|
||||||
|
|
||||||
|
str_free (&modes);
|
||||||
|
str_free (¶ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
handle_command_channel_mode (struct app_context *ctx, char *arguments,
|
handle_command_channel_mode (struct app_context *ctx, char *arguments,
|
||||||
const char *command_name, bool adding, char mode_char)
|
const char *command_name, bool adding, char mode_char)
|
||||||
@ -6263,39 +6288,19 @@ handle_command_channel_mode (struct app_context *ctx, char *arguments,
|
|||||||
struct server *s = ctx->current_buffer->server;
|
struct server *s = ctx->current_buffer->server;
|
||||||
char *channel_name = try_get_channel (ctx, &arguments);
|
char *channel_name = try_get_channel (ctx, &arguments);
|
||||||
if (!channel_name)
|
if (!channel_name)
|
||||||
{
|
|
||||||
buffer_send_error (ctx, ctx->current_buffer,
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
"%s: %s", "Can't set mode",
|
"%s: %s", "Can't set mode",
|
||||||
"no channel name given and this buffer is not a channel");
|
"no channel name given and this buffer is not a channel");
|
||||||
return true;
|
else if (*arguments)
|
||||||
}
|
|
||||||
if (!*arguments)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
struct str_vector v;
|
|
||||||
str_vector_init (&v);
|
|
||||||
split_str_ignore_empty (arguments, ' ', &v);
|
|
||||||
|
|
||||||
size_t n;
|
|
||||||
for (size_t i = 0; i < v.len; i += n)
|
|
||||||
{
|
{
|
||||||
struct str modes; str_init (&modes);
|
struct str_vector v;
|
||||||
struct str params; str_init (¶ms);
|
str_vector_init (&v);
|
||||||
|
split_str_ignore_empty (arguments, ' ', &v);
|
||||||
n = MIN (v.len - i, s->irc_max_modes);
|
mass_channel_mode (s, channel_name, adding, mode_char, &v);
|
||||||
str_append_printf (&modes, "MODE %s %c", channel_name, "-+"[adding]);
|
str_vector_free (&v);
|
||||||
for (size_t k = 0; k < n; k++)
|
|
||||||
{
|
|
||||||
str_append_c (&modes, mode_char);
|
|
||||||
str_append_printf (¶ms, " %s", v.vector[i + k]);
|
|
||||||
}
|
|
||||||
|
|
||||||
irc_send (s, "%s%s", modes.str, params.str);
|
|
||||||
|
|
||||||
str_free (&modes);
|
|
||||||
str_free (¶ms);
|
|
||||||
}
|
}
|
||||||
str_vector_free (&v);
|
else
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6421,6 +6426,22 @@ handle_command_kickban (struct app_context *ctx, char *arguments)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
complete_user_masks (struct str_vector *v)
|
||||||
|
{
|
||||||
|
// XXX: this may be a bit too trivial; we could map also nicknames
|
||||||
|
// to information from WHO polling or userhost-in-names
|
||||||
|
for (size_t i = 0; i < v->len; i++)
|
||||||
|
{
|
||||||
|
char *target = v->vector[i];
|
||||||
|
if (strpbrk (target, "!@*?"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
v->vector[i] = xstrdup_printf ("%s!*@*", target);
|
||||||
|
free (target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
handle_command_ban (struct app_context *ctx, char *arguments)
|
handle_command_ban (struct app_context *ctx, char *arguments)
|
||||||
{
|
{
|
||||||
@ -6434,7 +6455,40 @@ handle_command_ban (struct app_context *ctx, char *arguments)
|
|||||||
"%s: %s", "Can't ban",
|
"%s: %s", "Can't ban",
|
||||||
"no channel name given and this buffer is not a channel");
|
"no channel name given and this buffer is not a channel");
|
||||||
else if (*arguments)
|
else if (*arguments)
|
||||||
irc_send (s, "MODE %s +b %s", channel_name, arguments);
|
{
|
||||||
|
struct str_vector v;
|
||||||
|
str_vector_init (&v);
|
||||||
|
split_str_ignore_empty (arguments, ' ', &v);
|
||||||
|
complete_user_masks (&v);
|
||||||
|
mass_channel_mode (s, channel_name, true, 'b', &v);
|
||||||
|
str_vector_free (&v);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
irc_send (s, "MODE %s +b", channel_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
handle_command_unban (struct app_context *ctx, char *arguments)
|
||||||
|
{
|
||||||
|
if (!server_command_check (ctx, "unban", true))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
struct server *s = ctx->current_buffer->server;
|
||||||
|
char *channel_name = try_get_channel (ctx, &arguments);
|
||||||
|
if (!channel_name)
|
||||||
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
|
"%s: %s", "Can't unban",
|
||||||
|
"no channel name given and this buffer is not a channel");
|
||||||
|
else if (*arguments)
|
||||||
|
{
|
||||||
|
struct str_vector v;
|
||||||
|
str_vector_init (&v);
|
||||||
|
split_str_ignore_empty (arguments, ' ', &v);
|
||||||
|
complete_user_masks (&v);
|
||||||
|
mass_channel_mode (s, channel_name, false, 'b', &v);
|
||||||
|
str_vector_free (&v);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@ -6735,8 +6789,11 @@ g_command_handlers[] =
|
|||||||
"[<channel>] <user> [<reason>]",
|
"[<channel>] <user> [<reason>]",
|
||||||
handle_command_kickban },
|
handle_command_kickban },
|
||||||
{ "ban", "Ban user from channel",
|
{ "ban", "Ban user from channel",
|
||||||
"[<channel>] <mask>",
|
"[<channel>] [<mask>...]",
|
||||||
handle_command_ban },
|
handle_command_ban },
|
||||||
|
{ "unban", "Unban user from channel",
|
||||||
|
"[<channel>] <mask>...",
|
||||||
|
handle_command_unban },
|
||||||
{ "invite", "Invite user to channel",
|
{ "invite", "Invite user to channel",
|
||||||
"[<channel>] <user>",
|
"[<channel>] <user>",
|
||||||
handle_command_invite },
|
handle_command_invite },
|
||||||
|
Loading…
Reference in New Issue
Block a user