summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-19 23:09:46 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-19 23:09:46 +0200
commitb55494c68f016ff504ef8804330426613bbc09cc (patch)
treec17c920b3ff3b9dda696b9e65291de970910f5f7 /degesch.c
parent5be1cad4da5f5c72239a04c04bcab3afe28c2abe (diff)
downloadxK-b55494c68f016ff504ef8804330426613bbc09cc.tar.gz
xK-b55494c68f016ff504ef8804330426613bbc09cc.tar.xz
xK-b55494c68f016ff504ef8804330426613bbc09cc.zip
degesch: further cleanups
Diffstat (limited to 'degesch.c')
-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;
}