]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ircv3_msgid.cpp
Improve the header messages of the filter and permchannels modules.
[user/henk/code/inspircd.git] / src / modules / m_ircv3_msgid.cpp
index 00854a19cbda5266631c16189aa65886b75885c8..ca32f28a4e31e2cfcac6293ebee94278cb68c3cd 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2019 Peter Powell <petpow@saberuk.com>
- *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2019-2020 Sadie Powell <sadie@witchery.services>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
 
 
 #include "inspircd.h"
-#include "modules/cap.h"
 #include "modules/ctctags.h"
 
-class MsgIdGenerator
-{
-       uint64_t counter;
-       std::string strid;
-       const std::string::size_type baselen;
-
- public:
-       MsgIdGenerator()
-               : counter(0)
-               , strid(InspIRCd::Format("%s~%lu~", ServerInstance->Config->GetSID().c_str(), ServerInstance->startup_time))
-               , baselen(strid.length())
-       {
-       }
-
-       const std::string& GetNext()
-       {
-               strid.erase(baselen);
-               strid.append(ConvToStr(counter++));
-               return strid;
-       }
-};
-
 class MsgIdTag : public ClientProtocol::MessageTagProvider
 {
  private:
-       Cap::Reference ctctagcap;
+       CTCTags::CapReference ctctagcap;
 
  public:
-       MsgIdGenerator generator;
-
        MsgIdTag(Module* mod)
                : ClientProtocol::MessageTagProvider(mod)
-               , ctctagcap(mod, "message-tags")
-       {
-       }
-
-       void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
+               , ctctagcap(mod)
        {
-               const ClientProtocol::TagMap& tags = msg.GetTags();
-               if (tags.find("msgid") == tags.end())
-                       msg.AddTag("msgid", this, generator.GetNext());
        }
 
        ModResult OnProcessTag(User* user, const std::string& tagname, std::string& tagvalue) CXX11_OVERRIDE
@@ -80,12 +47,35 @@ class MsgIdTag : public ClientProtocol::MessageTagProvider
        }
 };
 
+class MsgIdGenerator
+{
+       uint64_t counter;
+       std::string strid;
+       const std::string::size_type baselen;
+
+ public:
+       MsgIdGenerator()
+               : counter(0)
+               , strid(InspIRCd::Format("%s~%lu~", ServerInstance->Config->GetSID().c_str(), ServerInstance->startup_time))
+               , baselen(strid.length())
+       {
+       }
+
+       const std::string& GetNext()
+       {
+               strid.erase(baselen);
+               strid.append(ConvToStr(counter++));
+               return strid;
+       }
+};
+
 class ModuleMsgId
        : public Module
        , public CTCTags::EventListener
 {
  private:
        MsgIdTag tag;
+       MsgIdGenerator generator;
 
        ModResult CopyMessageId(const ClientProtocol::TagMap& tags_in, ClientProtocol::TagMap& tags_out)
        {
@@ -95,7 +85,11 @@ class ModuleMsgId
                        // If the remote server has sent a message identifier we should use that as
                        // identifiers need to be the same on all sides of the network.
                        tags_out.insert(*iter);
+                       return MOD_RES_PASSTHRU;
                }
+
+               // Otherwise, we can just create a new message identifier.
+               tags_out.insert(std::make_pair("msgid", ClientProtocol::MessageTagData(&tag, generator.GetNext())));
                return MOD_RES_PASSTHRU;
        }
 
@@ -118,7 +112,7 @@ class ModuleMsgId
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides the msgid IRCv3 tag", VF_VENDOR);
+               return Version("Provides support for the IRCv3 Message IDs specification.", VF_VENDOR);
        }
 };