#include "inspircd.h"
+#include "listmode.h"
/** Holds a timed ban
*/
std::string channel;
std::string mask;
time_t expire;
+ Channel* chan;
};
typedef std::vector<TimedBan> timedbans;
*/
class CommandTban : public Command
{
+ ChanModeReference banmode;
+
+ bool IsBanSet(Channel* chan, const std::string& mask)
+ {
+ ListModeBase* banlm = static_cast<ListModeBase*>(*banmode);
+ const ListModeBase::ModeList* bans = banlm->GetList(chan);
+ if (bans)
+ {
+ for (ListModeBase::ModeList::const_iterator i = bans->begin(); i != bans->end(); ++i)
+ {
+ const ListModeBase::ListItem& ban = *i;
+ if (!strcasecmp(ban.mask.c_str(), mask.c_str()))
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public:
CommandTban(Module* Creator) : Command(Creator,"TBAN", 3)
+ , banmode(Creator, "ban")
{
syntax = "<channel> <duration> <banmask>";
}
if (!isextban && !InspIRCd::IsValidMask(mask))
mask.append("!*@*");
+ if (IsBanSet(channel, mask))
+ {
+ user->WriteNotice("Ban already set");
+ return CMD_FAILURE;
+ }
+
Modes::ChangeList setban;
setban.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), mask);
// Pass the user (instead of ServerInstance->FakeClient) to ModeHandler::Process() to
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
}
};
+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;
}
}
+ 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());
+ }
+
Version GetVersion() CXX11_OVERRIDE
{
return Version("Adds timed bans", VF_COMMON | VF_VENDOR);