]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commandbuilder.h
m_modenotice Use WriteNotice()
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / commandbuilder.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 #include "utils.h"
23
24 class TreeServer;
25
26 class CmdBuilder
27 {
28         std::string content;
29
30  public:
31         CmdBuilder(const char* cmd)
32                 : content(1, ':')
33         {
34                 content.append(ServerInstance->Config->GetSID());
35                 push(cmd);
36         }
37
38         CmdBuilder(const std::string& src, const char* cmd)
39                 : content(1, ':')
40         {
41                 content.append(src);
42                 push(cmd);
43         }
44
45         CmdBuilder(User* src, const char* cmd)
46                 : content(1, ':')
47         {
48                 content.append(src->uuid);
49                 push(cmd);
50         }
51
52         CmdBuilder& push_raw(const std::string& s)
53         {
54                 content.append(s);
55                 return *this;
56         }
57
58         CmdBuilder& push_raw(const char* s)
59         {
60                 content.append(s);
61                 return *this;
62         }
63
64         CmdBuilder& push_raw(char c)
65         {
66                 content.push_back(c);
67                 return *this;
68         }
69
70         CmdBuilder& push(const std::string& s)
71         {
72                 content.push_back(' ');
73                 content.append(s);
74                 return *this;
75         }
76
77         CmdBuilder& push(const char* s)
78         {
79                 content.push_back(' ');
80                 content.append(s);
81                 return *this;
82         }
83
84         CmdBuilder& push(char c)
85         {
86                 content.push_back(' ');
87                 content.push_back(c);
88                 return *this;
89         }
90
91         template <typename T>
92         CmdBuilder& push_int(T i)
93         {
94                 content.push_back(' ');
95                 content.append(ConvToStr(i));
96                 return *this;
97         }
98
99         CmdBuilder& push_last(const std::string& s)
100         {
101                 content.push_back(' ');
102                 content.push_back(':');
103                 content.append(s);
104                 return *this;
105         }
106
107         template<typename T>
108         CmdBuilder& insert(const T& cont)
109         {
110                 for (typename T::const_iterator i = cont.begin(); i != cont.end(); ++i)
111                         push(*i);
112                 return *this;
113         }
114
115         void push_back(const std::string& s) { push(s); }
116
117         const std::string& str() const { return content; }
118         operator const std::string&() const { return str(); }
119
120         void Broadcast() const
121         {
122                 Utils->DoOneToMany(*this);
123         }
124
125         void Forward(TreeServer* omit) const
126         {
127                 Utils->DoOneToAllButSender(*this, omit);
128         }
129
130         bool Unicast(const std::string& target) const
131         {
132                 return Utils->DoOneToOne(*this, target);
133         }
134
135         bool Unicast(User* target) const
136         {
137                 return Unicast(target->server);
138         }
139 };