summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrobbeh <robbeh@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 22:09:22 +0000
committerrobbeh <robbeh@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 22:09:22 +0000
commit3fe6a2523644b3952966b19ddb6a3fcee6a4fac2 (patch)
tree3cd771ed1c778d29cf8236d62680be32ac4e734e /src
parent8c5a7e7aead2e2f4a463d829f1db36d4ae3ffc16 (diff)
Moved cs_list.c to use the new command API
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1959 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/core/cs_list.c285
1 files changed, 151 insertions, 134 deletions
diff --git a/src/core/cs_list.c b/src/core/cs_list.c
index 28a51634e..505ed8895 100644
--- a/src/core/cs_list.c
+++ b/src/core/cs_list.c
@@ -14,30 +14,7 @@
/*************************************************************************/
#include "module.h"
-
-int do_list(User * u);
-void myChanServHelp(User * u);
-
-class CSList : public Module
-{
- public:
- CSList(const std::string &modname, const std::string &creator) : Module(modname, creator)
- {
- Command *c;
-
- this->SetAuthor("Anope");
- this->SetVersion("$Id$");
- this->SetType(CORE);
-
- c = createCommand("LIST", do_list, NULL, -1, CHAN_HELP_LIST, CHAN_SERVADMIN_HELP_LIST, CHAN_SERVADMIN_HELP_LIST, CHAN_SERVADMIN_HELP_LIST);
-
- this->AddCommand(CHANSERV, c, MOD_UNIQUE);
-
- this->SetChanHelp(myChanServHelp);
- }
-};
-
-
+#include "hashcomp.h"
/**
* Add the help response to anopes /cs help output.
@@ -45,143 +22,183 @@ class CSList : public Module
**/
void myChanServHelp(User * u)
{
- if (!CSListOpersOnly || (is_oper(u))) {
+ if (!CSListOpersOnly || (is_oper(u)))
+ {
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_LIST);
}
}
-/**
- * The /cs list command.
- * @param u The user who issued the command
- * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
- **/
-int do_list(User * u)
+
+class CommandCSList : public Command
{
- char *pattern = strtok(NULL, " ");
- int spattern_size;
- char *spattern;
- ChannelInfo *ci;
- unsigned nchans, i;
- char buf[BUFSIZE];
- int is_servadmin = is_services_admin(u);
- int count = 0, from = 0, to = 0, tofree = 0;
- char *tmp = NULL;
- char *s = NULL;
- char *keyword;
- int32 matchflags = 0;
-
- if (!(!CSListOpersOnly || (is_oper(u)))) {
- notice_lang(s_ChanServ, u, ACCESS_DENIED);
- return MOD_STOP;
- }
+public:
+ CommandCSList() : Command("LIST",1,2) { }
- if (!pattern) {
- syntax_error(s_ChanServ, u, "LIST",
- is_servadmin ? CHAN_LIST_SERVADMIN_SYNTAX :
- CHAN_LIST_SYNTAX);
- } else {
+ CommandReturn Execute(User *u, std::vector<std::string> &params)
+ {
+ const char *pattern = params[0].c_str();
+ int spattern_size;
+ char *spattern;
+ ChannelInfo *ci;
+ unsigned nchans, i;
+ char buf[BUFSIZE];
+ int is_servadmin = is_services_admin(u);
+ int count = 0, from = 0, to = 0, tofree = 0;
+ char *tmp = NULL;
+ char *s = NULL;
+ int32 matchflags = 0;
+
+ if (!(!CSListOpersOnly || (is_oper(u))))
+ {
+ notice_lang(s_ChanServ, u, ACCESS_DENIED);
+ return MOD_STOP;
+ }
- if (pattern) {
- if (pattern[0] == '#') {
- tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */
- if (!tmp) {
+ if (pattern[0] == '#')
+ {
+ tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */
+ if (!tmp)
+ {
+ notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
+ notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
+ return MOD_CONT;
+ }
+ for (s = tmp; *s; s++)
+ {
+ if (!isdigit(*s))
+ {
+ delete [] tmp;
notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
return MOD_CONT;
}
- for (s = tmp; *s; s++) {
- if (!isdigit(*s)) {
- delete [] tmp;
- notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
- notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- }
- from = atoi(tmp);
- delete [] tmp;
- tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */
- if (!tmp) {
+ }
+ from = atoi(tmp);
+ delete [] tmp;
+ tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */
+ if (!tmp)
+ {
+ notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
+ notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
+ return MOD_CONT;
+ }
+ for (s = tmp; *s; s++)
+ {
+ if (!isdigit(*s))
+ {
+ delete [] tmp;
notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
return MOD_CONT;
}
- for (s = tmp; *s; s++) {
- if (!isdigit(*s)) {
- delete [] tmp;
- notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
- notice_lang(s_ChanServ, u, CS_LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- }
- to = atoi(tmp);
- delete [] tmp;
- pattern = sstrdup("*");
- tofree = 1;
}
+ to = atoi(tmp);
+ delete [] tmp;
+ pattern = sstrdup("*");
+ tofree = 1;
}
nchans = 0;
- while (is_servadmin && (keyword = strtok(NULL, " "))) {
- if (stricmp(keyword, "FORBIDDEN") == 0)
- matchflags |= CI_VERBOTEN;
- if (stricmp(keyword, "SUSPENDED") == 0)
- matchflags |= CI_SUSPENDED;
- if (stricmp(keyword, "NOEXPIRE") == 0)
- matchflags |= CI_NO_EXPIRE;
- }
+ if (is_servadmin && params.size() > 1)
+ {
+ std::string keyword;
+ spacesepstream keywords(params[1]);
+ while (keywords.GetToken(keyword))
+ {
+ if (stricmp(keyword.c_str(), "FORBIDDEN") == 0)
+ matchflags |= CI_VERBOTEN;
+ if (stricmp(keyword.c_str(), "SUSPENDED") == 0)
+ matchflags |= CI_SUSPENDED;
+ if (stricmp(keyword.c_str(), "NOEXPIRE") == 0)
+ matchflags |= CI_NO_EXPIRE;
- spattern_size = (strlen(pattern) + 2) * sizeof(char);
- spattern = new char[spattern_size];
- snprintf(spattern, spattern_size, "#%s", pattern);
-
-
- notice_lang(s_ChanServ, u, CHAN_LIST_HEADER, pattern);
- for (i = 0; i < 256; i++) {
- for (ci = chanlists[i]; ci; ci = ci->next) {
- if (!is_servadmin && ((ci->flags & CI_PRIVATE)
- || (ci->flags & CI_VERBOTEN)))
- continue;
- if ((matchflags != 0) && !(ci->flags & matchflags))
- continue;
-
- if ((stricmp(pattern, ci->name) == 0)
- || (stricmp(spattern, ci->name) == 0)
- || match_wild_nocase(pattern, ci->name)
- || match_wild_nocase(spattern, ci->name)) {
- if ((((count + 1 >= from) && (count + 1 <= to))
- || ((from == 0) && (to == 0)))
- && (++nchans <= CSListMax)) {
- char noexpire_char = ' ';
- if (is_servadmin && (ci->flags & CI_NO_EXPIRE))
- noexpire_char = '!';
-
- if (ci->flags & CI_VERBOTEN) {
- snprintf(buf, sizeof(buf),
- "%-20s [Forbidden]", ci->name);
- } else if (ci->flags & CI_SUSPENDED) {
- snprintf(buf, sizeof(buf),
- "%-20s [Suspended]", ci->name);
- } else {
- snprintf(buf, sizeof(buf), "%-20s %s",
- ci->name, ci->desc ? ci->desc : "");
- }
+ }
- notice_user(s_ChanServ, u, " %c%s",
- noexpire_char, buf);
+ spattern_size = (strlen(pattern) + 2) * sizeof(char);
+ spattern = new char[spattern_size];
+ snprintf(spattern, spattern_size, "#%s", pattern);
+
+
+ notice_lang(s_ChanServ, u, CHAN_LIST_HEADER, pattern);
+ for (i = 0; i < 256; i++)
+ {
+ for (ci = chanlists[i]; ci; ci = ci->next)
+ {
+ if (!is_servadmin && ((ci->flags & CI_PRIVATE)
+ || (ci->flags & CI_VERBOTEN)))
+ continue;
+ if ((matchflags != 0) && !(ci->flags & matchflags))
+ continue;
+
+ if ((stricmp(pattern, ci->name) == 0)
+ || (stricmp(spattern, ci->name) == 0)
+ || match_wild_nocase(pattern, ci->name)
+ || match_wild_nocase(spattern, ci->name))
+ {
+ if ((((count + 1 >= from) && (count + 1 <= to))
+ || ((from == 0) && (to == 0)))
+ && (++nchans <= CSListMax))
+ {
+ char noexpire_char = ' ';
+ if (is_servadmin && (ci->flags & CI_NO_EXPIRE))
+ noexpire_char = '!';
+
+ if (ci->flags & CI_VERBOTEN)
+ {
+ snprintf(buf, sizeof(buf),
+ "%-20s [Forbidden]", ci->name);
+ }
+ else if (ci->flags & CI_SUSPENDED)
+ {
+ snprintf(buf, sizeof(buf),
+ "%-20s [Suspended]", ci->name);
+ }
+ else
+ {
+ snprintf(buf, sizeof(buf), "%-20s %s",
+ ci->name, ci->desc ? ci->desc : "");
+ }
+
+ notice_user(s_ChanServ, u, " %c%s",
+ noexpire_char, buf);
+ }
+ count++;
}
- count++;
}
}
+ notice_lang(s_ChanServ, u, CHAN_LIST_END,
+ nchans > CSListMax ? CSListMax : nchans, nchans);
+ delete [] spattern;
}
- notice_lang(s_ChanServ, u, CHAN_LIST_END,
- nchans > CSListMax ? CSListMax : nchans, nchans);
- delete [] spattern;
+ if (tofree)
+ delete [] pattern;
+ return MOD_CONT;
}
- if (tofree)
- delete [] pattern;
- return MOD_CONT;
-}
+ bool OnHelp(User *u, const std::string &subcommand)
+ {
+ notice_lang(s_ChanServ, u, CHAN_HELP_LIST);
+ return true;
+ }
+
+ void OnSyntaxError(User *u)
+ {
+ syntax_error(s_ChanServ, u, "LIST", CHAN_LIST_SYNTAX);
+ }
+};
+
+class CSList : public Module
+{
+public:
+ CSList(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ {
+ this->SetAuthor("Anope");
+ this->SetVersion("$Id$");
+ this->SetType(CORE);
+ this->AddCommand(CHANSERV, new CommandCSList(), MOD_UNIQUE);
+ this->SetChanHelp(myChanServHelp);
+ }
+};
MODULE_INIT("cs_list", CSList)