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
|
/* MemoServ core functions
*
* (C) 2003-2010 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 MemoDelCallback : public NumberList
{
User *u;
ChannelInfo *ci;
MemoInfo *mi;
public:
MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), mi(_mi)
{
}
void HandleNumber(unsigned Number)
{
if (!Number || Number > mi->memos.size())
return;
if (ci)
FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[Number - 1]));
else
FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[Number - 1]));
mi->Del(Number - 1);
u->SendMessage(MemoServ, MEMO_DELETED_ONE, Number);
}
};
class CommandMSDel : public Command
{
public:
CommandMSDel() : Command("DEL", 0, 2)
{
}
CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms)
{
MemoInfo *mi;
ChannelInfo *ci = NULL;
Anope::string numstr = !params.empty() ? params[0] : "", chan;
unsigned i, end;
if (!numstr.empty() && numstr[0] == '#')
{
chan = numstr;
numstr = params.size() > 1 ? params[1] : "";
if (!(ci = cs_findchan(chan)))
{
u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, chan.c_str());
return MOD_CONT;
}
else if (readonly)
{
u->SendMessage(MemoServ, READ_ONLY_MODE);
return MOD_CONT;
}
else if (!check_access(u, ci, CA_MEMO))
{
u->SendMessage(MemoServ, ACCESS_DENIED);
return MOD_CONT;
}
mi = &ci->memos;
}
else
mi = &u->Account()->memos;
if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST")))
this->OnSyntaxError(u, numstr);
else if (mi->memos.empty())
{
if (!chan.empty())
u->SendMessage(MemoServ, MEMO_X_HAS_NO_MEMOS, chan.c_str());
else
u->SendMessage(MemoServ, MEMO_HAVE_NO_MEMOS);
}
else
{
if (isdigit(numstr[0]))
{
MemoDelCallback list(u, ci, mi, numstr);
list.Process();
}
else if (numstr.equals_ci("LAST"))
{
/* Delete last memo. */
if (ci)
FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[mi->memos.size() - 1]));
else
FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[mi->memos.size() - 1]));
mi->Del(mi->memos[mi->memos.size() - 1]);
u->SendMessage(MemoServ, MEMO_DELETED_ONE, mi->memos.size() + 1);
}
else
{
if (ci)
FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, NULL));
else
FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, NULL));
/* Delete all memos. */
for (i = 0, end = mi->memos.size(); i < end; ++i)
delete mi->memos[i];
mi->memos.clear();
if (!chan.empty())
u->SendMessage(MemoServ, MEMO_CHAN_DELETED_ALL, chan.c_str());
else
u->SendMessage(MemoServ, MEMO_DELETED_ALL);
}
}
return MOD_CONT;
}
bool OnHelp(User *u, const Anope::string &subcommand)
{
u->SendMessage(MemoServ, MEMO_HELP_DEL);
return true;
}
void OnSyntaxError(User *u, const Anope::string &subcommand)
{
SyntaxError(MemoServ, u, "DEL", MEMO_DEL_SYNTAX);
}
void OnServHelp(User *u)
{
u->SendMessage(MemoServ, MEMO_HELP_CMD_DEL);
}
};
class MSDel : public Module
{
CommandMSDel commandmsdel;
public:
MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(CORE);
this->AddCommand(MemoServ, &commandmsdel);
}
};
MODULE_INIT(MSDel)
|