diff options
author | Timo Sirainen <cras@irssi.org> | 2001-08-08 16:22:01 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-08-08 16:22:01 +0000 |
commit | 59a1a4d649bfc4e1cce327c473a08560c29f503d (patch) | |
tree | 14636dd9d8dca7199131e7f644d9981e566b588c | |
parent | 4737d162900e8c90df461c421ca71136d519e3f1 (diff) | |
download | irssi-59a1a4d649bfc4e1cce327c473a08560c29f503d.zip |
/BAN [-type] -> /BAN [-normal | -user | -host | -domain | -custom <type>].
Added ban type "User"
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1722 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r-- | docs/help/in/ban.in | 9 | ||||
-rw-r--r-- | src/irc/core/bans.c | 87 |
2 files changed, 64 insertions, 32 deletions
diff --git a/docs/help/in/ban.in b/docs/help/in/ban.in index 4f8a541d..53ca80ef 100644 --- a/docs/help/in/ban.in +++ b/docs/help/in/ban.in @@ -7,15 +7,16 @@ If nick is given as parameter, the ban type is used to generate the ban mask. /SET ban_type specified the default ban type. Ban type is one of the following: - Normal - *!user@*.domain.net + Normal - *!*user@*.domain.net + User - *!*user@* Host - *!*@host.domain.net Domain - *!*@*.domain.net Custom [nick] [user] [host] [domain] Examples: - /BAN looser - This bans the nick 'looser' - /BAN *!*@*.org - This bans all the users coming from any - .org domain. + /BAN looser - Bans the nick 'looser' + /BAN -host looser - Bans the host of nick 'looser' + /BAN *!*@*.org - Bans all the users coming from any .org domain. /SET ban_type custom nick domain - nick!*@*.domain.net /SET ban_type custom user host - *!user@host.domain.net diff --git a/src/irc/core/bans.c b/src/irc/core/bans.c index 0140cc75..8f4c535d 100644 --- a/src/irc/core/bans.c +++ b/src/irc/core/bans.c @@ -30,6 +30,11 @@ #include "irc.h" #include "nicklist.h" +#define BAN_TYPE_NORMAL (IRC_MASK_USER | IRC_MASK_DOMAIN) +#define BAN_TYPE_USER (IRC_MASK_USER) +#define BAN_TYPE_HOST (IRC_MASK_HOST | IRC_MASK_DOMAIN) +#define BAN_TYPE_DOMAIN (IRC_MASK_DOMAIN) + static char *default_ban_type_str; static int default_ban_type; @@ -183,43 +188,57 @@ static void command_set_ban(const char *data, IRC_SERVER_REC *server, cmd_params_free(free_arg); } -static int ban_parse_type(const char *type) +static int parse_custom_ban(const char *type) { char **list; int n, ban_type; + ban_type = 0; + list = g_strsplit(type, " ", -1); + for (n = 0; list[n] != NULL; n++) { + if (toupper(list[n][0]) == 'N') + ban_type |= IRC_MASK_NICK; + else if (toupper(list[n][0]) == 'U') + ban_type |= IRC_MASK_USER; + else if (toupper(list[n][0]) == 'H') + ban_type |= IRC_MASK_HOST | IRC_MASK_DOMAIN; + else if (toupper(list[n][0]) == 'D') + ban_type |= IRC_MASK_DOMAIN; + } + g_strfreev(list); + + return ban_type; +} + +static int parse_ban_type(const char *type) +{ + const char *pos; + g_return_val_if_fail(type != NULL, 0); - ban_type = 0; if (toupper(type[0]) == 'N') - ban_type = IRC_MASK_USER | IRC_MASK_DOMAIN; - else if (toupper(type[0]) == 'H') - ban_type = IRC_MASK_HOST | IRC_MASK_DOMAIN; - else if (toupper(type[0]) == 'D') - ban_type = IRC_MASK_DOMAIN; - else if (toupper(type[0]) == 'C') { - list = g_strsplit(type, " ", -1); - for (n = 1; list[n] != NULL; n++) { - if (toupper(list[n][0]) == 'N') - ban_type |= IRC_MASK_NICK; - else if (toupper(list[n][0]) == 'U') - ban_type |= IRC_MASK_USER; - else if (toupper(list[n][0]) == 'H') - ban_type |= IRC_MASK_HOST | IRC_MASK_DOMAIN; - else if (toupper(list[n][0]) == 'D') - ban_type |= IRC_MASK_DOMAIN; - } - g_strfreev(list); + return BAN_TYPE_NORMAL; + if (toupper(type[0]) == 'U') + return BAN_TYPE_USER; + if (toupper(type[0]) == 'H') + return BAN_TYPE_HOST; + if (toupper(type[0]) == 'D') + return BAN_TYPE_DOMAIN; + if (toupper(type[0]) == 'C') { + pos = strchr(type, ' '); + if (pos != NULL) + return parse_custom_ban(pos+1); } - return ban_type; + return 0; } -/* SYNTAX: BAN [-type <ban type>] <nicks/masks> */ +/* SYNTAX: BAN [-normal | -user | -host | -domain | -custom <type>] <nicks/masks> */ static void cmd_ban(const char *data, IRC_SERVER_REC *server, void *item) { GHashTable *optlist; - char *ban, *ban_type_str; + const char *custom_type; + char *ban; int ban_type; void *free_arg; @@ -228,9 +247,21 @@ static void cmd_ban(const char *data, IRC_SERVER_REC *server, void *item) "ban", &optlist, &ban)) return; - ban_type_str = g_hash_table_lookup(optlist, "type"); - ban_type = ban_type_str == NULL ? default_ban_type : - ban_parse_type(ban_type_str); + if (g_hash_table_lookup(optlist, "normal") != NULL) + ban_type = BAN_TYPE_NORMAL; + else if (g_hash_table_lookup(optlist, "user") != NULL) + ban_type = BAN_TYPE_USER; + else if (g_hash_table_lookup(optlist, "host") != NULL) + ban_type = BAN_TYPE_HOST; + else if (g_hash_table_lookup(optlist, "domain") != NULL) + ban_type = BAN_TYPE_DOMAIN; + else { + custom_type = g_hash_table_lookup(optlist, "custom"); + if (custom_type != NULL) + ban_type = parse_custom_ban(custom_type); + else + ban_type = default_ban_type; + } command_set_ban(ban, server, item, TRUE, ban_type); @@ -250,7 +281,7 @@ static void read_settings(void) return; g_free_not_null(default_ban_type_str); - default_ban_type = ban_parse_type(settings_get_str("ban_type")); + default_ban_type = parse_ban_type(settings_get_str("ban_type")); if (default_ban_type <= 0 || default_ban_type_str != NULL) { signal_emit("ban type changed", 1, GINT_TO_POINTER(default_ban_type)); @@ -269,7 +300,7 @@ void bans_init(void) command_bind("ban", NULL, (SIGNAL_FUNC) cmd_ban); command_bind("unban", NULL, (SIGNAL_FUNC) cmd_unban); - command_set_options("ban", "+type"); + command_set_options("ban", "normal user host domain +custom"); read_settings(); signal_add("setup changed", (SIGNAL_FUNC) read_settings); |