summaryrefslogtreecommitdiff
path: root/src/irc/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-12-17 02:59:16 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-12-17 02:59:16 +0000
commit810584803b4d96dbfa77400981a1c68e89733010 (patch)
tree67eb633c0f9c54c755bcd27bfc01608480cacb32 /src/irc/core
parentfc491c5f8dd7f4a2ece6eb46feac687b4b0022ef (diff)
downloadirssi-810584803b4d96dbfa77400981a1c68e89733010.zip
/kickban and /knockout now accepts multiple nicks separated with commas.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1000 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc/core')
-rw-r--r--src/irc/core/bans.c63
-rw-r--r--src/irc/core/bans.h1
-rw-r--r--src/irc/core/irc-commands.c89
3 files changed, 103 insertions, 50 deletions
diff --git a/src/irc/core/bans.c b/src/irc/core/bans.c
index d0a6b198..947f3d69 100644
--- a/src/irc/core/bans.c
+++ b/src/irc/core/bans.c
@@ -31,7 +31,6 @@
static int bantype;
-/* Get ban mask */
char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick)
{
NICK_REC *rec;
@@ -62,6 +61,37 @@ char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick)
return str;
}
+char *ban_get_masks(IRC_CHANNEL_REC *channel, const char *nicks)
+{
+ GString *str;
+ char **ban, **banlist, *realban, *ret;
+
+ str = g_string_new(NULL);
+ banlist = g_strsplit(nicks, " ", -1);
+ for (ban = banlist; *ban != NULL; ban++) {
+ if (strchr(*ban, '!') != NULL) {
+ /* explicit ban */
+ g_string_sprintfa(str, "%s ", *ban);
+ continue;
+ }
+
+ /* ban nick */
+ realban = ban_get_mask(channel, *ban);
+ if (realban != NULL) {
+ g_string_sprintfa(str, "%s ", realban);
+ g_free(realban);
+ }
+ }
+ g_strfreev(banlist);
+
+ if (str->len > 0)
+ g_string_truncate(str, str->len-1);
+
+ ret = str->str;
+ g_string_free(str, FALSE);
+ return ret;
+}
+
void ban_set_type(const char *type)
{
char bantypestr[5], **list;
@@ -110,35 +140,14 @@ void ban_set_type(const char *type)
void ban_set(IRC_CHANNEL_REC *channel, const char *bans)
{
- GString *str;
- char **ban, **banlist, *realban;
+ char *masks;
g_return_if_fail(bans != NULL);
- str = g_string_new(NULL);
- banlist = g_strsplit(bans, " ", -1);
- for (ban = banlist; *ban != NULL; ban++) {
- if (strchr(*ban, '!') != NULL) {
- /* explicit ban */
- g_string_sprintfa(str, "%s ", *ban);
- continue;
- }
-
- /* ban nick */
- realban = ban_get_mask(channel, *ban);
- if (realban != NULL) {
- g_string_sprintfa(str, "%s ", realban);
- g_free(realban);
- }
- }
- g_strfreev(banlist);
-
- if (str->len > 0) {
- g_string_truncate(str, str->len-1);
- channel_set_singlemode(channel->server, channel->name,
- str->str, "+b");
- }
- g_string_free(str, TRUE);
+ masks = ban_get_masks(channel, bans);
+ channel_set_singlemode(channel->server, channel->name,
+ masks, "+b");
+ g_free(masks);
}
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)
diff --git a/src/irc/core/bans.h b/src/irc/core/bans.h
index 9a6587a7..1cf86851 100644
--- a/src/irc/core/bans.h
+++ b/src/irc/core/bans.h
@@ -7,6 +7,7 @@ void bans_init(void);
void bans_deinit(void);
char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick);
+char *ban_get_masks(IRC_CHANNEL_REC *channel, const char *nicks);
void ban_set_type(const char *type);
void ban_set(IRC_CHANNEL_REC *channel, const char *bans);
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index 710ed760..ed0984f8 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -813,20 +813,45 @@ static void cmd_cycle(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *ite
cmd_params_free(free_arg);
}
-/* SYNTAX: KICKBAN [<channel>] <nick> <reason> */
-static void cmd_kickban(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
+/* SYNTAX: KICKBAN [<channel>] <nicks> <reason> */
+static void cmd_kickban(const char *data, IRC_SERVER_REC *server,
+ WI_ITEM_REC *item)
{
- char *nick;
+ IRC_CHANNEL_REC *chanrec;
+ char *channel, *nicks, *reason, *str;
+ char **nicklist, *spacenicks;
void *free_arg;
g_return_if_fail(data != NULL);
+ if (!IS_IRC_SERVER(server) || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
- if (!cmd_get_params(data, &free_arg, 1, &nick))
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
+ item, &channel, &nicks, &reason))
return;
- if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- signal_emit("command ban", 3, nick, server, item);
- signal_emit("command kick", 3, data, server, item);
+ if (*channel == '\0' || *nicks == '\0')
+ cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+ chanrec = irc_channel_find(server, channel);
+ if (chanrec == NULL)
+ cmd_param_error(CMDERR_CHAN_NOT_FOUND);
+ if (!chanrec->wholist)
+ cmd_param_error(CMDERR_CHAN_NOT_SYNCED);
+
+ nicklist = g_strsplit(nicks, ",", -1);
+ spacenicks = g_strjoinv(" ", nicklist);
+ g_strfreev(nicklist);
+
+ str = g_strdup_printf("%s %s", chanrec->name, spacenicks);
+ signal_emit("command ban", 3, str, server, channel);
+ g_free(str);
+
+ str = g_strdup_printf("%s %s %s", chanrec->name, nicks, reason);
+ signal_emit("command kick", 3, str, server, channel);
+ g_free(str);
+
+ g_free(spacenicks);
cmd_params_free(free_arg);
}
@@ -872,48 +897,66 @@ static int knockout_timeout(void)
return 1;
}
-/* SYNTAX: KNOCKOUT [<seconds>] <nick> <reason> */
+/* SYNTAX: KNOCKOUT [<seconds>] <nicks> <reason> */
static void cmd_knockout(const char *data, IRC_SERVER_REC *server,
IRC_CHANNEL_REC *channel)
{
KNOCKOUT_REC *rec;
- char *nick, *reason, *timeoutstr, *str;
+ char *nicks, *reason, *timeoutstr, *str;
+ char **nicklist, *spacenicks, *banmasks;
void *free_arg;
int timeleft;
g_return_if_fail(data != NULL);
- if (!IS_IRC_SERVER(server) || !server->connected)
- cmd_return_error(CMDERR_NOT_CONNECTED);
if (!IS_IRC_CHANNEL(channel))
cmd_return_error(CMDERR_NOT_JOINED);
+ if (!channel->wholist)
+ cmd_param_error(CMDERR_CHAN_NOT_SYNCED);
if (is_numeric(data, ' ')) {
/* first argument is the timeout */
- if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nick, &reason))
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
+ &timeoutstr, &nicks, &reason))
return;
timeleft = atoi(timeoutstr);
} else {
- timeleft = 0;
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &reason))
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
+ &nicks, &reason))
return;
+ timeleft = 0;
}
if (timeleft == 0) timeleft = settings_get_int("knockout_time");
- if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+ if (*nicks == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+ nicklist = g_strsplit(nicks, ",", -1);
+ spacenicks = g_strjoinv(" ", nicklist);
+ g_strfreev(nicklist);
+
+ banmasks = ban_get_masks(channel, spacenicks);
+ g_free(spacenicks);
- signal_emit("command ban", 3, nick, server, channel);
+ if (*banmasks != '\0') {
+ str = g_strdup_printf("%s %s", channel->name, banmasks);
+ signal_emit("command ban", 3, str, server, channel);
+ g_free(str);
+ }
- str = g_strdup_printf("%s %s", nick, reason);
+ str = g_strdup_printf("%s %s %s", channel->name, nicks, reason);
signal_emit("command kick", 3, str, server, channel);
g_free(str);
- /* create knockout record */
- rec = g_new(KNOCKOUT_REC, 1);
- rec->timeleft = timeleft;
- rec->channel = channel;
- rec->ban = ban_get_mask(channel, nick);
+ if (*banmasks == '\0')
+ g_free(banmasks);
+ else {
+ /* create knockout record */
+ rec = g_new(KNOCKOUT_REC, 1);
+ rec->timeleft = timeleft;
+ rec->channel = channel;
+ rec->ban = banmasks;
- server->knockoutlist = g_slist_append(server->knockoutlist, rec);
+ server->knockoutlist = g_slist_append(server->knockoutlist, rec);
+ }
cmd_params_free(free_arg);
}