diff options
| author | 2019-07-19 14:12:13 +0100 | |
|---|---|---|
| committer | 2019-07-19 14:17:10 +0100 | |
| commit | e2fcf7b3b15f86fec250b7b784bdf3d0631048c6 (patch) | |
| tree | c0fea58c832b87abd3f5be1f920aaa5bfff475aa /src/modules/m_spanningtree/commandbuilder.h | |
| parent | Get rid of CommandBuilder::push_back. (diff) | |
Add an event for adding tags to S2S messages.
Diffstat (limited to 'src/modules/m_spanningtree/commandbuilder.h')
| -rw-r--r-- | src/modules/m_spanningtree/commandbuilder.h | 50 |
1 files changed, 30 insertions, 20 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) + CmdBuilder& push_tags(ClientProtocol::TagMap newtags) { - 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); - } + // 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; } |
