]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_botmode.cpp
Fix cloaking not ignoring the case of a user's hostname.
[user/henk/code/inspircd.git] / src / modules / m_botmode.cpp
index 67f692b8623077a4fd40b77a42f163f5346bcc86..44241e82c5e83151391bb48a33cba37865f50a77 100644 (file)
 
 
 #include "inspircd.h"
+#include "modules/cap.h"
+#include "modules/whois.h"
 
-/** Handles user mode +B
- */
-class BotMode : public SimpleUserModeHandler
+enum
+{
+       // From UnrealIRCd.
+       RPL_WHOISBOT = 335
+};
+
+class BotTag : public ClientProtocol::MessageTagProvider
 {
+ private:
+       SimpleUserModeHandler& botmode;
+       Cap::Reference ctctagcap;
+
  public:
-       BotMode(Module* Creator) : SimpleUserModeHandler(Creator, "bot", 'B') { }
+       BotTag(Module* mod, SimpleUserModeHandler& bm)
+               : ClientProtocol::MessageTagProvider(mod)
+               , botmode(bm)
+               , ctctagcap(mod, "message-tags")
+       {
+       }
+
+       void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
+       {
+               User* const user = msg.GetSourceUser();
+               if (user && user->IsModeSet(botmode))
+                       msg.AddTag("inspircd.org/bot", this, "");
+       }
+
+       bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE
+       {
+               return ctctagcap.get(user);
+       }
 };
 
-class ModuleBotMode : public Module
+class ModuleBotMode : public Module, public Whois::EventListener
 {
-       BotMode bm;
+ private:
+       SimpleUserModeHandler bm;
+       BotTag tag;
+
  public:
        ModuleBotMode()
-               : bm(this)
+               : Whois::EventListener(this)
+               , bm(this, "bot", 'B')
+               , tag(this, bm)
        {
        }
 
@@ -43,11 +75,11 @@ class ModuleBotMode : public Module
                return Version("Provides user mode +B to mark the user as a bot",VF_VENDOR);
        }
 
-       void OnWhois(User* src, User* dst) CXX11_OVERRIDE
+       void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
        {
-               if (dst->IsModeSet(bm))
+               if (whois.GetTarget()->IsModeSet(bm))
                {
-                       ServerInstance->SendWhoisLine(src, dst, 335, dst->nick+" :is a bot on "+ServerInstance->Config->Network);
+                       whois.SendLine(RPL_WHOISBOT, "is a bot on " + ServerInstance->Config->Network);
                }
        }
 };