+class InvisibleWatcher : public ModeWatcher
+{
+ unsigned int& invisible;
+public:
+ InvisibleWatcher(Module* mod, unsigned int& Invisible)
+ : ModeWatcher(mod, 'i', MODETYPE_USER), invisible(Invisible)
+ {
+ }
+
+ void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding, ModeType type)
+ {
+ if (dest->registered != REG_ALL)
+ return;
+
+ if (adding)
+ invisible++;
+ else
+ invisible--;
+ }
+};
+
+class ModuleLusers : public Module
+{
+ LusersCounters counters;
+ CommandLusers cmd;
+ InvisibleWatcher mw;
+
+ public:
+ ModuleLusers()
+ : cmd(this, counters), mw(this, counters.invisible)
+ {
+ }
+
+ void init()
+ {
+ ServerInstance->Modules->AddService(cmd);
+ Implementation events[] = { I_OnPostConnect, I_OnUserQuit };
+ ServerInstance->Modules->Attach(events, this, sizeof(events)/sizeof(Implementation));
+ ServerInstance->Modes->AddModeWatcher(&mw);
+ }
+
+ void OnPostConnect(User* user)
+ {
+ counters.UpdateMaxUsers();
+ if (user->IsModeSet('i'))
+ counters.invisible++;
+ }
+
+ void OnUserQuit(User* user, const std::string& message, const std::string& oper_message)
+ {
+ if (user->IsModeSet('i'))
+ counters.invisible--;
+ }
+
+ ~ModuleLusers()
+ {
+ ServerInstance->Modes->DelModeWatcher(&mw);
+ }
+
+ Version GetVersion()
+ {
+ return Version("LUSERS", VF_VENDOR | VF_CORE);
+ }
+};