X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_timedbans.cpp;h=61095d6ebae2f2ed70ce316ff21c1f1f66fc2024;hb=a5d110282a864fd2e91b51ce360a977cd0643657;hp=f633bc3e209d6ea5b19ffea5bdd61411814d1018;hpb=8723866b4cdf100892677ab5c1619fcee9536d9b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index f633bc3e2..61095d6eb 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) { @@ -86,15 +96,20 @@ 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 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; @@ -104,7 +119,7 @@ found: // If halfop is loaded, send notice to halfops and above, otherwise send to ops and above ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL); - char pfxchar = (mh && mh->name == "halfop") ? '%' : '@'; + char pfxchar = (mh && mh->name == "halfop") ? mh->GetPrefix() : '@'; channel->WriteAllExcept(ServerInstance->FakeClient, true, pfxchar, tmp, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name.c_str(), user->nick.c_str(), mask.c_str(), duration); return CMD_SUCCESS; @@ -116,6 +131,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 +159,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 +216,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);