From 8723866b4cdf100892677ab5c1619fcee9536d9b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 13 Apr 2015 15:40:26 +0200 Subject: m_timedbans Store Channel pointer in struct TimedBan --- src/modules/m_timedbans.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 497ac2569..f633bc3e2 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -32,6 +32,7 @@ class TimedBan std::string channel; std::string mask; time_t expire; + Channel* chan; }; typedef std::vector timedbans; @@ -98,6 +99,7 @@ found: T.channel = channelname; T.mask = mask; T.expire = expire + (IS_REMOTE(user) ? 5 : 0); + T.chan = channel; TimedBanList.push_back(T); // If halfop is loaded, send notice to halfops and above, otherwise send to ops and above -- cgit v1.2.3 From 0243179509eb8a561b62c7845dc1322fcd94654a Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 13 Apr 2015 15:42:06 +0200 Subject: m_timedbans On channel destruction remove all timed bans belonging to the channel from internal bookkeeping --- src/modules/m_timedbans.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index f633bc3e2..ef1ae4c48 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -116,6 +116,22 @@ found: } }; +class ChannelMatcher +{ + Channel* const chan; + + public: + ChannelMatcher(Channel* ch) + : chan(ch) + { + } + + bool operator()(const TimedBan& tb) const + { + return (tb.chan == chan); + } +}; + class ModuleTimedBans : public Module { CommandTban cmd; @@ -128,7 +144,7 @@ class ModuleTimedBans : public Module void init() { ServerInstance->Modules->AddService(cmd); - Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer }; + Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer, I_OnChannelDelete }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } @@ -185,6 +201,12 @@ class ModuleTimedBans : public Module } } + void OnChannelDelete(Channel* chan) + { + // Remove all timed bans affecting the channel from internal bookkeeping + TimedBanList.erase(std::remove_if(TimedBanList.begin(), TimedBanList.end(), ChannelMatcher(chan)), TimedBanList.end()); + } + virtual Version GetVersion() { return Version("Adds timed bans", VF_COMMON | VF_VENDOR); -- cgit v1.2.3 From b7526f6efd47ed87dc67adfa70f09c9b83adf9a8 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 13 Apr 2015 15:48:00 +0200 Subject: m_timedbans Extract IsBanSet() to a function --- src/modules/m_timedbans.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index ef1ae4c48..754b4c3a0 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -42,6 +42,16 @@ timedbans TimedBanList; */ class CommandTban : public Command { + static bool IsBanSet(Channel* chan, const std::string& mask) + { + for (BanList::const_iterator i = chan->bans.begin(); i != chan->bans.end(); ++i) + { + if (!strcasecmp(i->data.c_str(), mask.c_str())) + return true; + } + return false; + } + public: CommandTban(Module* Creator) : Command(Creator,"TBAN", 3) { @@ -90,11 +100,9 @@ class CommandTban : public Command // use CallHandler to make it so that the user sets the mode // themselves ServerInstance->Parser->CallHandler("MODE",setban,user); - for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++) - if (!strcasecmp(i->data.c_str(), mask.c_str())) - goto found; - return CMD_FAILURE; -found: + if (!IsBanSet(channel, mask)) + return CMD_FAILURE; + CUList tmp; T.channel = channelname; T.mask = mask; -- cgit v1.2.3 From 4e24fb7c19cff866eda602349fbafce78b7e4c51 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 13 Apr 2015 15:49:29 +0200 Subject: m_timedbans Notice user when trying to set a ban that's already set --- src/modules/m_timedbans.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 754b4c3a0..b47327704 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -96,6 +96,13 @@ class CommandTban : public Command user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask"); return CMD_FAILURE; } + + if (IsBanSet(channel, mask)) + { + user->WriteServ("NOTICE %s :Ban already set", user->nick.c_str()); + return CMD_FAILURE; + } + setban.push_back(mask); // use CallHandler to make it so that the user sets the mode // themselves -- cgit v1.2.3