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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* OperServ core functions
*
* (C) 2003-2012 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
/*************************************************************************/
#include "module.h"
struct MyOper : Oper, Serializable
{
MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
Serialize::Data serialize() const anope_override
{
Serialize::Data data;
data["name"] << this->name;
data["type"] << this->ot->GetName();
return data;
}
static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
OperType *ot = OperType::Find(data["type"].astr());
if (ot == NULL)
return NULL;
NickCore *nc = findcore(data["name"].astr());
if (nc == NULL)
return NULL;
MyOper *myo;
if (obj)
myo = anope_dynamic_static_cast<MyOper *>(obj);
else
myo = new MyOper(nc->display, ot);
nc->o = myo;
Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
return myo;
}
};
class CommandOSOper : public Command
{
public:
CommandOSOper(Module *creator) : Command(creator, "operserv/oper", 1, 3)
{
this->SetDesc(_("View and change services operators"));
this->SetSyntax(_("ADD \037oper\037 \037type\037"));
this->SetSyntax(_("DEL [\037oper\037]"));
this->SetSyntax(_("INFO [\037type\037]"));
this->SetSyntax(_("LIST"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
const Anope::string &subcommand = params[0];
if (subcommand.equals_ci("ADD") && params.size() > 2)
{
const Anope::string &oper = params[1];
const Anope::string &otype = params[2];
const NickAlias *na = findnick(oper);
if (na == NULL)
source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
else if (na->nc->o)
source.Reply(_("Nick \2%s\2 is already an operator."), na->nick.c_str());
else
{
OperType *ot = OperType::Find(otype);
if (ot == NULL)
source.Reply(_("Oper type \2%s\2 has not been configured."), otype.c_str());
else
{
na->nc->o = new MyOper(na->nc->display, ot);
Log(LOG_ADMIN, source, this) << "ADD " << na->nick << " as type " << ot->GetName();
source.Reply("%s (%s) added to the \2%s\2 list.", na->nick.c_str(), na->nc->display.c_str(), ot->GetName().c_str());
}
}
}
else if (subcommand.equals_ci("DEL") && params.size() > 1)
{
const Anope::string &oper = params[1];
const NickAlias *na = findnick(oper);
if (na == NULL)
source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
else if (!na->nc || !na->nc->o)
source.Reply(_("Nick \2%s\2 is not a services operator."), oper.c_str());
else
{
delete na->nc->o;
na->nc->o = NULL;
Log(LOG_ADMIN, source, this) << "DEL " << na->nick;
source.Reply(_("Oper privileges removed from %s (%s)."), na->nick.c_str(), na->nc->display.c_str());
}
}
else if (subcommand.equals_ci("LIST"))
{
source.Reply(_("Name Type"));
for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
const NickCore *nc = it->second;
if (!nc->o)
continue;
source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str());
if (nc->o->config)
source.Reply(_(" This oper is configured in the configuration file."));
for (std::list<User *>::const_iterator uit = nc->Users.begin(); uit != nc->Users.end(); ++uit)
{
User *u = *uit;
source.Reply(_(" %s is online using this oper block."), u->nick.c_str());
}
}
}
else if (subcommand.equals_ci("INFO") && params.size() > 1)
{
Anope::string fulltype = params[1];
if (params.size() > 2)
fulltype += " " + params[2];
OperType *ot = OperType::Find(fulltype);
if (ot == NULL)
source.Reply(_("Oper type \2%s\2 has not been configured."), fulltype.c_str());
else
{
if (ot->GetCommands().empty())
source.Reply(_("Opertype \2%s\2 has no allowed commands."), ot->GetName().c_str());
else
{
source.Reply(_("Available commands for \2%s\2:"), ot->GetName().c_str());
Anope::string buf;
std::list<Anope::string> cmds = ot->GetCommands();
for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it)
{
buf += *it + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!buf.empty())
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (ot->GetPrivs().empty())
source.Reply(_("Opertype \2%s\2 has no allowed privileges."), ot->GetName().c_str());
else
{
source.Reply(_("Available privileges for \2%s\2:"), ot->GetName().c_str());
Anope::string buf;
std::list<Anope::string> privs = ot->GetPrivs();
for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it)
{
buf += *it + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!buf.empty())
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!ot->modes.empty())
source.Reply(_("Opertype \2%s\2 receives modes \2%s\2 once identifying."), ot->GetName().c_str(), ot->modes.c_str());
}
}
else
this->OnSyntaxError(source, subcommand);
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows you to change and view services operators.\n"
"Note that operators removed by this command but are still set in\n"
"the configuration file are not permanently affected by this."));
return true;
}
};
class OSOper : public Module
{
SerializeType myoper_type;
CommandOSOper commandosoper;
public:
OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
myoper_type("Oper", MyOper::unserialize), commandosoper(this)
{
this->SetAuthor("Anope");
}
~OSOper()
{
for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
const NickCore *nc = it->second;
if (nc->o && !nc->o->config)
delete nc->o;
}
}
};
MODULE_INIT(OSOper)
|