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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
/* BotServ core functions
*
* (C) 2003-2022 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"
class CommandBSBot : public Command
{
private:
void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms)
{
const Anope::string &nick = params[1];
const Anope::string &user = params[2];
const Anope::string &host = params[3];
const Anope::string &real = params[4];
if (BotInfo::Find(nick, true))
{
source.Reply(_("Bot \002%s\002 already exists."), nick.c_str());
return;
}
Configuration::Block *networkinfo = Config->GetBlock("networkinfo");
if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
{
source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
return;
}
if (user.length() > networkinfo->Get<unsigned>("userlen"))
{
source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
return;
}
if (host.length() > networkinfo->Get<unsigned>("hostlen"))
{
source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
return;
}
if (!IRCD->IsNickValid(nick))
{
source.Reply(_("Bot nicks may only contain valid nick characters."));
return;
}
if (!IRCD->IsIdentValid(user))
{
source.Reply(_("Bot idents may only contain valid ident characters."));
return;
}
if (!IRCD->IsHostValid(host))
{
source.Reply(_("Bot hosts may only contain valid host characters."));
return;
}
/* We check whether the nick is registered, and inform the user
* if so. You need to drop the nick manually before you can use
* it as a bot nick from now on -GD
*/
if (NickAlias::Find(nick))
{
source.Reply(NICK_ALREADY_REGISTERED, nick.c_str());
return;
}
User *u = User::Find(nick, true);
if (u)
{
source.Reply(_("Nick \002%s\002 is currently in use."), u->nick.c_str());
return;
}
BotInfo *bi = new BotInfo(nick, user, host, real);
Log(LOG_ADMIN, source, this) << "ADD " << bi->GetMask() << " " << bi->realname;
source.Reply(_("%s!%s@%s (%s) added to the bot list."), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str());
FOREACH_MOD(OnBotCreate, (bi));
return;
}
void DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms)
{
const Anope::string &oldnick = params[1];
const Anope::string &nick = params.size() > 2 ? params[2] : "";
const Anope::string &user = params.size() > 3 ? params[3] : "";
const Anope::string &host = params.size() > 4 ? params[4] : "";
const Anope::string &real = params.size() > 5 ? params[5] : "";
if (oldnick.empty() || nick.empty())
{
this->OnSyntaxError(source, "CHANGE");
return;
}
BotInfo *bi = BotInfo::Find(oldnick, true);
if (!bi)
{
source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str());
return;
}
if (bi->conf)
{
source.Reply(_("Bot %s is not changeable."), bi->nick.c_str());
return;
}
Configuration::Block *networkinfo = Config->GetBlock("networkinfo");
if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
{
source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
return;
}
if (user.length() > networkinfo->Get<unsigned>("userlen"))
{
source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
return;
}
if (host.length() > networkinfo->Get<unsigned>("hostlen"))
{
source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
return;
}
/* Checks whether there *are* changes.
* Case sensitive because we may want to change just the case.
* And we must finally check that the nick is not already
* taken by another bot.
*/
if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1))
{
source.Reply(_("The old information is the same as the new information specified."));
return;
}
if (!IRCD->IsNickValid(nick))
{
source.Reply(_("Bot nicks may only contain valid nick characters."));
return;
}
if (!user.empty() && !IRCD->IsIdentValid(user))
{
source.Reply(_("Bot idents may only contain valid ident characters."));
return;
}
if (!host.empty() && !IRCD->IsHostValid(host))
{
source.Reply(_("Bot hosts may only contain valid host characters."));
return;
}
if (!nick.equals_ci(bi->nick))
{
if (BotInfo::Find(nick, true))
{
source.Reply(_("Bot \002%s\002 already exists."), nick.c_str());
return;
}
if (User::Find(nick, true))
{
source.Reply(_("Nick \002%s\002 is currently in use."), nick.c_str());
return;
}
}
if (!nick.equals_ci(bi->nick))
{
/* We check whether the nick is registered, and inform the user
* if so. You need to drop the nick manually before you can use
* it as a bot nick from now on -GD
*/
if (NickAlias::Find(nick))
{
source.Reply(NICK_ALREADY_REGISTERED, nick.c_str());
return;
}
/* The new nick is really different, so we remove the Q line for the old nick. */
XLine x_del(bi->nick);
IRCD->SendSQLineDel(&x_del);
/* Add a Q line for the new nick */
XLine x(nick, "Reserved for services");
IRCD->SendSQLine(NULL, &x);
}
if (!user.empty())
{
IRCD->SendQuit(bi, "Quit: Be right back");
bi->introduced = false;
}
else
IRCD->SendNickChange(bi, nick);
if (!nick.equals_cs(bi->nick))
bi->SetNewNick(nick);
if (!user.empty() && !user.equals_cs(bi->GetIdent()))
bi->SetIdent(user);
if (!host.empty() && !host.equals_cs(bi->host))
bi->host = host;
if (!real.empty() && !real.equals_cs(bi->realname))
bi->realname = real;
if (!user.empty())
bi->OnKill();
source.Reply(_("Bot \002%s\002 has been changed to %s!%s@%s (%s)."), oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str());
Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname;
FOREACH_MOD(OnBotChange, (bi));
return;
}
void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms)
{
const Anope::string &nick = params[1];
if (nick.empty())
{
this->OnSyntaxError(source, "DEL");
return;
}
BotInfo *bi = BotInfo::Find(nick, true);
if (!bi)
{
source.Reply(BOT_DOES_NOT_EXIST, nick.c_str());
return;
}
if (bi->conf)
{
source.Reply(_("Bot %s is not deletable."), bi->nick.c_str());
return;
}
FOREACH_MOD(OnBotDelete, (bi));
Log(LOG_ADMIN, source, this) << "DEL " << bi->nick;
source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str());
delete bi;
return;
}
public:
CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6)
{
this->SetDesc(_("Maintains network bot list"));
this->SetSyntax(_("\002ADD \037nick\037 \037user\037 \037host\037 \037real\037\002"));
this->SetSyntax(_("\002CHANGE \037oldnick\037 \037newnick\037 [\037user\037 [\037host\037 [\037real\037]]]\002"));
this->SetSyntax(_("\002DEL \037nick\037\002"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
const Anope::string &cmd = params[0];
if (Anope::ReadOnly)
{
source.Reply(_("Sorry, bot modification is temporarily disabled."));
return;
}
if (cmd.equals_ci("ADD"))
{
// ADD nick user host real - 5
if (!source.HasCommand("botserv/bot/add"))
{
source.Reply(ACCESS_DENIED);
return;
}
if (params.size() < 5)
{
this->OnSyntaxError(source, "ADD");
return;
}
std::vector<Anope::string> tempparams = params;
// ADD takes less params than CHANGE, so we need to take 6 if given and append it with a space to 5.
if (tempparams.size() >= 6)
tempparams[4] = tempparams[4] + " " + tempparams[5];
return this->DoAdd(source, tempparams);
}
else if (cmd.equals_ci("CHANGE"))
{
// CHANGE oldn newn user host real - 6
// but only oldn and newn are required
if (!source.HasCommand("botserv/bot/change"))
{
source.Reply(ACCESS_DENIED);
return;
}
if (params.size() < 3)
{
this->OnSyntaxError(source, "CHANGE");
return;
}
return this->DoChange(source, params);
}
else if (cmd.equals_ci("DEL"))
{
// DEL nick
if (!source.HasCommand("botserv/bot/del"))
{
source.Reply(ACCESS_DENIED);
return;
}
if (params.size() < 1)
{
this->OnSyntaxError(source, "DEL");
return;
}
return this->DoDel(source, params);
}
else
this->OnSyntaxError(source, "");
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows Services Operators to create, modify, and delete\n"
"bots that users will be able to use on their own\n"
"channels.\n"
" \n"
"\002BOT ADD\002 adds a bot with the given nickname, username,\n"
"hostname and realname. Since no integrity checks are done\n"
"for these settings, be really careful.\n"
" \n"
"\002BOT CHANGE\002 allows you to change the nickname, username, hostname\n"
"or realname of a bot without deleting it (and\n"
"all the data associated with it).\n"
" \n"
"\002BOT DEL\002 removes the given bot from the bot list.\n"
" \n"
"\002Note\002: You cannot create a bot with a nick that is\n"
"currently registered. If an unregistered user is currently\n"
"using the nick, they will be killed."));
return true;
}
};
class BSBot : public Module
{
CommandBSBot commandbsbot;
public:
BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsbot(this)
{
}
};
MODULE_INIT(BSBot)
|