]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_showwhois.cpp
Hide User#host and User#dhost and use accessors to modify them.
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
index f4997d8dcd07f0a05d9b52e846676f9f202391cc..99774563d3d827a7b7612210afb8eb8962c7e87d 100644 (file)
 
 #include "inspircd.h"
 
-/* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
-
 /** Handle user mode +W
  */
 class SeeWhois : public SimpleUserModeHandler
 {
  public:
-       SeeWhois(Module* Creator, bool IsOpersOnly) : SimpleUserModeHandler(Creator, "showwhois", 'W')
+       SeeWhois(Module* Creator)
+               : SimpleUserModeHandler(Creator, "showwhois", 'W')
        {
-               oper = IsOpersOnly;
+       }
+
+       void SetOperOnly(bool operonly)
+       {
+               oper = operonly;
        }
 };
 
 class WhoisNoticeCmd : public Command
 {
  public:
-       WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 1)
+       WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 2)
        {
                flags_needed = FLAG_SERVERONLY;
        }
@@ -47,7 +50,7 @@ class WhoisNoticeCmd : public Command
        void HandleFast(User* dest, User* src)
        {
                dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
-                       (dest->HasPrivPermission("users/auspex") ? src->host : src->dhost) +
+                       src->GetHost(dest->HasPrivPermission("users/auspex")) + 
                        ") did a /whois on you");
        }
 
@@ -66,46 +69,39 @@ class WhoisNoticeCmd : public Command
        }
 };
 
-class ModuleShowwhois : public Module
+class ModuleShowwhois : public Module, public Whois::EventListener
 {
        bool ShowWhoisFromOpers;
-       SeeWhois* sw;
+       SeeWhois sw;
        WhoisNoticeCmd cmd;
 
  public:
 
        ModuleShowwhois()
-               : sw(NULL), cmd(this)
+               : Whois::EventListener(this)
+               , sw(this)
+               , cmd(this)
        {
        }
 
-       void init()
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
 
-               bool OpersOnly = tag->getBool("opersonly", true);
+               sw.SetOperOnly(tag->getBool("opersonly", true));
                ShowWhoisFromOpers = tag->getBool("showfromopers", true);
-
-               sw = new SeeWhois(this, OpersOnly);
-               ServerInstance->Modules->AddService(*sw);
-               ServerInstance->Modules->AddService(cmd);
-               Implementation eventlist[] = { I_OnWhois };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleShowwhois()
-       {
-               delete sw;
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
        }
 
-       void OnWhois(User* source, User* dest)
+       void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
        {
-               if (!dest->IsModeSet('W') || source == dest)
+               User* const source = whois.GetSource();
+               User* const dest = whois.GetTarget();
+               if (!dest->IsModeSet(sw) || whois.IsSelfWhois())
                        return;
 
                if (!ShowWhoisFromOpers && source->IsOper())
@@ -118,14 +114,11 @@ class ModuleShowwhois : public Module
                else
                {
                        std::vector<std::string> params;
-                       params.push_back(dest->server);
-                       params.push_back("WHOISNOTICE");
                        params.push_back(dest->uuid);
                        params.push_back(source->uuid);
-                       ServerInstance->PI->SendEncapsulatedData(params);
+                       ServerInstance->PI->SendEncapsulatedData(dest->server->GetName(), cmd.name, params);
                }
        }
 };
 
 MODULE_INIT(ModuleShowwhois)
-