blob: 07f7c94d0c0d616d622bbf045290706b8a669231 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
*
* 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
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "utils.h"
class TreeServer;
class CmdBuilder
{
std::string content;
public:
CmdBuilder(const char* cmd)
: content(1, ':')
{
content.append(ServerInstance->Config->GetSID());
push(cmd);
}
CmdBuilder(const std::string& src, const char* cmd)
: content(1, ':')
{
content.append(src);
push(cmd);
}
CmdBuilder(User* src, const char* cmd)
: content(1, ':')
{
content.append(src->uuid);
push(cmd);
}
CmdBuilder& push_raw(const std::string& str)
{
content.append(str);
return *this;
}
CmdBuilder& push_raw(const char* str)
{
content.append(str);
return *this;
}
CmdBuilder& push_raw(char c)
{
content.push_back(c);
return *this;
}
CmdBuilder& push(const std::string& str)
{
content.push_back(' ');
content.append(str);
return *this;
}
CmdBuilder& push(const char* str)
{
content.push_back(' ');
content.append(str);
return *this;
}
CmdBuilder& push(char c)
{
content.push_back(' ');
content.push_back(c);
return *this;
}
template <typename T>
CmdBuilder& push_int(T i)
{
content.push_back(' ');
content.append(ConvToStr(i));
return *this;
}
CmdBuilder& push_last(const std::string& str)
{
content.push_back(' ');
content.push_back(':');
content.append(str);
return *this;
}
template<typename T>
CmdBuilder& insert(const T& cont)
{
for (typename T::const_iterator i = cont.begin(); i != cont.end(); ++i)
push(*i);
return *this;
}
void push_back(const std::string& str) { push(str); }
const std::string& str() const { return content; }
operator const std::string&() const { return str(); }
void Broadcast() const
{
Utils->DoOneToMany(*this);
}
void Forward(TreeServer* omit) const
{
Utils->DoOneToAllButSender(*this, omit);
}
bool Unicast(const std::string& target) const
{
return Utils->DoOneToOne(*this, target);
}
bool Unicast(User* target) const
{
return Unicast(target->server);
}
};
|