bool NeedsOper() { return true; }
};
+class ModuleOperPrefixMode;
+class HideOperWatcher : public ModeWatcher
+{
+ ModuleOperPrefixMode* parentmod;
+
+ public:
+ HideOperWatcher(ModuleOperPrefixMode* parent);
+ void AfterMode(User* source, User* dest, Channel* channel, const std::string ¶meter, bool adding);
+};
+
class ModuleOperPrefixMode : public Module
{
- private:
OperPrefixMode opm;
+ HideOperWatcher hideoperwatcher;
+
public:
ModuleOperPrefixMode()
- : opm(this)
+ : opm(this), hideoperwatcher(this)
{
}
- void init()
+ void init() CXX11_OVERRIDE
{
ServerInstance->Modules->AddService(opm);
Implementation eventlist[] = { I_OnUserPreJoin, I_OnPostOper };
- ServerInstance->Modules->Attach(eventlist, this, 2);
+ ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
/* To give clients a chance to learn about the new prefix we don't give +y to opers
* right now. That means if the module was loaded after opers have joined channels
* they need to rejoin them in order to get the oper prefix.
*/
+
+ ServerInstance->Modes->AddModeWatcher(&hideoperwatcher);
}
- ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string& privs, const std::string& keygiven)
+ ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
{
- if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
+ if ((user->IsOper()) && (user->IsModeSet('H')))
privs.push_back('y');
return MOD_RES_PASSTHRU;
}
}
}
- void OnPostOper(User* user, const std::string& opername, const std::string& opertype)
+ void OnPostOper(User* user, const std::string& opername, const std::string& opertype) CXX11_OVERRIDE
{
- if (IS_LOCAL(user))
+ if (IS_LOCAL(user) && (!user->IsModeSet('H')))
SetOperPrefix(user, true);
}
+
~ModuleOperPrefixMode()
{
+ ServerInstance->Modes->DelModeWatcher(&hideoperwatcher);
}
- Version GetVersion()
+ Version GetVersion() CXX11_OVERRIDE
{
return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
}
+
+ void Prioritize()
+ {
+ // m_opermodes may set +H on the oper to hide him, we don't want to set the oper prefix in that case
+ Module* opermodes = ServerInstance->Modules->Find("m_opermodes.so");
+ ServerInstance->Modules->SetPriority(this, I_OnPostOper, PRIORITY_AFTER, opermodes);
+ }
};
+HideOperWatcher::HideOperWatcher(ModuleOperPrefixMode* parent)
+ : ModeWatcher(parent, "hideoper", MODETYPE_USER)
+ , parentmod(parent)
+{
+}
+
+void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding)
+{
+ if (IS_LOCAL(dest))
+ parentmod->SetOperPrefix(dest, !adding);
+}
+
MODULE_INIT(ModuleOperPrefixMode)