2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /** The raw message contents. */
32 /** Tags which have been added to this message. */
33 ClientProtocol::TagMap tags;
35 /** The size of tags within the contents. */
38 /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a server target. */
39 void FireEvent(Server* target, const char* cmd, ClientProtocol::TagMap& taglist);
41 /** Fires the ServerProtocol::MessageEventListener::OnBuildMessage event for a user target. */
42 void FireEvent(User* target, const char* cmd, ClientProtocol::TagMap& taglist);
44 /** Updates the tag string within the buffer. */
48 CmdBuilder(const char* cmd)
52 content.append(ServerInstance->Config->GetSID());
54 FireEvent(ServerInstance->FakeClient->server, cmd, tags);
57 CmdBuilder(TreeServer* src, const char* cmd)
61 content.append(src->GetId());
63 FireEvent(src, cmd, tags);
66 CmdBuilder(User* src, const char* cmd)
70 content.append(src->uuid);
72 if (InspIRCd::IsSID(src->uuid))
73 FireEvent(src->server, cmd, tags);
75 FireEvent(src, cmd, tags);
78 CmdBuilder& push_raw(const std::string& s)
84 CmdBuilder& push_raw(const char* s)
90 CmdBuilder& push_raw(char c)
97 CmdBuilder& push_raw_int(T i)
99 content.append(ConvToStr(i));
103 template <typename InputIterator>
104 CmdBuilder& push_raw(InputIterator first, InputIterator last)
106 content.append(first, last);
110 CmdBuilder& push(const std::string& s)
112 content.push_back(' ');
117 CmdBuilder& push(const char* s)
119 content.push_back(' ');
124 CmdBuilder& push(char c)
126 content.push_back(' ');
127 content.push_back(c);
131 template <typename T>
132 CmdBuilder& push_int(T i)
134 content.push_back(' ');
135 content.append(ConvToStr(i));
139 CmdBuilder& push_last(const std::string& s)
141 content.push_back(' ');
142 content.push_back(':');
147 CmdBuilder& push_tags(ClientProtocol::TagMap newtags)
149 // It has to be this way around so new tags get priority.
150 newtags.insert(tags.begin(), tags.end());
151 std::swap(tags, newtags);
157 CmdBuilder& insert(const T& cont)
159 for (typename T::const_iterator i = cont.begin(); i != cont.end(); ++i)
164 const std::string& str() const { return content; }
165 operator const std::string&() const { return str(); }
167 void Broadcast() const
169 Utils->DoOneToMany(*this);
172 void Forward(TreeServer* omit) const
174 Utils->DoOneToAllButSender(*this, omit);
177 void Unicast(User* target) const
179 Utils->DoOneToOne(*this, target->server);