X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodules%2Fm_timedbans.cpp;h=bbbc518bdd1b7a7947464c43b83a8942ea2c7d2f;hb=8f83c6709fa531e4d1ff323eb35cd6d394419b17;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..bbbc518bd 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; @@ -102,11 +117,13 @@ found: T.chan = channel; TimedBanList.push_back(T); + const std::string addban = user->nick + " added a timed ban on " + mask + " lasting for " + ConvToStr(duration) + " seconds."; // 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); + channel->WriteAllExcept(ServerInstance->FakeClient, true, pfxchar, tmp, "NOTICE %s :%s", channel->name.c_str(), addban.c_str()); + ServerInstance->PI->SendChannelNotice(channel, pfxchar, addban); return CMD_SUCCESS; } @@ -116,6 +133,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 +161,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)); } @@ -176,15 +209,25 @@ class ModuleTimedBans : public Module setban.push_back(mask); CUList empty; - std::string expiry = "*** Timed ban on " + chan + " expired."; - cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str()); - ServerInstance->PI->SendChannelNotice(cr, '@', expiry); + const std::string expiry = "*** Timed ban on " + chan + " expired."; + // 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") ? mh->GetPrefix() : '@'; + + cr->WriteAllExcept(ServerInstance->FakeClient, true, pfxchar, empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str()); + ServerInstance->PI->SendChannelNotice(cr, pfxchar, expiry); ServerInstance->SendGlobalMode(setban, ServerInstance->FakeClient); } } } + 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);