diff options
author | Adam <Adam@anope.org> | 2013-09-27 10:51:46 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-09-27 19:11:02 -0400 |
commit | b3061087401a4f8d22b122fa4dfd11c98e75da3c (patch) | |
tree | d00e110778fe2859dc8d51ef4984af8cbc76b544 /modules/commands/os_ignore.cpp | |
parent | 12a0311aaa783385bba3194e92ed0eb4665621ed (diff) |
Fix /os ignore del on nicks
Diffstat (limited to 'modules/commands/os_ignore.cpp')
-rw-r--r-- | modules/commands/os_ignore.cpp | 99 |
1 files changed, 59 insertions, 40 deletions
diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index 22d426fda..fd623c20e 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -19,33 +19,8 @@ class OSIgnoreService : public IgnoreService IgnoreData* AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) anope_override { - /* If it s an existing user, we ignore the hostmask. */ - Anope::string realmask = mask; - size_t user, host; - - User *u = User::Find(mask, true); - if (u) - realmask = "*!*@" + u->host; - /* Determine whether we get a nick or a mask. */ - else if ((host = mask.find('@')) != Anope::string::npos) - { - /* Check whether we have a nick too.. */ - if ((user = mask.find('!')) != Anope::string::npos) - { - /* this should never happen */ - if (user > host) - return NULL; - } - else - /* We have user@host. Add nick wildcard. */ - realmask = "*!" + mask; - } - /* We only got a nick.. */ - else - realmask = mask + "!*@*"; - /* Check if we already got an identical entry. */ - IgnoreData *ign = this->Find(realmask); + IgnoreData *ign = this->Find(mask); if (ign != NULL) { if (!delta) @@ -58,7 +33,7 @@ class OSIgnoreService : public IgnoreService else { IgnoreData newign; - newign.mask = realmask; + newign.mask = mask; newign.creator = creator; newign.reason = reason; newign.time = delta ? Anope::CurTime + delta : 0; @@ -144,6 +119,36 @@ class OSIgnoreService : public IgnoreService class CommandOSIgnore : public Command { private: + Anope::string RealMask(const Anope::string &mask) + { + /* If it s an existing user, we ignore the hostmask. */ + User *u = User::Find(mask, true); + if (u) + return "*!*@" + u->host; + + size_t host = mask.find('@'); + /* Determine whether we get a nick or a mask. */ + if (host != Anope::string::npos) + { + size_t user = mask.find('!'); + /* Check whether we have a nick too.. */ + if (user != Anope::string::npos) + { + if (user > host) + /* this should never happen */ + return ""; + else + return mask; + } + else + /* We have user@host. Add nick wildcard. */ + return "*!" + mask; + } + + /* We only got a nick.. */ + return mask + "!*@*"; + } + void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (!ignore_service) @@ -168,20 +173,25 @@ class CommandOSIgnore : public Command return; } - ignore_service->AddIgnore(nick, source.GetNick(), reason, t); + Anope::string mask = RealMask(nick); + if (mask.empty()) + { + source.Reply(BAD_USERHOST_MASK); + return; + } + + ignore_service->AddIgnore(mask, source.GetNick(), reason, t); if (!t) { - source.Reply(_("\002%s\002 will now permanently be ignored."), nick.c_str()); - Log(LOG_ADMIN, source, this) << "to add a permanent ignore for " << nick; + source.Reply(_("\002%s\002 will now permanently be ignored."), mask.c_str()); + Log(LOG_ADMIN, source, this) << "to add a permanent ignore for " << mask; } else { - source.Reply(_("\002%s\002 will now be ignored for \002%s\002."), nick.c_str(), Anope::Duration(t, source.GetAccount()).c_str()); - Log(LOG_ADMIN, source, this) << "to add an ignore on " << nick << " for " << Anope::Duration(t); + source.Reply(_("\002%s\002 will now be ignored for \002%s\002."), mask.c_str(), Anope::Duration(t, source.GetAccount()).c_str()); + Log(LOG_ADMIN, source, this) << "to add an ignore on " << mask << " for " << Anope::Duration(t); } } - - return; } void DoList(CommandSource &source) @@ -239,16 +249,25 @@ class CommandOSIgnore : public Command const Anope::string nick = params.size() > 1 ? params[1] : ""; if (nick.empty()) + { this->OnSyntaxError(source, "DEL"); - else if (ignore_service->DelIgnore(nick)) + return; + } + + Anope::string mask = RealMask(nick); + if (mask.empty()) { - Log(LOG_ADMIN, source, this) << "to remove an ignore on " << nick; - source.Reply(_("\002%s\002 will no longer be ignored."), nick.c_str()); + source.Reply(BAD_USERHOST_MASK); + return; } - else - source.Reply(_("Nick \002%s\002 not found on ignore list."), nick.c_str()); - return; + if (ignore_service->DelIgnore(mask)) + { + Log(LOG_ADMIN, source, this) << "to remove an ignore on " << mask; + source.Reply(_("\002%s\002 will no longer be ignored."), mask.c_str()); + } + else + source.Reply(_("Nick \002%s\002 not found on ignore list."), mask.c_str()); } void DoClear(CommandSource &source) |