}
};
-//typedef std::vector<Shun> shunlist;
-
class CommandShun : public Command
{
public:
CommandShun(Module* Creator) : Command(Creator, "SHUN", 1, 3)
{
- flags_needed = 'o'; this->syntax = "<nick!user@host> [<duration> :<reason>]";
+ flags_needed = 'o';
+ syntax = "<nick!user@host> [<duration> :<reason>]";
}
CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
class ModuleShun : public Module, public Stats::EventListener
{
+ private:
CommandShun cmd;
- ShunFactory f;
- insp::flat_set<std::string> ShunEnabledCommands;
- bool NotifyOfShun;
+ ShunFactory shun;
+ insp::flat_set<std::string, irc::insensitive_swo> enabledcommands;
bool affectopers;
+ bool notifyuser;
+
+ bool IsShunned(LocalUser* user)
+ {
+ // Exempt the user from shuns if they are an oper and affectopers is disabled.
+ if (!affectopers && user->IsOper())
+ return false;
+
+ // Exempt the user from shuns if they are an oper with the servers/ignore-shun privilege.
+ if (user->HasPrivPermission("servers/ignore-shun"))
+ return false;
+
+ // Check whether the user is actually shunned.
+ return ServerInstance->XLines->MatchesLine("SHUN", user);
+ }
public:
ModuleShun()
void init() CXX11_OVERRIDE
{
- ServerInstance->XLines->RegisterFactory(&f);
+ ServerInstance->XLines->RegisterFactory(&shun);
}
~ModuleShun()
{
ServerInstance->XLines->DelAll("SHUN");
- ServerInstance->XLines->UnregisterFactory(&f);
+ ServerInstance->XLines->UnregisterFactory(&shun);
}
void Prioritize() CXX11_OVERRIDE
{
ConfigTag* tag = ServerInstance->Config->ConfValue("shun");
- ShunEnabledCommands.clear();
+ enabledcommands.clear();
irc::spacesepstream enabledcmds(tag->getString("enabledcommands", "ADMIN OPER PING PONG QUIT", 1));
for (std::string enabledcmd; enabledcmds.GetToken(enabledcmd); )
- {
- std::transform(enabledcmd.begin(), enabledcmd.end(), enabledcmd.begin(), ::toupper);
- ShunEnabledCommands.insert(enabledcmd);
- }
+ enabledcommands.insert(enabledcmd);
- NotifyOfShun = tag->getBool("notifyuser", true);
affectopers = tag->getBool("affectopers", false);
+ notifyuser = tag->getBool("notifyuser", true);
}
ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
{
- if (validated)
+ if (validated || !IsShunned(user))
return MOD_RES_PASSTHRU;
- // Exempt the user from shuns if:
- // (1) They are an oper and affectopers is disabled.
- // (2) They have the servers/ignore-shun privilege.
- if ((!affectopers && user->IsOper()) || user->HasPrivPermission("servers/ignore-shun"))
- return MOD_RES_PASSTHRU;
-
- if (ServerInstance->XLines->MatchesLine("SHUN", user) && !ShunEnabledCommands.count(command))
+ if (!enabledcommands.count(command))
{
- if (NotifyOfShun)
- user->WriteNotice("*** Command " + command + " not processed, as you have been blocked from issuing commands (SHUN)");
+ if (notifyuser)
+ user->WriteNotice("*** " + command + " command not processed as you have been blocked from issuing commands.");
return MOD_RES_DENY;
}