- Implementation eventlist[] = { I_OnPostJoin, I_OnUserQuit, I_OnUserKick, I_OnUserPart, I_OnOper };
- ServerInstance->Modules->Attach(eventlist, this, 5);
+ /* 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.
+ */
+
+ if (ServerInstance->Modules->Find("m_hideoper.so"))
+ mw_added = ServerInstance->Modes->AddModeWatcher(&hideoperwatcher);
+ }
+
+ ModResult OnUserPreJoin(User* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven)
+ {
+ /* The user may have the +H umode on himself, but +H does not necessarily correspond
+ * to the +H of m_hideoper.
+ * However we only add the modewatcher when m_hideoper is loaded, so these
+ * conditions (mw_added and the user being +H) together mean the user is a hidden oper.
+ */
+
+ if (user->IsOper() && (!mw_added || !user->IsModeSet('H')))
+ privs.push_back('y');
+ return MOD_RES_PASSTHRU;