user->nick.c_str(), channel->name.c_str());
return CMD_FAILURE;
}
- if (!ServerInstance->IsValidMask(parameters[2]))
- {
- user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask");
- return CMD_FAILURE;
- }
+
TimedBan T;
std::string channelname = parameters[0];
- long duration = ServerInstance->Duration(parameters[1]);
+ unsigned long duration = InspIRCd::Duration(parameters[1]);
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];
std::vector<std::string> setban;
setban.push_back(parameters[0]);
setban.push_back("+b");
- setban.push_back(parameters[2]);
- // use CallCommandHandler to make it so that the user sets the mode
+ bool isextban = ((mask.size() > 2) && (mask[1] == ':'));
+ if (!isextban && !ServerInstance->IsValidMask(mask))
+ mask.append("!*@*");
+
+ setban.push_back(mask);
+ // use CallHandler to make it so that the user sets the mode
// themselves
- ServerInstance->CallCommandHandler("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:
+ ServerInstance->Parser->CallHandler("MODE",setban,user);
+ if (ServerInstance->Modes->GetLastParse().empty())
+ {
+ user->WriteNotice("Invalid ban mask");
+ return CMD_FAILURE;
+ }
+
CUList tmp;
T.channel = channelname;
T.mask = mask;
T.expire = expire + (IS_REMOTE(user) ? 5 : 0);
TimedBanList.push_back(T);
- channel->WriteAllExcept(ServerInstance->FakeClient, true, '@', 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);
+
+ // 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") ? '%' : '@';
+
+ 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;
}
}
};
-class ModuleTimedBans : public Module
+class BanWatcher : public ModeWatcher
{
- CommandTban cmd;
public:
- ModuleTimedBans()
- : cmd(this)
+ BanWatcher(Module* parent)
+ : ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
{
- ServerInstance->AddCommand(&cmd);
- TimedBanList.clear();
- Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
- ServerInstance->Modules->Attach(eventlist, this, 2);
}
- virtual ~ModuleTimedBans()
+ void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding)
{
- TimedBanList.clear();
- }
+ 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();
break;
}
}
- return MOD_RES_PASSTHRU;
}
+};
- virtual void OnBackgroundTimer(time_t curtime)
+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);
+ }
+
+ void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE
{
timedbans expired;
for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
}
}
- virtual Version GetVersion()
+ Version GetVersion() CXX11_OVERRIDE
{
return Version("Adds timed bans", VF_COMMON | VF_VENDOR);
}
};
MODULE_INIT(ModuleTimedBans)
-