1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

/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
This commit is contained in:
Timo Sirainen 2000-12-17 02:59:16 +00:00 committed by cras
parent fc491c5f8d
commit 810584803b
3 changed files with 103 additions and 50 deletions

View File

@ -31,7 +31,6 @@
static int bantype; static int bantype;
/* Get ban mask */
char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick) char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick)
{ {
NICK_REC *rec; NICK_REC *rec;
@ -62,6 +61,37 @@ char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick)
return str; 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) void ban_set_type(const char *type)
{ {
char bantypestr[5], **list; 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) void ban_set(IRC_CHANNEL_REC *channel, const char *bans)
{ {
GString *str; char *masks;
char **ban, **banlist, *realban;
g_return_if_fail(bans != NULL); g_return_if_fail(bans != NULL);
str = g_string_new(NULL); masks = ban_get_masks(channel, bans);
banlist = g_strsplit(bans, " ", -1); channel_set_singlemode(channel->server, channel->name,
for (ban = banlist; *ban != NULL; ban++) { masks, "+b");
if (strchr(*ban, '!') != NULL) { g_free(masks);
/* 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);
} }
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans) void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)

View File

@ -7,6 +7,7 @@ void bans_init(void);
void bans_deinit(void); void bans_deinit(void);
char *ban_get_mask(IRC_CHANNEL_REC *channel, const char *nick); 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_type(const char *type);
void ban_set(IRC_CHANNEL_REC *channel, const char *bans); void ban_set(IRC_CHANNEL_REC *channel, const char *bans);

View File

@ -813,20 +813,45 @@ static void cmd_cycle(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *ite
cmd_params_free(free_arg); cmd_params_free(free_arg);
} }
/* SYNTAX: KICKBAN [<channel>] <nick> <reason> */ /* SYNTAX: KICKBAN [<channel>] <nicks> <reason> */
static void cmd_kickban(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) 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; void *free_arg;
g_return_if_fail(data != NULL); 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; return;
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
signal_emit("command ban", 3, nick, server, item); if (*channel == '\0' || *nicks == '\0')
signal_emit("command kick", 3, data, server, item); 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); cmd_params_free(free_arg);
} }
@ -872,48 +897,66 @@ static int knockout_timeout(void)
return 1; return 1;
} }
/* SYNTAX: KNOCKOUT [<seconds>] <nick> <reason> */ /* SYNTAX: KNOCKOUT [<seconds>] <nicks> <reason> */
static void cmd_knockout(const char *data, IRC_SERVER_REC *server, static void cmd_knockout(const char *data, IRC_SERVER_REC *server,
IRC_CHANNEL_REC *channel) IRC_CHANNEL_REC *channel)
{ {
KNOCKOUT_REC *rec; KNOCKOUT_REC *rec;
char *nick, *reason, *timeoutstr, *str; char *nicks, *reason, *timeoutstr, *str;
char **nicklist, *spacenicks, *banmasks;
void *free_arg; void *free_arg;
int timeleft; int timeleft;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
if (!IS_IRC_CHANNEL(channel)) if (!IS_IRC_CHANNEL(channel))
cmd_return_error(CMDERR_NOT_JOINED); cmd_return_error(CMDERR_NOT_JOINED);
if (!channel->wholist)
cmd_param_error(CMDERR_CHAN_NOT_SYNCED);
if (is_numeric(data, ' ')) { if (is_numeric(data, ' ')) {
/* first argument is the timeout */ /* 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; return;
timeleft = atoi(timeoutstr); timeleft = atoi(timeoutstr);
} else { } else {
timeleft = 0; if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &reason)) &nicks, &reason))
return; return;
timeleft = 0;
} }
if (timeleft == 0) timeleft = settings_get_int("knockout_time"); 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);
signal_emit("command ban", 3, nick, server, channel); nicklist = g_strsplit(nicks, ",", -1);
spacenicks = g_strjoinv(" ", nicklist);
g_strfreev(nicklist);
str = g_strdup_printf("%s %s", nick, reason); banmasks = ban_get_masks(channel, spacenicks);
g_free(spacenicks);
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 %s", channel->name, nicks, reason);
signal_emit("command kick", 3, str, server, channel); signal_emit("command kick", 3, str, server, channel);
g_free(str); g_free(str);
/* create knockout record */ if (*banmasks == '\0')
rec = g_new(KNOCKOUT_REC, 1); g_free(banmasks);
rec->timeleft = timeleft; else {
rec->channel = channel; /* create knockout record */
rec->ban = ban_get_mask(channel, nick); 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); cmd_params_free(free_arg);
} }