diff options
author | Peter Powell <petpow@saberuk.com> | 2019-07-19 14:12:13 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-07-19 14:17:10 +0100 |
commit | e2fcf7b3b15f86fec250b7b784bdf3d0631048c6 (patch) | |
tree | c0fea58c832b87abd3f5be1f920aaa5bfff475aa /src/modules/m_spanningtree | |
parent | a9989ac3978bd6e1f9e915aeed399d9db327c235 (diff) |
Add an event for adding tags to S2S messages.
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r-- | src/modules/m_spanningtree/commandbuilder.h | 52 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.h | 7 | ||||
-rw-r--r-- | src/modules/m_spanningtree/misccommands.cpp | 36 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treeserver.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket1.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 1 |
8 files changed, 75 insertions, 26 deletions
diff --git a/src/modules/m_spanningtree/commandbuilder.h b/src/modules/m_spanningtree/commandbuilder.h index 4913120e0..6159d7b8a 100644 --- a/src/modules/m_spanningtree/commandbuilder.h +++ b/src/modules/m_spanningtree/commandbuilder.h @@ -26,28 +26,53 @@ class TreeServer; class CmdBuilder { protected: + /** The raw message contents. */ std::string content; + /** Tags which have been added to this message. */ + ClientProtocol::TagMap tags; + + /** The size of tags within the contents. */ + size_t tagsize; + + /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a server target. */ + void FireEvent(Server* target, const char* cmd, ClientProtocol::TagMap& taglist); + + /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a user target. */ + void FireEvent(User* target, const char* cmd, ClientProtocol::TagMap& taglist); + + /** Updates the tag string within the buffer. */ + void UpdateTags(); + public: CmdBuilder(const char* cmd) : content(1, ':') + , tagsize(0) { content.append(ServerInstance->Config->GetSID()); push(cmd); + FireEvent(ServerInstance->FakeClient->server, cmd, tags); } CmdBuilder(TreeServer* src, const char* cmd) : content(1, ':') + , tagsize(0) { content.append(src->GetID()); push(cmd); + FireEvent(src, cmd, tags); } CmdBuilder(User* src, const char* cmd) : content(1, ':') + , tagsize(0) { content.append(src->uuid); push(cmd); + if (src == ServerInstance->FakeClient) + FireEvent(src->server, cmd, tags); + else + FireEvent(src, cmd, tags); } CmdBuilder& push_raw(const std::string& s) @@ -119,27 +144,12 @@ class CmdBuilder return *this; } - CmdBuilder& push_tags(const ClientProtocol::TagMap& tags) - { - if (!tags.empty()) - { - char separator = '@'; - std::string taglist; - for (ClientProtocol::TagMap::const_iterator iter = tags.begin(); iter != tags.end(); ++iter) - { - taglist.push_back(separator); - separator = ';'; - - taglist.append(iter->first); - if (!iter->second.value.empty()) - { - taglist.push_back('='); - taglist.append(iter->second.value); - } - } - taglist.push_back(' '); - content.insert(0, taglist); - } + CmdBuilder& push_tags(ClientProtocol::TagMap newtags) + { + // It has to be this way around so new tags get priority. + newtags.insert(tags.begin(), tags.end()); + std::swap(tags, newtags); + UpdateTags(); return *this; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 561eed2fb..484d72e6d 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -25,7 +25,6 @@ #include "socket.h" #include "xline.h" #include "iohook.h" -#include "modules/server.h" #include "resolvers.h" #include "main.h" @@ -47,6 +46,7 @@ ModuleSpanningTree::ModuleSpanningTree() , currmembid(0) , broadcasteventprov(this, "event/server-broadcast") , linkeventprov(this, "event/server-link") + , messageeventprov(this, "event/server-message") , synceventprov(this, "event/server-sync") , sslapi(this) , DNS(this, "DNS") diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 1aeffbc72..bc31a9aea 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -29,6 +29,7 @@ #include "modules/ssl.h" #include "modules/stats.h" #include "modules/ctctags.h" +#include "modules/server.h" #include "servercommand.h" #include "commands.h" #include "protocolinterface.h" @@ -99,6 +100,9 @@ class ModuleSpanningTree /** Event provider for our link events. */ Events::ModuleEventProvider linkeventprov; + /** Event provider for our message events. */ + Events::ModuleEventProvider messageeventprov; + /** Event provider for our sync events. */ Events::ModuleEventProvider synceventprov; @@ -169,6 +173,9 @@ class ModuleSpanningTree /** Retrieves the event provider for link events. */ const Events::ModuleEventProvider& GetLinkEventProvider() const { return linkeventprov; } + /** Retrieves the event provider for message events. */ + const Events::ModuleEventProvider& GetMessageEventProvider() const { return messageeventprov; } + /** Retrieves the event provider for sync events. */ const Events::ModuleEventProvider& GetSyncEventProvider() const { return synceventprov; } diff --git a/src/modules/m_spanningtree/misccommands.cpp b/src/modules/m_spanningtree/misccommands.cpp index 8fc1b178f..1d4104f28 100644 --- a/src/modules/m_spanningtree/misccommands.cpp +++ b/src/modules/m_spanningtree/misccommands.cpp @@ -29,6 +29,42 @@ #include "commands.h" #include "treeserver.h" +void CmdBuilder::FireEvent(Server* target, const char* cmd, ClientProtocol::TagMap& taglist) +{ + FOREACH_MOD_CUSTOM(Utils->Creator->GetMessageEventProvider(), ServerProtocol::MessageEventListener, OnBuildMessage, (target, cmd, taglist)); + UpdateTags(); +} + +void CmdBuilder::FireEvent(User* target, const char* cmd, ClientProtocol::TagMap& taglist) +{ + FOREACH_MOD_CUSTOM(Utils->Creator->GetMessageEventProvider(), ServerProtocol::MessageEventListener, OnBuildMessage, (target, cmd, taglist)); + UpdateTags(); +} + +void CmdBuilder::UpdateTags() +{ + std::string taglist; + if (!tags.empty()) + { + char separator = '@'; + for (ClientProtocol::TagMap::const_iterator iter = tags.begin(); iter != tags.end(); ++iter) + { + taglist.push_back(separator); + separator = ';'; + taglist.append(iter->first); + if (!iter->second.value.empty()) + { + taglist.push_back('='); + taglist.append(iter->second.value); + } + } + taglist.push_back(' '); + content.insert(0, taglist); + } + content.replace(0, tagsize, taglist); + tagsize = content.length(); +} + CmdResult CommandSNONotice::Handle(User* user, Params& params) { ServerInstance->SNO->WriteToSnoMask(params[0][0], "From " + user->nick + ": " + params[1]); diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index ca4d1a472..f3f2ea7ac 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -27,7 +27,6 @@ #include "treeserver.h" #include "main.h" #include "commands.h" -#include "modules/server.h" /** * Creates FMODE messages, used only when syncing channels diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index ec1fb079d..952899962 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -23,7 +23,6 @@ #include "inspircd.h" #include "xline.h" #include "main.h" -#include "modules/server.h" #include "utils.h" #include "treeserver.h" diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index 190c5dc15..2e08dea63 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -24,7 +24,6 @@ #include "iohook.h" #include "main.h" -#include "modules/server.h" #include "utils.h" #include "treeserver.h" #include "link.h" diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 2957b8c14..41cce0541 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -28,7 +28,6 @@ #include "treesocket.h" #include "resolvers.h" #include "commandbuilder.h" -#include "modules/server.h" SpanningTreeUtilities* Utils = NULL; |