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
|
/* ChanServ core functions
*
* (C) 2003-2009 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.
*
* $Id$
*
*/
/*************************************************************************/
#include "module.h"
class CommandCSClear : public Command
{
public:
CommandCSClear() : Command("CLEAR", 2, 2)
{
}
CommandReturn Execute(User *u, std::vector<ci::string> ¶ms)
{
const char *chan = params[0].c_str();
ci::string what = params[1];
Channel *c = findchan(chan);
ChannelInfo *ci;
if (c)
ci = c->ci;
if (!c) {
notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
} else if (!u || !check_access(u, ci, CA_CLEAR)) {
notice_lang(s_ChanServ, u, ACCESS_DENIED);
} else if (what == "bans") {
const char *av[2];
Entry *ban, *bnext;
if (c->bans && c->bans->count) {
for (ban = c->bans->entries; ban; ban = bnext) {
bnext = ban->next;
av[0] = "-b";
av[1] = ban->mask;
ircdproto->SendMode(whosends(ci), chan, "-b %s", ban->mask);
chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
}
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_BANS, chan);
} else if (ircd->except && what == "excepts") {
const char *av[2];
Entry *except, *bnext;
if (c->excepts && c->excepts->count) {
for (except = c->excepts->entries; except; except = bnext) {
bnext = except->next;
av[0] = "-e";
av[1] = except->mask;
ircdproto->SendMode(whosends(ci), chan, "-e %s", except->mask);
chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
}
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan);
} else if (ircd->invitemode && what == "invites") {
const char *av[2];
Entry *invite, *bnext;
if (c->invites && c->invites->count) {
for (invite = c->invites->entries; invite; invite = bnext) {
bnext = invite->next;
av[0] = "-I";
av[1] = invite->mask;
ircdproto->SendMode(whosends(ci), chan, "-I %s", invite->mask);
chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
}
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_INVITES, chan);
} else if (what == "modes") {
const char *argv[2];
if (c->mode) {
/* Clear modes the bulk of the modes */
ircdproto->SendMode(whosends(ci), c->name, "%s",
ircd->modestoremove);
argv[0] = ircd->modestoremove;
chan_set_modes(whosends(ci)->nick, c, 1, argv, 0);
/* to prevent the internals from complaining send -k, -L, -f by themselves if we need
to send them - TSL */
if (c->key) {
ircdproto->SendMode(whosends(ci), c->name, "-k %s", c->key);
argv[0] = "-k";
argv[1] = c->key;
chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
}
if (ircd->Lmode && c->redirect) {
ircdproto->SendMode(whosends(ci), c->name, "-L %s",
c->redirect);
argv[0] = "-L";
argv[1] = c->redirect;
chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
}
if (ircd->fmode && c->flood) {
if (flood_mode_char_remove) {
ircdproto->SendMode(whosends(ci), c->name, "%s %s",
flood_mode_char_remove, c->flood);
argv[0] = flood_mode_char_remove;
argv[1] = c->flood;
chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
} else {
if (debug) {
alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
}
}
}
check_modes(c);
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_MODES, chan);
} else if (what == "ops") {
const char *av[6]; /* The max we have to hold: chan, ts, modes(max3), nick, nick, nick */
int ac, isop, isadmin, isown, count, i;
char buf[BUFSIZE], tmp[BUFSIZE], tmp2[BUFSIZE];
struct c_userlist *cu, *bnext;
if (ircd->svsmode_ucmode) {
av[0] = chan;
ircdproto->SendSVSModeChan(av[0], "-o", NULL);
if (ircd->owner) {
ircdproto->SendSVSModeChan(av[0], ircd->ownerunset, NULL);
}
if (ircd->protect || ircd->admin) {
ircdproto->SendSVSModeChan(av[0], ircd->adminunset, NULL);
}
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
isop = chan_has_user_status(c, cu->user, CUS_OP);
isadmin = chan_has_user_status(c, cu->user, CUS_PROTECT);
isown = chan_has_user_status(c, cu->user, CUS_OWNER);
count = (isop ? 1 : 0) + (isadmin ? 1 : 0) + (isown ? 1 : 0);
if (!isop && !isadmin && !isown)
continue;
snprintf(tmp, BUFSIZE, "-%s%s%s", (isop ? "o" : ""), (isadmin ?
ircd->adminunset+1 : ""), (isown ? ircd->ownerunset+1 : ""));
if (ircdcap->tsmode) {
snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL)));
av[1] = buf;
av[2] = tmp;
/* We have to give as much nicks as modes.. - Viper */
for (i = 0; i < count; i++)
av[i+3] = cu->user->nick;
ac = 3 + i;
} else {
av[1] = tmp;
/* We have to give as much nicks as modes.. - Viper */
for (i = 0; i < count; i++)
av[i+2] = cu->user->nick;
ac = 2 + i;
}
do_cmode(s_ChanServ, ac, av);
}
} else {
av[0] = chan;
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
isop = chan_has_user_status(c, cu->user, CUS_OP);
isadmin = chan_has_user_status(c, cu->user, CUS_PROTECT);
isown = chan_has_user_status(c, cu->user, CUS_OWNER);
count = (isop ? 1 : 0) + (isadmin ? 1 : 0) + (isown ? 1 : 0);
if (!isop && !isadmin && !isown)
continue;
snprintf(tmp, BUFSIZE, "-%s%s%s", (isop ? "o" : ""), (isadmin ?
ircd->adminunset+1 : ""), (isown ? ircd->ownerunset+1 : ""));
/* We need to send the IRCd a nick for every mode.. - Viper */
snprintf(tmp2, BUFSIZE, "%s %s %s", (isop ? cu->user->nick : ""),
(isadmin ? cu->user->nick : ""), (isown ? cu->user->nick : ""));
if (ircdcap->tsmode) {
snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL)));
av[1] = buf;
av[2] = tmp;
/* We have to give as much nicks as modes.. - Viper */
for (i = 0; i < count; i++)
av[i+3] = cu->user->nick;
ac = 3 + i;
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[2], tmp2);
} else {
av[1] = tmp;
/* We have to give as much nicks as modes.. - Viper */
for (i = 0; i < count; i++)
av[i+2] = cu->user->nick;
ac = 2 + i;
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[1], tmp2);
}
do_cmode(s_ChanServ, ac, av);
}
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_OPS, chan);
} else if (ircd->halfop && what == "hops") {
const char *av[4];
int ac;
char buf[BUFSIZE];
struct c_userlist *cu, *bnext;
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
continue;
if (ircdcap->tsmode) {
snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL)));
av[0] = chan;
av[1] = buf;
av[2] = "-h";
av[3] = cu->user->nick;
ac = 4;
} else {
av[0] = chan;
av[1] = "-h";
av[2] = cu->user->nick;
ac = 3;
}
if (ircd->svsmode_ucmode) {
if (ircdcap->tsmode)
ircdproto->SendSVSModeChan(av[0], av[2], NULL);
else
ircdproto->SendSVSModeChan(av[0], av[1], NULL);
do_cmode(s_ChanServ, ac, av);
break;
} else {
if (ircdcap->tsmode)
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[2],
av[3]);
else
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[1],
av[2]);
}
do_cmode(s_ChanServ, ac, av);
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_HOPS, chan);
} else if (what == "voices") {
const char *av[4];
int ac;
char buf[BUFSIZE];
struct c_userlist *cu, *bnext;
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
if (!chan_has_user_status(c, cu->user, CUS_VOICE))
continue;
if (ircdcap->tsmode) {
snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long int>(time(NULL)));
av[0] = chan;
av[1] = buf;
av[2] = "-v";
av[3] = cu->user->nick;
ac = 4;
} else {
av[0] = chan;
av[1] = "-v";
av[2] = cu->user->nick;
ac = 3;
}
if (ircd->svsmode_ucmode) {
if (ircdcap->tsmode)
ircdproto->SendSVSModeChan(av[0], av[2], NULL);
else
ircdproto->SendSVSModeChan(av[0], av[1], NULL);
do_cmode(s_ChanServ, ac, av);
break;
} else {
if (ircdcap->tsmode) {
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[2],
av[3]);
} else {
ircdproto->SendMode(whosends(ci), av[0], "%s %s", av[1],
av[2]);
}
}
do_cmode(s_ChanServ, ac, av);
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_VOICES, chan);
} else if (what == "users") {
const char *av[3];
struct c_userlist *cu, *bnext;
char buf[256];
snprintf(buf, sizeof(buf), "CLEAR USERS command from %s", u->nick);
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
av[0] = sstrdup(chan);
av[1] = sstrdup(cu->user->nick);
av[2] = sstrdup(buf);
ircdproto->SendKick(whosends(ci), av[0], av[1], av[2]);
do_kick(s_ChanServ, 3, av);
delete [] av[2];
delete [] av[1];
delete [] av[0];
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_USERS, chan);
} else {
syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
}
return MOD_CONT;
}
bool OnHelp(User *u, const ci::string &subcommand)
{
notice_help(s_ChanServ, u, CHAN_HELP_CLEAR);
return true;
}
void OnSyntaxError(User *u)
{
syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
}
};
class CSClear : public Module
{
public:
CSClear(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetVersion("$Id$");
this->SetType(CORE);
this->AddCommand(CHANSERV, new CommandCSClear());
}
void ChanServHelp(User *u)
{
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_CLEAR);
}
};
MODULE_INIT(CSClear)
|