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
|
/* MemoServ 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 CommandMSSet : public Command
{
private:
CommandReturn DoNotify(User *u, std::vector<ci::string> ¶ms, MemoInfo *mi)
{
ci::string param = params[1];
if (param == "ON")
{
u->nc->flags |= NI_MEMO_SIGNON | NI_MEMO_RECEIVE;
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_ON, s_MemoServ);
}
else if (param == "LOGON")
{
u->nc->flags |= NI_MEMO_SIGNON;
u->nc->flags &= ~NI_MEMO_RECEIVE;
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_LOGON, s_MemoServ);
}
else if (param == "NEW")
{
u->nc->flags &= ~NI_MEMO_SIGNON;
u->nc->flags |= NI_MEMO_RECEIVE;
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_NEW, s_MemoServ);
}
else if (param == "MAIL")
{
if (u->nc->email)
{
u->nc->flags |= NI_MEMO_MAIL;
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_MAIL);
}
else
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_INVALIDMAIL);
}
else if (param == "NOMAIL")
{
u->nc->flags &= ~NI_MEMO_MAIL;
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_NOMAIL);
}
else if (param == "OFF")
{
u->nc->flags &= ~(NI_MEMO_SIGNON | NI_MEMO_RECEIVE | NI_MEMO_MAIL);
notice_lang(s_MemoServ, u, MEMO_SET_NOTIFY_OFF, s_MemoServ);
}
else
syntax_error(s_MemoServ, u, "SET NOTIFY", MEMO_SET_NOTIFY_SYNTAX);
return MOD_CONT;
}
CommandReturn DoLimit(User *u, std::vector<ci::string> ¶ms, MemoInfo *mi)
{
ci::string p1 = params[1];
ci::string p2 = params.size() > 2 ? params[2] : "";
ci::string p3 = params.size() > 3 ? params[3] : "";
ci::string user, chan;
int32 limit;
NickCore *nc = u->nc;
ChannelInfo *ci = NULL;
bool is_servadmin = u->nc->HasPriv("memoserv/set-limit");
if (p1[0] == '#')
{
chan = p1;
p1 = p2;
p2 = p3;
p3 = params.size() > 4 ? params[4] : "";
if (!(ci = cs_findchan(chan.c_str())))
{
notice_lang(s_MemoServ, u, CHAN_X_NOT_REGISTERED, chan.c_str());
return MOD_CONT;
}
else if (!is_servadmin && !check_access(u, ci, CA_MEMO))
{
notice_lang(s_MemoServ, u, ACCESS_DENIED);
return MOD_CONT;
}
mi = &ci->memos;
}
if (is_servadmin)
{
if (!p2.empty() && p2 != "HARD" && chan.empty())
{
NickAlias *na;
if (!(na = findnick(p1.c_str())))
{
notice_lang(s_MemoServ, u, NICK_X_NOT_REGISTERED, p1.c_str());
return MOD_CONT;
}
user = p1;
mi = &na->nc->memos;
nc = na->nc;
p1 = p2;
p2 = p3;
}
else if (p1.empty())
{
syntax_error(s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SERVADMIN_SYNTAX);
return MOD_CONT;
}
if ((!isdigit(p1[0]) && p1 != "NONE") || (!p2.empty() && p2 != "HARD"))
{
syntax_error(s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SERVADMIN_SYNTAX);
return MOD_CONT;
}
if (!chan.empty())
{
if (!p2.empty())
ci->flags |= CI_MEMO_HARDMAX;
else
ci->flags &= ~CI_MEMO_HARDMAX;
}
else
{
if (!p2.empty())
nc->flags |= NI_MEMO_HARDMAX;
else
nc->flags &= ~NI_MEMO_HARDMAX;
}
limit = atoi(p1.c_str());
if (limit < 0 || limit > 32767)
{
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT_OVERFLOW, 32767);
limit = 32767;
}
if (p1 == "NONE")
limit = -1;
}
else
{
if (p1.empty() || !p2.empty() || !isdigit(p1[0])) {
syntax_error(s_MemoServ, u, "SET LIMIT", MEMO_SET_LIMIT_SYNTAX);
return MOD_CONT;
}
if (!chan.empty() && (ci->flags & CI_MEMO_HARDMAX))
{
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT_FORBIDDEN, chan.c_str());
return MOD_CONT;
}
else if (chan.empty() && (nc->flags & NI_MEMO_HARDMAX))
{
notice_lang(s_MemoServ, u, MEMO_SET_YOUR_LIMIT_FORBIDDEN);
return MOD_CONT;
}
limit = atoi(p1.c_str());
/* The first character is a digit, but we could still go negative
* from overflow... watch out! */
if (limit < 0 || (MSMaxMemos > 0 && limit > MSMaxMemos))
{
if (!chan.empty())
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT_TOO_HIGH, chan.c_str(), MSMaxMemos);
else
notice_lang(s_MemoServ, u, MEMO_SET_YOUR_LIMIT_TOO_HIGH, MSMaxMemos);
return MOD_CONT;
}
else if (limit > 32767)
{
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT_OVERFLOW, 32767);
limit = 32767;
}
}
mi->memomax = limit;
if (limit > 0)
{
if (chan.empty() && nc == u->nc)
notice_lang(s_MemoServ, u, MEMO_SET_YOUR_LIMIT, limit);
else
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str(), limit);
}
else if (!limit)
{
if (chan.empty() && nc == u->nc)
notice_lang(s_MemoServ, u, MEMO_SET_YOUR_LIMIT_ZERO);
else
notice_lang(s_MemoServ, u, MEMO_SET_LIMIT_ZERO, !chan.empty() ? chan.c_str() : user.c_str());
}
else
{
if (chan.empty() && nc == u->nc)
notice_lang(s_MemoServ, u, MEMO_UNSET_YOUR_LIMIT);
else
notice_lang(s_MemoServ, u, MEMO_UNSET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str());
}
return MOD_CONT;
}
public:
CommandMSSet() : Command("SET", 2, 5)
{
}
CommandReturn Execute(User *u, std::vector<ci::string> ¶ms)
{
ci::string cmd = params[0];
MemoInfo *mi = &u->nc->memos;
if (readonly)
{
notice_lang(s_MemoServ, u, MEMO_SET_DISABLED);
return MOD_CONT;
}
else if (cmd == "NOTIFY")
return this->DoNotify(u, params, mi);
else if (cmd == "LIMIT")
return this->DoLimit(u, params, mi);
else
{
notice_lang(s_MemoServ, u, MEMO_SET_UNKNOWN_OPTION, cmd.c_str());
notice_lang(s_MemoServ, u, MORE_INFO, s_MemoServ, "SET");
}
return MOD_CONT;
}
bool OnHelp(User *u, const ci::string &subcommand)
{
if (subcommand.empty())
notice_help(s_MemoServ, u, MEMO_HELP_SET);
else if (subcommand == "NOTIFY")
notice_help(s_MemoServ, u, MEMO_HELP_SET_NOTIFY);
else if (subcommand == "LIMIT")
{
if (u->nc && u->nc->IsServicesOper())
notice_help(s_MemoServ, u, MEMO_SERVADMIN_HELP_SET_LIMIT, MSMaxMemos);
else
notice_help(s_MemoServ, u, MEMO_HELP_SET_LIMIT, MSMaxMemos);
}
else
return false;
return true;
}
void OnSyntaxError(User *u)
{
syntax_error(s_MemoServ, u, "SET", MEMO_SET_SYNTAX);
}
};
class MSSet : public Module
{
public:
MSSet(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetVersion("$Id$");
this->SetType(CORE);
this->AddCommand(MEMOSERV, new CommandMSSet());
}
void MemoServHelp(User *u)
{
notice_lang(s_MemoServ, u, MEMO_HELP_CMD_SET);
}
};
MODULE_INIT(MSSet)
|