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
|
/* 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"
void myChanServHelp(User *u);
class CommandCSSuspend : public Command
{
public:
CommandCSSuspend() : Command("SUSPEND", 1, 2)
{
}
CommandReturn Execute(User *u, std::vector<std::string> ¶ms)
{
ChannelInfo *ci;
const char *chan = params[0].c_str();
const char *reason = params.size() > 1 ? params[1].c_str() : NULL;
Channel *c;
if (!u->nc->HasCommand("chanserv/suspend"))
{
notice_lang(s_ChanServ, u, ACCESS_DENIED);
return MOD_CONT; // XXX: error?
}
/* Assumes that permission checking has already been done. */
if (ForceForbidReason && !reason)
{
this->OnSyntaxError(u);
return MOD_CONT;
}
if (chan[0] != '#')
{
notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR);
return MOD_CONT;
}
/* Only SUSPEND existing channels, otherwise use FORBID (bug #54) */
if (!(ci = cs_findchan(chan)))
{
notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
return MOD_CONT;
}
/* You should not SUSPEND a FORBIDEN channel */
if (ci->flags & CI_FORBIDDEN)
{
notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
return MOD_CONT;
}
if (readonly)
notice_lang(s_ChanServ, u, READ_ONLY_MODE);
if (ci)
{
ci->flags |= CI_SUSPENDED;
ci->forbidby = sstrdup(u->nick);
if (reason)
ci->forbidreason = sstrdup(reason);
if ((c = findchan(ci->name)))
{
struct c_userlist *cu, *nextu;
const char *av[3];
for (cu = c->users; cu; cu = nextu)
{
nextu = cu->next;
if (is_oper(cu->user))
continue;
av[0] = c->name;
av[1] = cu->user->nick;
av[2] = reason ? reason : getstring(cu->user->nc, CHAN_SUSPEND_REASON);
ircdproto->SendKick(findbot(s_ChanServ), av[0], av[1], av[2]);
do_kick(s_ChanServ, 3, av);
}
}
if (WallForbid)
ircdproto->SendGlobops(s_ChanServ, "\2%s\2 used SUSPEND on channel \2%s\2", u->nick, ci->name);
alog("%s: %s set SUSPEND for channel %s", s_ChanServ, u->nick, ci->name);
notice_lang(s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan);
send_event(EVENT_CHAN_SUSPENDED, 1, chan);
}
else
{
alog("%s: Valid SUSPEND for %s by %s failed", s_ChanServ, ci->name, u->nick);
notice_lang(s_ChanServ, u, CHAN_SUSPEND_FAILED, chan);
}
return MOD_CONT;
}
bool OnHelp(User *u, const std::string &subcommand)
{
if (!is_services_oper(u))
return false;
notice_help(s_ChanServ, u, CHAN_SERVADMIN_HELP_SUSPEND);
return true;
}
void OnSyntaxError(User *u)
{
syntax_error(s_ChanServ, u, "SUSPEND", ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON : CHAN_SUSPEND_SYNTAX);
}
};
class CommandCSUnSuspend : public Command
{
public:
CommandCSUnSuspend() : Command("UNSUSPEND", 1, 1)
{
}
CommandReturn Execute(User *u, std::vector<std::string> ¶ms)
{
ChannelInfo *ci;
const char *chan = params[0].c_str();
if (chan[0] != '#')
{
notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR);
return MOD_CONT;
}
if (readonly)
notice_lang(s_ChanServ, u, READ_ONLY_MODE);
/* Only UNSUSPEND already suspended channels */
if (!(ci = cs_findchan(chan)))
{
notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
return MOD_CONT;
}
if (!(ci->flags & CI_SUSPENDED))
{
notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan);
return MOD_CONT;
}
if (ci)
{
ci->flags &= ~CI_SUSPENDED;
if (ci->forbidreason)
{
delete [] ci->forbidreason;
ci->forbidreason = NULL;
}
if (ci->forbidby)
{
delete [] ci->forbidby;
ci->forbidby = NULL;
}
if (WallForbid)
ircdproto->SendGlobops(s_ChanServ, "\2%s\2 used UNSUSPEND on channel \2%s\2", u->nick, ci->name);
alog("%s: %s set UNSUSPEND for channel %s", s_ChanServ, u->nick, ci->name);
notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan);
send_event(EVENT_CHAN_UNSUSPEND, 1, chan);
}
else
{
alog("%s: Valid UNSUSPEND for %s by %s failed", s_ChanServ, chan, u->nick);
notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan);
}
return MOD_CONT;
}
bool OnHelp(User *u, const std::string &subcommand)
{
if (!is_services_oper(u))
return false;
notice_help(s_ChanServ, u, CHAN_SERVADMIN_HELP_UNSUSPEND);
return true;
}
void OnSyntaxError(User *u)
{
syntax_error(s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX);
}
};
class CSSuspend : public Module
{
public:
CSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetVersion("$Id$");
this->SetType(CORE);
this->AddCommand(CHANSERV, new CommandCSSuspend(), MOD_UNIQUE);
this->AddCommand(CHANSERV, new CommandCSUnSuspend(), MOD_UNIQUE);
this->SetChanHelp(myChanServHelp);
}
};
/**
* Add the help response to anopes /cs help output.
* @param u The user who is requesting help
**/
void myChanServHelp(User *u)
{
if (is_services_oper(u))
{
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SUSPEND);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNSUSPEND);
}
}
MODULE_INIT("cs_suspend", CSSuspend)
|