2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013 Adam <Adam@anope.org>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** The raw message contents. */
34 /** Tags which have been added to this message. */
35 ClientProtocol::TagMap tags;
37 /** The size of tags within the contents. */
40 /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a server target. */
41 void FireEvent(Server* target, const char* cmd, ClientProtocol::TagMap& taglist);
43 /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a user target. */
44 void FireEvent(User* target, const char* cmd, ClientProtocol::TagMap& taglist);
46 /** Updates the tag string within the buffer. */
50 CmdBuilder(const char* cmd)
54 content.append(ServerInstance->Config->GetSID());
56 FireEvent(ServerInstance->FakeClient->server, cmd, tags);
59 CmdBuilder(TreeServer* src, const char* cmd)
63 content.append(src->GetId());
65 FireEvent(src, cmd, tags);
68 CmdBuilder(User* src, const char* cmd)
72 content.append(src->uuid);
74 if (InspIRCd::IsSID(src->uuid))
75 FireEvent(src->server, cmd, tags);
77 FireEvent(src, cmd, tags);
80 CmdBuilder& push_raw(const std::string& s)
86 CmdBuilder& push_raw(const char* s)
92 CmdBuilder& push_raw(char c)
99 CmdBuilder& push_raw_int(T i)
101 content.append(ConvToStr(i));
105 template <typename InputIterator>
106 CmdBuilder& push_raw(InputIterator first, InputIterator last)
108 content.append(first, last);
112 CmdBuilder& push(const std::string& s)
114 content.push_back(' ');
119 CmdBuilder& push(const char* s)
121 content.push_back(' ');
126 CmdBuilder& push(char c)
128 content.push_back(' ');
129 content.push_back(c);
133 template <typename T>
134 CmdBuilder& push_int(T i)
136 content.push_back(' ');
137 content.append(ConvToStr(i));
141 CmdBuilder& push_last(const std::string& s)
143 content.push_back(' ');
144 content.push_back(':');
149 CmdBuilder& push_tags(ClientProtocol::TagMap newtags)
151 // It has to be this way around so new tags get priority.
152 newtags.insert(tags.begin(), tags.end());
153 std::swap(tags, newtags);
159 CmdBuilder& insert(const T& cont)
161 for (typename T::const_iterator i = cont.begin(); i != cont.end(); ++i)
166 const std::string& str() const { return content; }
167 operator const std::string&() const { return str(); }
169 void Broadcast() const
171 Utils->DoOneToMany(*this);
174 void Forward(TreeServer* omit) const
176 Utils->DoOneToAllButSender(*this, omit);
179 void Unicast(User* target) const
181 Utils->DoOneToOne(*this, target->server);