summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c97
1 files changed, 44 insertions, 53 deletions
diff --git a/degesch.c b/degesch.c
index ed4a902..ad4abb8 100644
--- a/degesch.c
+++ b/degesch.c
@@ -6314,16 +6314,14 @@ handle_command_channel_mode (struct app_context *ctx, char *arguments,
{
CHANNEL_COMMAND (command_name, true)
- if (*arguments)
- {
- struct str_vector v;
- str_vector_init (&v);
- split_str_ignore_empty (arguments, ' ', &v);
- mass_channel_mode (s, channel_name, adding, mode_char, &v);
- str_vector_free (&v);
- }
- else
+ if (!*arguments)
return false;
+
+ struct str_vector v;
+ str_vector_init (&v);
+ split_str_ignore_empty (arguments, ' ', &v);
+ mass_channel_mode (s, channel_name, adding, mode_char, &v);
+ str_vector_free (&v);
return true;
}
@@ -6391,16 +6389,14 @@ handle_command_kick (struct app_context *ctx, char *arguments)
{
CHANNEL_COMMAND ("kick", true)
+ if (!*arguments)
+ return false;
+
+ char *target = cut_word (&arguments);
if (*arguments)
- {
- char *target = cut_word (&arguments);
- if (*arguments)
- irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
- else
- irc_send (s, "KICK %s %s", channel_name, target);
- }
+ irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else
- return false;
+ irc_send (s, "KICK %s %s", channel_name, target);
return true;
}
@@ -6409,38 +6405,44 @@ handle_command_kickban (struct app_context *ctx, char *arguments)
{
CHANNEL_COMMAND ("kickban", true)
- if (*arguments)
- {
- char *target = cut_word (&arguments);
- if (strpbrk (target, "!@*?"))
- return false;
+ if (!*arguments)
+ return false;
- // XXX: how about other masks?
- irc_send (s, "MODE %s +b %s!*@*", channel_name, target);
- if (*arguments)
- irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
- else
- irc_send (s, "KICK %s %s", channel_name, target);
- }
- else
+ char *target = cut_word (&arguments);
+ if (strpbrk (target, "!@*?"))
return false;
+
+ // XXX: how about other masks?
+ irc_send (s, "MODE %s +b %s!*@*", channel_name, target);
+ if (*arguments)
+ irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
+ else
+ irc_send (s, "KICK %s %s", channel_name, target);
return true;
}
static void
-complete_user_masks (struct str_vector *v)
+mass_channel_mode_mask_list (struct server *s, const char *channel_name,
+ bool adding, char mode_char, const char *arguments)
{
+ struct str_vector v;
+ str_vector_init (&v);
+ split_str_ignore_empty (arguments, ' ', &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++)
+ for (size_t i = 0; i < v.len; i++)
{
- char *target = v->vector[i];
+ char *target = v.vector[i];
if (strpbrk (target, "!@*?"))
continue;
- v->vector[i] = xstrdup_printf ("%s!*@*", target);
+ v.vector[i] = xstrdup_printf ("%s!*@*", target);
free (target);
}
+
+ mass_channel_mode (s, channel_name, adding, mode_char, &v);
+ str_vector_free (&v);
}
static bool
@@ -6448,17 +6450,13 @@ handle_command_ban (struct app_context *ctx, char *arguments)
{
CHANNEL_COMMAND ("ban", true)
- if (*arguments)
+ 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, true, 'b', &v);
- str_vector_free (&v);
- }
- else
irc_send (s, "MODE %s +b", channel_name);
+ return true;
+ }
+
+ mass_channel_mode_mask_list (s, channel_name, true, 'b', arguments);
return true;
}
@@ -6467,17 +6465,10 @@ handle_command_unban (struct app_context *ctx, char *arguments)
{
CHANNEL_COMMAND ("unban", true)
- 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
+ if (!*arguments)
return false;
+
+ mass_channel_mode_mask_list (s, channel_name, false, 'b', arguments);
return true;
}