summaryrefslogtreecommitdiff
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
parent2a22d9c2fdf6978858055f1143af0ec40e417424 (diff)
Removed process_numlist and having to mark everything as "in use" and constantly checking it. Replaced with a better system.
-rw-r--r--include/extern.h6
-rw-r--r--include/modules.h14
-rw-r--r--include/regchannel.h22
-rw-r--r--include/services.h28
-rw-r--r--src/chanserv.c26
-rw-r--r--src/core/bs_badwords.c170
-rw-r--r--src/core/cs_access.c319
-rw-r--r--src/core/cs_akick.c269
-rw-r--r--src/core/cs_set.c8
-rw-r--r--src/core/cs_xop.c232
-rw-r--r--src/core/db_plain.cpp5
-rw-r--r--src/core/ms_del.c64
-rw-r--r--src/core/ms_list.c119
-rw-r--r--src/core/ms_read.c111
-rw-r--r--src/core/os_session.c269
-rw-r--r--src/memoserv.c1
-rw-r--r--src/misc.c132
-rw-r--r--src/regchannel.cpp89
18 files changed, 937 insertions, 947 deletions
diff --git a/include/extern.h b/include/extern.h
index 757bac3dc..100aceaa3 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -81,6 +81,7 @@ E User *nc_on_chan(Channel * c, NickCore * nc);
E char *chan_get_modes(Channel * chan, int complete, int plus);
E int get_access_level(ChannelInfo * ci, NickAlias * na);
+E int get_access_level(ChannelInfo *ci, NickCore *nc);
E const char *get_xop_level(int level);
E void do_cmode(const char *source, int ac, const char **av);
@@ -262,6 +263,7 @@ E char *sstrdup(const char *s);
E void ms_init();
E void memoserv(User * u, char *buf);
+E void rsend_notify(User *u, Memo *m, const char *chan);
E void check_memos(User * u);
E MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid);
E void memo_send(User * u, const char *name, const char *text, int z);
@@ -302,10 +304,6 @@ E const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds);
E const char *expire_left(NickCore *nc, char *buf, int len, time_t expires);
E int doValidHost(const char *host, int type);
-typedef int (*range_callback_t) (User * u, int num, va_list args);
-E int process_numlist(const char *numstr, int *count_ret,
- range_callback_t callback, User * u, ...);
-
E int isValidHost(const char *host, int type);
E int isvalidchar(const char c);
diff --git a/include/modules.h b/include/modules.h
index d76b8f70b..98dfd6d3e 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -790,18 +790,18 @@ class CoreExport Module
/** Called when access is changed
* @param ci The channel
* @param u The user who changed the access
- * @param na The nick whos access was changed
+ * @param nc The nick whos access was changed
* @param level The level of the new access
*/
- virtual void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level) { }
+ virtual void OnAccessChange(ChannelInfo *ci, User *u, NickCore *nc, int level) { }
/** Called when access is added
* @param ci The channel
* @param u The user who added the access
- * @para na The nick who was added to access
+ * @para nc The nick who was added to access
* @param level The level they were added at
*/
- virtual void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level) { }
+ virtual void OnAccessAdd(ChannelInfo *ci, User *u, NickCore *nc, int level) { }
/** Called when the access list is cleared
* @param ci The channel
@@ -858,16 +858,18 @@ class CoreExport Module
virtual void OnChannelDelete(Channel *c) { }
/** Called after adding an akick to a channel
+ * @param u The user adding the akick
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickAdd(ChannelInfo *ci, AutoKick *ak) { }
+ virtual void OnAkickAdd(User *u, ChannelInfo *ci, AutoKick *ak) { }
/** Called before removing an akick from a channel
+ * @param u The user removing the akick
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickDel(ChannelInfo *ci, AutoKick *ak) { }
+ virtual void OnAkickDel(User *u, ChannelInfo *ci, AutoKick *ak) { }
/** Called when a user requests info for a channel
* @param u The user requesting info
diff --git a/include/regchannel.h b/include/regchannel.h
index 474b6f79a..e4c6fa6f5 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -161,12 +161,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag>
*/
void EraseAccess(unsigned index);
- /** Cleans the channel access list
- *
- * Cleans up the access list so it no longer contains entries no longer in use.
- */
- void CleanAccess();
-
/** Clear the entire channel access list
*
* Clears the entire access list by deleting every item and then clearing the vector.
@@ -203,18 +197,14 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag>
const unsigned GetAkickCount() const;
/** Erase an entry from the channel akick list
- * @param akick The akick
+ * @param index The index of the akick
*/
- void EraseAkick(AutoKick *akick);
+ void EraseAkick(unsigned index);
/** Clear the whole akick list
*/
void ClearAkick();
- /** Clean all of the nonused entries from the akick list
- */
- void CleanAkick();
-
/** Add a badword to the badword list
* @param word The badword
* @param type The type (SINGLE START END)
@@ -234,18 +224,14 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag>
const unsigned GetBadWordCount() const;
/** Remove a badword
- * @param badword The badword
+ * @param index The index of the badword
*/
- void EraseBadWord(BadWord *badword);
+ void EraseBadWord(unsigned index);
/** Clear all badwords from the channel
*/
void ClearBadWords();
- /** Clean all of the nonused entries from the badwords list
- */
- void CleanBadWords();
-
/** Check if a mode is mlocked
* @param Name The mode
* @param status True to check mlock on, false for mlock off
diff --git a/include/services.h b/include/services.h
index 6d7669e63..7db58e3fb 100644
--- a/include/services.h
+++ b/include/services.h
@@ -530,7 +530,6 @@ enum AccessLevel
/* Access levels for users. */
struct ChanAccess
{
- uint16 in_use; /* 1 if this entry is in use, else 0 */
int16 level;
NickCore *nc; /* Guaranteed to be non-NULL if in use, NULL if not */
time_t last_seen;
@@ -551,7 +550,6 @@ enum AutoKickFlag
class AutoKick : public Flags<AutoKickFlag>
{
public:
- bool InUse;
/* Only one of these can be in use */
std::string mask;
NickCore *nc;
@@ -579,7 +577,6 @@ enum BadWordType
/* Structure used to contain bad words. */
struct BadWord
{
- bool InUse;
std::string word;
BadWordType type;
};
@@ -1164,4 +1161,29 @@ class ChanServTimer : public Timer
void Tick(time_t);
};
+/** A class to process numbered lists (passed to most DEL commands).
+ * The function HandleNumber is called for every number in the list. Note that
+ * it *always* gets called in descending order. This is so deleting the index passed
+ * to the function from an array will not cause the other indexes passed to the function
+ * to be incorrect. This keeps us from having to have an 'in use' flag on everything.
+ */
+class NumberList
+{
+ private:
+ std::set<unsigned> numbers;
+ public:
+ /** Processes a numbered list
+ * @param list The list
+ */
+ NumberList(const std::string &list);
+
+ virtual ~NumberList();
+
+ void Process();
+
+ virtual void HandleNumber(unsigned Number);
+
+ virtual bool InvalidRange(const std::string &list);
+};
+
#endif /* SERVICES_H */
diff --git a/src/chanserv.c b/src/chanserv.c
index 7f5602ed1..17dd65a7b 100644
--- a/src/chanserv.c
+++ b/src/chanserv.c
@@ -788,15 +788,15 @@ void cs_remove_nick(const NickCore * nc)
{
ca = ci->GetAccess(j - 1);
- if (ca->in_use && ca->nc == nc)
+ if (ca->nc == nc)
ci->EraseAccess(j - 1);
}
for (j = ci->GetAkickCount(); j > 0; --j)
{
akick = ci->GetAkick(j - 1);
- if (akick->InUse && akick->HasFlag(AK_ISNICK) && akick->nc == nc)
- ci->EraseAkick(akick);
+ if (akick->HasFlag(AK_ISNICK) && akick->nc == nc)
+ ci->EraseAkick(j - 1);
}
}
}
@@ -1054,6 +1054,22 @@ int get_access_level(ChannelInfo * ci, NickAlias * na)
return access->level;
}
+int get_access_level(ChannelInfo *ci, NickCore *nc)
+{
+ if (!ci || !nc)
+ return 0;
+
+ if (nc == ci->founder)
+ return ACCESS_FOUNDER;
+
+ ChanAccess *access = ci->GetAccess(nc);
+
+ if (!access)
+ return 0;
+ else
+ return access->level;
+}
+
const char *get_xop_level(int level)
{
ChannelMode *halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP);
@@ -1091,7 +1107,7 @@ AutoKick *is_stuck(ChannelInfo * ci, const char *mask)
{
AutoKick *akick = ci->GetAkick(i);
- if (!akick->InUse || akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK))
+ if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK))
continue;
if (Anope::Match(akick->mask, mask, false))
@@ -1146,7 +1162,7 @@ void stick_all(ChannelInfo * ci)
{
AutoKick *akick = ci->GetAkick(i);
- if (!akick->InUse || (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK)))
+ if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK))
continue;
ci->c->SetMode(NULL, CMODE_BAN, akick->mask.c_str());
diff --git a/src/core/bs_badwords.c b/src/core/bs_badwords.c
index 3db6f1e42..ce026e9c4 100644
--- a/src/core/bs_badwords.c
+++ b/src/core/bs_badwords.c
@@ -14,40 +14,106 @@
#include "module.h"
-int badwords_del_callback(User * u, int num, va_list args);
-int badwords_list(User * u, int index, ChannelInfo * ci, int *sent_header);
-int badwords_list_callback(User * u, int num, va_list args);
+class BadwordsListCallback : public NumberList
+{
+ User *u;
+ ChannelInfo *ci;
+ bool SentHeader;
+ public:
+ BadwordsListCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list), u(_u), ci(_ci), SentHeader(false)
+ {
+ }
+
+ ~BadwordsListCallback()
+ {
+ if (!SentHeader)
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
+ }
+
+ void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->GetBadWordCount())
+ return;
+
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
+ }
+
+ DoList(u, ci, Number - 1, ci->GetBadWord(Number - 1));
+ }
+
+ static void DoList(User *u, ChannelInfo *ci, unsigned Number, BadWord *bw)
+ {
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), ((bw->type == BW_SINGLE) ? "(SINGLE)" : ((bw->type == BW_START) ? "(START)" : ((bw->type == BW_END) ? "(END)" : ""))));
+ }
+};
+
+class BadwordsDelCallback : public NumberList
+{
+ User *u;
+ ChannelInfo *ci;
+ unsigned Deleted;
+ public:
+ BadwordsDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list), u(_u), ci(_ci), Deleted(0)
+ {
+ }
+
+ ~BadwordsDelCallback()
+ {
+ if (!Deleted)
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
+ else if (Deleted == 1)
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_ONE, ci->name.c_str());
+ else
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_SEVERAL, Deleted, ci->name.c_str());
+ }
+
+ void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->GetBadWordCount())
+ return;
+
+ ++Deleted;
+ ci->EraseBadWord(Number - 1);
+ }
+};
class CommandBSBadwords : public Command
{
private:
CommandReturn DoList(User *u, ChannelInfo *ci, const ci::string &word)
{
- int sent_header = 0;
-
if (!ci->GetBadWordCount())
{
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str());
- return MOD_CONT;
- }
- if (!word.empty() && strspn(word.c_str(), "1234567890,-") == word.length())
- {
- process_numlist(word.c_str(), NULL, badwords_list_callback, u, ci, &sent_header);
}
+ else if (!word.empty() && strspn(word.c_str(), "1234567890,-") == word.length())
+ (new BadwordsListCallback(u, ci, word.c_str()))->Process();
else
{
+ bool SentHeader = false;
+
for (unsigned i = 0; i < ci->GetBadWordCount(); i++)
{
- BadWord *badword = ci->GetBadWord(i);
+ BadWord *bw = ci->GetBadWord(i);
- if (!word.empty() && !Anope::Match(badword->word, word.c_str(), false))
+ if (!word.empty() && !Anope::Match(bw->word, word.c_str(), false))
continue;
- badwords_list(u, i, ci, &sent_header);
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
+ }
+
+ BadwordsListCallback::DoList(u, ci, i, bw);
}
+
+ if (!SentHeader)
+ notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
}
- if (!sent_header)
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
return MOD_CONT;
}
@@ -102,33 +168,7 @@ class CommandBSBadwords : public Command
{
/* Special case: is it a number/list? Only do search if it isn't. */
if (!word.empty() && isdigit(word[0]) && strspn(word.c_str(), "1234567890,-") == word.length())
- {
- int count, deleted, last = -1;
- deleted = process_numlist(word.c_str(), &count, badwords_del_callback, u, ci, &last);
-
- if (!deleted)
- {
- if (count == 1)
- {
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_SUCH_ENTRY, last, ci->name.c_str());
- }
- else
- {
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
- }
- }
- else if (deleted == 1)
- {
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_ONE, ci->name.c_str());
- }
- else
- {
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_SEVERAL, deleted, ci->name.c_str());
- }
-
- if (deleted)
- ci->CleanBadWords();
- }
+ (new BadwordsDelCallback(u, ci, word.c_str()))->Process();
else
{
unsigned i;
@@ -148,7 +188,7 @@ class CommandBSBadwords : public Command
return MOD_CONT;
}
- ci->EraseBadWord(badword);
+ ci->EraseBadWord(i);
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED, badword->word.c_str(), ci->name.c_str());
}
@@ -239,48 +279,4 @@ class BSBadwords : public Module
}
};
-int badwords_del_callback(User * u, int num, va_list args)
-{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *last = va_arg(args, int *);
-
- *last = num;
-
- if (num < 1 || num > ci->GetBadWordCount())
- return 0;
-
- ci->GetBadWord(num - 1)->InUse = false;
-
- return 1;
-}
-
-int badwords_list(User * u, int index, ChannelInfo * ci, int *sent_header)
-{
- BadWord *bw = ci->GetBadWord(index);
-
- if (!*sent_header)
- {
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
- *sent_header = 1;
- }
-
- notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, index + 1, bw->word.c_str(),
- ((bw->type == BW_SINGLE) ? "(SINGLE)" : ((bw->type == BW_START) ? "(START)"
- : ((bw->type == BW_END) ? "(END)" : "")))
- );
-
- return 1;
-}
-
-int badwords_list_callback(User * u, int num, va_list args)
-{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *sent_header = va_arg(args, int *);
-
- if (num < 1 || num > ci->GetBadWordCount())
- return 0;
-
- return badwords_list(u, num - 1, ci, sent_header);
-}
-
MODULE_INIT(BSBadwords)
diff --git a/src/core/cs_access.c b/src/core/cs_access.c
index 718a7dc0f..f49fca990 100644
--- a/src/core/cs_access.c
+++ b/src/core/cs_access.c
@@ -14,116 +14,151 @@
#include "module.h"
-static int access_del(User * u, ChannelInfo *ci, ChanAccess * access, int *perm, int uacc)
+class AccessListCallback : public NumberList
{
- if (!access->in_use)
- return 0;
- if (uacc <= access->level && !u->Account()->HasPriv("chanserv/access/modify"))
+ protected:
+ User *u;
+ ChannelInfo *ci;
+ bool SentHeader;
+ public:
+ AccessListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), SentHeader(false)
{
- (*perm)++;
- return 0;
}
- NickCore *nc = access->nc;
- access->nc = NULL;
- access->in_use = 0;
- FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, nc));
+ ~AccessListCallback()
+ {
+ if (SentHeader)
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str());
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, ci->name.c_str());
+ }
- return 1;
-}
+ virtual void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->GetAccessCount())
+ return;
-static int access_del_callback(User * u, int num, va_list args)
-{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *last = va_arg(args, int *);
- int *perm = va_arg(args, int *);
- int uacc = va_arg(args, int);
- if (num < 1 || num > ci->GetAccessCount())
- return 0;
- *last = num;
- return access_del(u, ci, ci->GetAccess(num - 1), perm, uacc);
-}
-
-
-static int access_list(User * u, int index, ChannelInfo * ci, int *sent_header)
-{
- ChanAccess *access = ci->GetAccess(index);
- const char *xop;
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
+ }
- if (!access->in_use)
- return 0;
+ DoList(u, ci, Number - 1, ci->GetAccess(Number - 1));
+ }
- if (!*sent_header)
+ static void DoList(User *u, ChannelInfo *ci, unsigned Number, ChanAccess *access)
{
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
- *sent_header = 1;
+ if (ci->HasFlag(CI_XOP))
+ {
+ const char *xop = get_xop_level(access->level);
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_XOP_FORMAT, Number + 1, xop, access->nc->display);
+ }
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_AXS_FORMAT, Number + 1, access->level, access->nc->display);
}
+};
- if (ci->HasFlag(CI_XOP))
+class AccessViewCallback : public AccessListCallback
+{
+ public:
+ AccessViewCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : AccessListCallback(_u, _ci, numlist)
{
- xop = get_xop_level(access->level);
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_XOP_FORMAT, index + 1, xop, access->nc->display);
}
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_AXS_FORMAT, index + 1, access->level, access->nc->display);
- return 1;
-}
-static int access_list_callback(User * u, int num, va_list args)
-{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *sent_header = va_arg(args, int *);
- if (num < 1 || num > ci->GetAccessCount())
- return 0;
- return access_list(u, num - 1, ci, sent_header);
-}
-
-static int access_view(User *u, int index, ChannelInfo *ci, int *sent_header)
-{
- ChanAccess *access = ci->GetAccess(index);
- const char *xop;
- char timebuf[64];
- tm tm;
+ void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->GetAccessCount())
+ return;
- if (!access || !access->in_use)
- return 0;
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
+ }
+
+ DoList(u, ci, Number - 1, ci->GetAccess(Number - 1));
+ }
- if (!*sent_header)
+ static void DoList(User *u, ChannelInfo *ci, unsigned Number, ChanAccess *access)
{
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
- *sent_header = 1;
+ char timebuf[64];
+ struct tm tm;
+
+ memset(&timebuf, 0, sizeof(timebuf));
+ if (ci->c && u->Account() && nc_on_chan(ci->c, u->Account()))
+ snprintf(timebuf, sizeof(timebuf), "Now");
+ else if (access->last_seen == 0)
+ snprintf(timebuf, sizeof(timebuf), "Never");
+ else
+ {
+ tm = *localtime(&access->last_seen);
+ strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm);
+ }
+
+ if (ci->HasFlag(CI_XOP))
+ {
+ const char *xop = get_xop_level(access->level);
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop, access->nc->display, access->creator.c_str(), timebuf);
+ }
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->nc->display, access->creator.c_str(), timebuf);
}
+};
- memset(&timebuf, 0, sizeof(timebuf));
- if (ci->c && u->Account() && nc_on_chan(ci->c, u->Account()))
- sprintf(timebuf, "Now");
- else if (access->last_seen == 0)
- sprintf(timebuf, "Never");
- else
+class AccessDelCallback : public NumberList
+{
+ User *u;
+ ChannelInfo *ci;
+ unsigned Deleted;
+ std::string Nicks;
+ bool Denied;
+ public:
+ AccessDelCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), Deleted(0), Denied(false)
{
- tm = *localtime(&access->last_seen);
- strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm);
}
- if (ci->HasFlag(CI_XOP))
+ ~AccessDelCallback()
{
- xop = get_xop_level(access->level);
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_XOP_FORMAT, index + 1, xop, access->nc->display, access->creator.c_str(), timebuf);
+ if (Denied && !Deleted)
+ notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
+ else if (!Deleted)
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, ci->name.c_str());
+ else
+ {
+ Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << get_access(u, ci) << ") deleted access of user" << (Deleted == 1 ? " " : "s ") << Nicks << " on " << ci->name;
+
+ if (Deleted == 1)
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED_ONE, ci->name.c_str());
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED_SEVERAL, Deleted, ci->name.c_str());
+ }
}
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_VIEW_AXS_FORMAT, index + 1, access->level, access->nc->display, access->creator.c_str(), timebuf);
- return 1;
-}
+ void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->GetAccessCount())
+ return;
+
+ ChanAccess *access = ci->GetAccess(Number - 1);
-static int access_view_callback(User *u, int num, va_list args)
-{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *sent_header = va_arg(args, int *);
- if (num < 1 || num > ci->GetAccessCount())
- return 0;
- return access_view(u, num - 1, ci, sent_header);
-}
+ if (get_access(u, ci) <= access->level && !u->Account()->HasPriv("chanserv/access/modify"))
+ {
+ Denied = true;
+ return;
+ }
+
+ ++Deleted;
+ if (!Nicks.empty())
+ Nicks += ", " + std::string(access->nc->display);
+ else
+ Nicks = access->nc->display;
+
+ FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, access->nc));
+
+ ci->EraseAccess(Number - 1);
+ }
+};
class CommandCSAccess : public Command
{
@@ -224,7 +259,7 @@ class CommandCSAccess : public Command
}
access->level = level;
- FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na, level));
+ FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na->nc, level));
Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << ulev << ") set access level "
<< access->level << " to " << na->nick << " (group " << nc->display << ") on channel " << ci->name;
@@ -238,10 +273,9 @@ class CommandCSAccess : public Command
return MOD_CONT;
}
- std::string usernick = u->nick;
- ci->AddAccess(nc, level, usernick);
+ ci->AddAccess(nc, level, u->nick);
- FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, na, level));
+ FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, nc, level));
Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << ulev << ") set access level "
<< level << " to " << na->nick << " (group " << nc->display << ") on channel " << ci->name;
@@ -249,7 +283,6 @@ class CommandCSAccess : public Command
}
else if (cmd == "DEL")
{
- int deleted;
if (readonly)
{
notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DISABLED);
@@ -264,31 +297,7 @@ class CommandCSAccess : public Command
/* Special case: is it a number/list? Only do search if it isn't. */
if (isdigit(*nick) && strspn(nick, "1234567890,-") == strlen(nick))
- {
- int count, last = -1, perm = 0;
- deleted = process_numlist(nick, &count, access_del_callback, u, ci, &last, &perm, get_access(u, ci));
- if (!deleted)
- {
- if (perm)
- notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
- else if (count == 1)
- {
- last = atoi(nick);
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_SUCH_ENTRY, last, ci->name.c_str());
- }
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, ci->name.c_str());
- }
- else
- {
- Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << get_access(u, ci)
- << ") deleted access of user" << (deleted == 1 ? " " : "s ") << nick << " on " << chan;
- if (deleted == 1)
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED_ONE, ci->name.c_str());
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED_SEVERAL, deleted, ci->name.c_str());
- }
- }
+ (new AccessDelCallback(u, ci, nick))->Process();
else
{
na = findnick(nick);
@@ -297,16 +306,25 @@ class CommandCSAccess : public Command
notice_lang(Config.s_ChanServ, u, NICK_X_NOT_REGISTERED, nick);
return MOD_CONT;
}
+
nc = na->nc;
- access = ci->GetAccess(nc);
- if (!access)
+
+ for (i = 0; i < ci->GetAccessCount(); ++i)
+ {
+ access = ci->GetAccess(i);
+
+ if (access->nc == nc)
+ break;
+ }
+
+ if (i == ci->GetAccessCount())
{
notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NOT_FOUND, nick, chan);
return MOD_CONT;
}
+
if (get_access(u, ci) <= access->level && !u->Account()->HasPriv("chanserv/access/modify"))
{
- deleted = 0;
notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
}
else
@@ -314,76 +332,81 @@ class CommandCSAccess : public Command
notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_DELETED, access->nc->display, ci->name.c_str());
Alog() << Config.s_ChanServ << ": " << u->GetMask() << " (level " << get_access(u, ci)
<< ") deleted access of " << na->nick << " (group " << access->nc->display << ") on " << chan;
- access->nc = NULL;
- access->in_use = 0;
- deleted = 1;
- }
- }
-
- if (deleted)
- {
- /* We'll free the access entries no longer in use... */
- ci->CleanAccess();
-
- /* Only call this event if na exists (if they deleted by user, not numlist).
- * The callback for deleting by numlist will call this event otherwise - Adam */
- if (na)
- {
FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, na->nc));
+
+ ci->EraseAccess(i);
}
}
}
else if (cmd == "LIST")
{
- int sent_header = 0;
-
if (!ci->GetAccessCount())
{
notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, chan);
return MOD_CONT;
}
if (nick && strspn(nick, "1234567890,-") == strlen(nick))
- process_numlist(nick, NULL, access_list_callback, u, ci, &sent_header);
+ (new AccessListCallback(u, ci, nick))->Process();
else
{
+ bool SentHeader = false;
+
for (i = 0; i < ci->GetAccessCount(); i++)
{
access = ci->GetAccess(i);
+
if (nick && access->nc && !Anope::Match(access->nc->display, nick, false))
continue;
- access_list(u, i, ci, &sent_header);
+
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
+ }
+
+ AccessListCallback::DoList(u, ci, i, access);
}
+
+ if (SentHeader)
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str());
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, chan);
}
- if (!sent_header)
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, chan);
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str());
}
else if (cmd == "VIEW")
{
- int sent_header = 0;
-
if (!ci->GetAccessCount())
{
notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_EMPTY, chan);
return MOD_CONT;
}
if (nick && strspn(nick, "1234567890,-") == strlen(nick))
- process_numlist(nick, NULL, access_view_callback, u, ci, &sent_header);
+ (new AccessViewCallback(u, ci, nick))->Process();
else
{
+ bool SentHeader = false;
+
for (i = 0; i < ci->GetAccessCount(); ++i)
{
access = ci->GetAccess(i);
+
if (nick && access->nc && !Anope::Match(access->nc->display, nick, false))
continue;
- access_view(u, i, ci, &sent_header);
+
+ if (!SentHeader)
+ {
+ SentHeader = true;
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
+ }
+
+ AccessViewCallback::DoList(u, ci, i, access);
}
+
+ if (SentHeader)
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str());
+ else
+ notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, chan);
}
- if (!sent_header)
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_NO_MATCH, chan);
- else
- notice_lang(Config.s_ChanServ, u, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str());
}
else if (cmd == "CLEAR")
{
diff --git a/src/core/cs_akick.c b/src/core/cs_akick.c
index abd00be6a..42b79c362 100644
--- a/src/core/cs_akick.c
+++ b/src/core/cs_akick.c
@@ -45,103 +45,125 @@ static void split_usermask(const char *mask, const char **nick, const char **use
delete [] mask2;
}
-int akick_del_callback(User * u, int num, va_list args)
+class AkickListCallback : public NumberList
{
- ChannelInfo *ci = va_arg(args, ChannelInfo *);
- int *last = va_arg(args, int *);
+ protected:
+ User *u;
+ ChannelInfo *ci;
+ bool SentHeader;
+ public:
+ AkickListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), SentHeader(false)
+ {
+ }
+
+ ~AkickListCallback()
+ {
+ if (!SentHeader)
+ notice_lang(Config.s_ChanServ, u, CHAN_AKICK_NO_MATCH, ci->name.c_str());
+ }
- *last = num;
+ virtual void HandleNumber(unsigned Number)
+ {
+ if (Number > ci->G