X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_timedbans.cpp;h=93245432d996332e374d5beaf1dab0ad592036dc;hb=3624c137a6db85eaab0372550c9dca79d6d21e55;hp=e10a622e90aa4187f357dfe17eea72953997c0a7;hpb=886f1ba488a5ab9d7fe4d7b4ac6b9c9dc2841738;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index e10a622e9..93245432d 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -70,7 +70,7 @@ class CommandTban : public Command unsigned long expire = duration + ServerInstance->Time(); if (duration < 1) { - user->WriteServ("NOTICE "+user->nick+" :Invalid ban time"); + user->WriteNotice("Invalid ban time"); return CMD_FAILURE; } std::string mask = parameters[2]; @@ -80,20 +80,17 @@ class CommandTban : public Command bool isextban = ((mask.size() > 2) && (mask[1] == ':')); if (!isextban && !ServerInstance->IsValidMask(mask)) mask.append("!*@*"); - if ((mask.length() > 250) || (!ServerInstance->IsValidMask(mask) && !isextban)) - { - user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask"); - 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 (ServerInstance->Modes->GetLastParse().empty()) + { + user->WriteNotice("Invalid ban mask"); + return CMD_FAILURE; + } + CUList tmp; T.channel = channelname; T.mask = mask; @@ -114,27 +111,22 @@ found: } }; -class ModuleTimedBans : public Module +class BanWatcher : public ModeWatcher { - CommandTban cmd; public: - ModuleTimedBans() - : cmd(this) + BanWatcher(Module* parent) + : ModeWatcher(parent, "ban", MODETYPE_CHANNEL) { } - void init() + void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding) { - ServerInstance->Modules->AddService(cmd); - Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer }; - ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); - } + if (adding) + return; - virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask) - { irc::string listitem = banmask.c_str(); irc::string thischan = chan->name.c_str(); - for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++) + for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); ++i) { irc::string target = i->mask.c_str(); irc::string tchan = i->channel.c_str(); @@ -144,10 +136,35 @@ class ModuleTimedBans : public Module break; } } - return MOD_RES_PASSTHRU; + } +}; + +class ModuleTimedBans : public Module +{ + CommandTban cmd; + BanWatcher banwatcher; + + public: + ModuleTimedBans() + : cmd(this) + , banwatcher(this) + { + } + + void init() CXX11_OVERRIDE + { + ServerInstance->Modules->AddService(cmd); + Implementation eventlist[] = { I_OnBackgroundTimer }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); + ServerInstance->Modes->AddModeWatcher(&banwatcher); + } + + ~ModuleTimedBans() + { + ServerInstance->Modes->DelModeWatcher(&banwatcher); } - virtual void OnBackgroundTimer(time_t curtime) + void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE { timedbans expired; for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();) @@ -178,12 +195,12 @@ class ModuleTimedBans : public Module cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str()); ServerInstance->PI->SendChannelNotice(cr, '@', expiry); - ServerInstance->SendGlobalMode(setban, ServerInstance->FakeClient); + ServerInstance->Modes->Process(setban, ServerInstance->FakeClient); } } } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { return Version("Adds timed bans", VF_COMMON | VF_VENDOR); }