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:
parent
fc491c5f8d
commit
810584803b
@ -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);
|
||||
masks = ban_get_masks(channel, bans);
|
||||
channel_set_singlemode(channel->server, channel->name,
|
||||
str->str, "+b");
|
||||
}
|
||||
g_string_free(str, TRUE);
|
||||
masks, "+b");
|
||||
g_free(masks);
|
||||
}
|
||||
|
||||
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
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);
|
||||
g_free(str);
|
||||
|
||||
if (*banmasks == '\0')
|
||||
g_free(banmasks);
|
||||
else {
|
||||
/* create knockout record */
|
||||
rec = g_new(KNOCKOUT_REC, 1);
|
||||
rec->timeleft = timeleft;
|
||||
rec->channel = channel;
|
||||
rec->ban = ban_get_mask(channel, nick);
|
||||
rec->ban = banmasks;
|
||||
|
||||
server->knockoutlist = g_slist_append(server->knockoutlist, rec);
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user