aboutsummaryrefslogtreecommitdiffstats
path: root/include/modules
diff options
context:
space:
mode:
authorGravatar Sadie Powell2020-05-07 23:31:22 +0100
committerGravatar Sadie Powell2020-05-07 23:45:52 +0100
commitdac52889545cb71e006a1934668db91554f96822 (patch)
tree54b28e6bd57db8f22e085e1b0f16e31c23aece60 /include/modules
parentDeduplicate extban parsing. (diff)
Implement support for inverted extbans.
Diffstat (limited to 'include/modules')
-rw-r--r--include/modules/extban.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/include/modules/extban.h b/include/modules/extban.h
index 9172c053d..a8f986e9e 100644
--- a/include/modules/extban.h
+++ b/include/modules/extban.h
@@ -43,9 +43,10 @@ namespace ExtBan
* @param banentry The ban entry to parse.
* @param name The parsed name of the extban.
* @param value The parsed value of the extban.
+ * @param inverted Whether the extban is inverted.
* @return True if an extban was extracted from the ban entry; otherwise, false.
*/
- inline bool Parse(const std::string& banentry, std::string& name, std::string& value);
+ inline bool Parse(const std::string& banentry, std::string& name, std::string& value, bool& inverted);
}
/** Manager for the extban system. */
@@ -261,14 +262,22 @@ class ExtBan::EventListener
virtual ModResult OnExtBanCheck(User* user, Channel* chan, ExtBan::Base* extban) = 0;
};
-inline bool ExtBan::Parse(const std::string& banentry, std::string& name, std::string& value)
+inline bool ExtBan::Parse(const std::string& banentry, std::string& name, std::string& value, bool& inverted)
{
- // The mask must be in the format <letter>:<value> or <name>:<value>.
- size_t endpos = banentry.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+ // The mask must be in the format [!]<letter>:<value> or [!]<name>:<value>.
+ inverted = false;
+ size_t startpos = 0;
+ if (banentry[0] == '!')
+ {
+ inverted = true;
+ startpos++;
+ }
+
+ size_t endpos = banentry.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", startpos);
if (endpos == std::string::npos || banentry[endpos] != ':')
return false;
- name.assign(banentry, 0, endpos);
+ name.assign(banentry, startpos, endpos - startpos);
value.assign(banentry, endpos + 1);
return true;
}