class CommandTban : public Command
{
public:
- CommandTban (InspIRCd* Instance) : Command(Instance,"TBAN", 0, 3)
+ CommandTban (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"TBAN", 0, 3)
{
- this->source = "m_timedbans.so";
syntax = "<channel> <duration> <banmask>";
TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
}
class ModuleTimedBans : public Module
{
- CommandTban* mycommand;
+ CommandTban cmd;
public:
ModuleTimedBans(InspIRCd* Me)
- : Module(Me)
+ : Module(Me), cmd(Me, this)
{
-
- mycommand = new CommandTban(ServerInstance);
- ServerInstance->AddCommand(mycommand);
+ ServerInstance->AddCommand(&cmd);
TimedBanList.clear();
Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
ServerInstance->Modules->Attach(eventlist, this, 2);
TimedBanList.clear();
}
- virtual int OnDelBan(User* source, Channel* chan, const std::string &banmask)
+ 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();
break;
}
}
- return 0;
+ return MOD_RES_PASSTHRU;
}
virtual void OnBackgroundTimer(time_t curtime)
{
- timedbans::iterator safei;
- for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end();)
+ for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
{
- /* Safe copy of iterator, so we can erase as we iterate */
- safei = i;
- ++i;
-
- if (curtime > safei->expire)
+ if (curtime > i->expire)
{
- Channel* cr = ServerInstance->FindChan(safei->channel);
+ std::string chan = i->channel;
+ std::string mask = i->mask;
+ Channel* cr = ServerInstance->FindChan(chan);
+ i = TimedBanList.erase(i);
if (cr)
{
- std::string mask = safei->mask;
std::vector<std::string> setban;
- setban.push_back(safei->channel);
+ setban.push_back(chan);
setban.push_back("-b");
setban.push_back(mask);
CUList empty;
- cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :*** Timed ban on %s expired.", cr->name.c_str(), safei->mask.c_str());
- ServerInstance->PI->SendChannelNotice(cr, '@', "*** Timed ban on " + safei->mask + " expired.");
+ 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);
if (ServerInstance->Config->AllowHalfop)
{
- cr->WriteAllExcept(ServerInstance->FakeClient, true, '%', empty, "NOTICE %s :*** Timed ban on %s expired.", cr->name.c_str(), safei->mask.c_str());
- ServerInstance->PI->SendChannelNotice(cr, '%', "*** Timed ban on " + safei->mask + " expired.");
+ cr->WriteAllExcept(ServerInstance->FakeClient, true, '%', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str());
+ ServerInstance->PI->SendChannelNotice(cr, '%', expiry);
}
- /* Removes the ban item for us, no ::erase() needed */
- ServerInstance->PI->SendModeStr(safei->channel, std::string("-b ") + setban[2]);
ServerInstance->SendMode(setban, ServerInstance->FakeClient);
-
- if (ServerInstance->Modes->GetLastParse().empty())
- TimedBanList.erase(safei);
- }
- else
- {
- /* Where the hell did our channel go?! */
- TimedBanList.erase(safei);
+ ServerInstance->PI->SendMode(chan, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
}
}
+ else
+ ++i;
}
}