X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Fcommandbuilder.h;h=527b535847109d9267799128f3fc592e638f903f;hb=3151d60c1ecc9462e4c335282ee6c31672f45111;hp=597b22751509caaca4a78a957cb6cfd88aa60b56;hpb=29694ce3d2c57ebefa9b14b6816679bf44799921;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/commandbuilder.h b/src/modules/m_spanningtree/commandbuilder.h index 597b22751..527b53584 100644 --- a/src/modules/m_spanningtree/commandbuilder.h +++ b/src/modules/m_spanningtree/commandbuilder.h @@ -1,7 +1,9 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013 Attila Molnar + * Copyright (C) 2019 Sadie Powell + * Copyright (C) 2013-2015 Attila Molnar + * Copyright (C) 2013 Adam * * 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 @@ -25,28 +27,54 @@ 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(const std::string& src, const char* cmd) + CmdBuilder(TreeServer* src, const char* cmd) : content(1, ':') + , tagsize(0) { - content.append(src); + 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 (InspIRCd::IsSID(src->uuid)) + FireEvent(src->server, cmd, tags); + else + FireEvent(src, cmd, tags); } CmdBuilder& push_raw(const std::string& s) @@ -67,6 +95,20 @@ class CmdBuilder return *this; } + template + CmdBuilder& push_raw_int(T i) + { + content.append(ConvToStr(i)); + return *this; + } + + template + CmdBuilder& push_raw(InputIterator first, InputIterator last) + { + content.append(first, last); + return *this; + } + CmdBuilder& push(const std::string& s) { content.push_back(' '); @@ -104,6 +146,15 @@ class CmdBuilder return *this; } + 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; + } + template CmdBuilder& insert(const T& cont) { @@ -112,8 +163,6 @@ class CmdBuilder return *this; } - void push_back(const std::string& s) { push(s); } - const std::string& str() const { return content; } operator const std::string&() const { return str(); } @@ -127,13 +176,8 @@ class CmdBuilder Utils->DoOneToAllButSender(*this, omit); } - bool Unicast(const std::string& target) const - { - return Utils->DoOneToOne(*this, target); - } - - bool Unicast(User* target) const + void Unicast(User* target) const { - return Unicast(target->server); + Utils->DoOneToOne(*this, target->server); } };