summaryrefslogtreecommitdiff
path: root/src/core/ms_del.c
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-17 20:33:28 -0400
committerAdam <Adam@anope.org>2010-06-18 21:03:41 -0400
commit17ab4104005cc5098d9152e6c90d54977222dd06 (patch)
treed8ffffedcf5537292a4f19faeb5f1e7796969132 /src/core/ms_del.c
parent2a22d9c2fdf6978858055f1143af0ec40e417424 (diff)
Removed process_numlist and having to mark everything as "in use" and constantly checking it. Replaced with a better system.
Diffstat (limited to 'src/core/ms_del.c')
-rw-r--r--src/core/ms_del.c64
1 files changed, 29 insertions, 35 deletions
diff --git a/src/core/ms_del.c b/src/core/ms_del.c
index b2fd08fa1..68c093f86 100644
--- a/src/core/ms_del.c
+++ b/src/core/ms_del.c
@@ -14,7 +14,33 @@
#include "module.h"
-int del_memo_callback(User *u, int num, va_list args);
+class MemoDelCallback : public NumberList
+{
+ User *u;
+ ChannelInfo *ci;
+ MemoInfo *mi;
+ public:
+ MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list), u(_u), ci(_ci), mi(_mi)
+ {
+ }
+
+ void HandleNumber(unsigned Number)
+ {
+ if (Number > mi->memos.size())
+ return;
+
+ if (ci)
+ {
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, Number - 1));
+ }
+ else
+ {
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, Number - 1));
+ }
+
+ delmemo(mi, Number - 1);
+ }
+};
class CommandMSDel : public Command
{
@@ -28,10 +54,8 @@ class CommandMSDel : public Command
MemoInfo *mi;
ChannelInfo *ci = NULL;
ci::string numstr = params.size() ? params[0] : "", chan;
- int last, last0;
unsigned i;
- char buf[BUFSIZE], *end;
- int delcount, count, left;
+ int last;
if (!numstr.empty() && numstr[0] == '#')
{
@@ -71,37 +95,7 @@ class CommandMSDel : public Command
else
{
if (isdigit(numstr[0]))
- {
- /* Delete a specific memo or memos. */
- last = -1; /* Last memo deleted */
- last0 = -1; /* Beginning of range of last memos deleted */
- end = buf;
- left = sizeof(buf);
- delcount = process_numlist(numstr.c_str(), &count, del_memo_callback, u, mi, &last, &last0, &end, &left, ci);
- if (last != -1)
- {
- /* Some memos got deleted; tell them which ones. */
- if (delcount > 1)
- {
- if (last0 != last)
- end += snprintf(end, sizeof(buf) - (end - buf), ",%d-%d", last0, last);
- else
- end += snprintf(end, sizeof(buf) - (end - buf), ",%d", last);
- /* "buf+1" here because *buf == ',' */
- notice_lang(Config.s_MemoServ, u, MEMO_DELETED_SEVERAL, buf + 1);
- }
- else
- notice_lang(Config.s_MemoServ, u, MEMO_DELETED_ONE, last);
- }
- else
- {
- /* No memos were deleted. Tell them so. */
- if (count == 1)
- notice_lang(Config.s_MemoServ, u, MEMO_DOES_NOT_EXIST, atoi(numstr.c_str()));
- else
- notice_lang(Config.s_MemoServ, u, MEMO_DELETED_NONE);
- }
- }
+ (new MemoDelCallback(u, ci, mi, numstr.c_str()))->Process();
else if (numstr == "LAST")
{
/* Delete last memo. */