diff options
author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-02-09 22:53:42 +0000 |
---|---|---|
committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-02-09 22:53:42 +0000 |
commit | de6a85bdf5b329d16c666d873122b1d76a6ac0df (patch) | |
tree | 43eeac1e788267293632fe0a67ce7b14b8722b31 /src | |
parent | 0ab457110638876994dd0fc116b16ca62bb2abd6 (diff) |
Changed cs_suspend to use new command API.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1963 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r-- | src/core/cs_suspend.c | 310 |
1 files changed, 170 insertions, 140 deletions
diff --git a/src/core/cs_suspend.c b/src/core/cs_suspend.c index 23089d90c..1cee2f9bc 100644 --- a/src/core/cs_suspend.c +++ b/src/core/cs_suspend.c @@ -15,184 +15,214 @@ #include "module.h" -int do_suspend(User * u); -int do_unsuspend(User * u); -void myChanServHelp(User * u); +void myChanServHelp(User *u); -class CSSuspend : public Module +class CommandCSSuspend : public Command { public: - CSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator) + CommandCSSuspend() : Command("SUSPEND", 1, 2) { - Command *c; + } - this->SetAuthor("Anope"); - this->SetVersion("$Id$"); - this->SetType(CORE); + CommandResult Execute(User *u, std::vector<std::string> ¶ms) + { + ChannelInfo *ci; + char *chan = params[0].c_str(); + char *reason = params.size() > 1 ? params[1].c_str() : NULL; - c = createCommand("SUSPEND", do_suspend, is_services_oper, -1, -1, -1, CHAN_SERVADMIN_HELP_SUSPEND, CHAN_SERVADMIN_HELP_SUSPEND); - this->AddCommand(CHANSERV, c, MOD_UNIQUE); - c = createCommand("UNSUSPEND", do_unsuspend, is_services_oper, -1, -1, -1, CHAN_SERVADMIN_HELP_UNSUSPEND, CHAN_SERVADMIN_HELP_UNSUSPEND); - this->AddCommand(CHANSERV, c, MOD_UNIQUE); + Channel *c; - this->SetChanHelp(myChanServHelp); - } -}; + /* Assumes that permission checking has already been done. */ + if (ForceForbidReason && !reason) + { + this->OnSyntaxError(u); + return MOD_CONT; + } + if (chan[0] != '#') + { + notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); + return MOD_CONT; + } -/** - * Add the help response to anopes /cs help output. - * @param u The user who is requesting help - **/ -void myChanServHelp(User * u) -{ - if (is_services_oper(u)) { - notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SUSPEND); - notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNSUSPEND); - } -} + /* Only SUSPEND existing channels, otherwise use FORBID (bug #54) */ + if (!(ci = cs_findchan(chan))) + { + notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); + return MOD_CONT; + } -/** - * The /cs (un)suspend command. - * @param u The user who issued the command - * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. - **/ -int do_suspend(User * u) -{ - ChannelInfo *ci; - char *chan = strtok(NULL, " "); - char *reason = strtok(NULL, ""); + /* You should not SUSPEND a FORBIDEN channel */ + if (ci->flags & CI_VERBOTEN) + { + notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan); + return MOD_CONT; + } - Channel *c; + if (readonly) + notice_lang(s_ChanServ, u, READ_ONLY_MODE); - /* Assumes that permission checking has already been done. */ - if (!chan || (ForceForbidReason && !reason)) { - syntax_error(s_ChanServ, u, "SUSPEND", - (ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON : - CHAN_SUSPEND_SYNTAX)); - return MOD_CONT; - } + if (ci) + { + ci->flags |= CI_SUSPENDED; + ci->forbidby = sstrdup(u->nick); + if (reason) + ci->forbidreason = sstrdup(reason); + + if ((c = findchan(ci->name))) + { + struct c_userlist *cu, *next; + const char *av[3]; + + for (cu = c->users; cu; cu = next) + { + next = cu->next; + + if (is_oper(cu->user)) + continue; + + av[0] = c->name; + av[1] = cu->user->nick; + av[2] = reason ? reason : "CHAN_SUSPEND_REASON"; + ircdproto->SendKick(findbot(s_ChanServ), av[0], av[1], av[2]); + do_kick(s_ChanServ, 3, av); + } + } - if (chan[0] != '#') { - notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); - return MOD_CONT; - } + if (WallForbid) + ircdproto->SendGlobops(s_ChanServ, "\2%s\2 used SUSPEND on channel \2%s\2", u->nick, ci->name); - /* Only SUSPEND existing channels, otherwise use FORBID (bug #54) */ - if ((ci = cs_findchan(chan)) == NULL) { - notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); + alog("%s: %s set SUSPEND for channel %s", s_ChanServ, u->nick, ci->name); + notice_lang(s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan); + send_event(EVENT_CHAN_SUSPENDED, 1, chan); + } + else + { + alog("%s: Valid SUSPEND for %s by %s failed", s_ChanServ, ci->name, u->nick); + notice_lang(s_ChanServ, u, CHAN_SUSPEND_FAILED, chan); + } return MOD_CONT; } - /* You should not SUSPEND a FORBIDEN channel */ - if (ci->flags & CI_VERBOTEN) { - notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan); - return MOD_CONT; - } + bool OnHelp(User *u, const std::string &subcommand) + { + if (!is_services_oper(u)) + return false; - if (readonly) - notice_lang(s_ChanServ, u, READ_ONLY_MODE); + notice_lang(s_ChanServ, u, CHAN_SERVADMIN_HELP_SUSPEND); + return true; + } - if (ci) { - ci->flags |= CI_SUSPENDED; - ci->forbidby = sstrdup(u->nick); - if (reason) - ci->forbidreason = sstrdup(reason); + void OnSyntaxError(User *u) + { + syntax_error(s_ChanServ, u, "SUSPEND", ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON : CHAN_SUSPEND_SYNTAX); + } +}; - if ((c = findchan(ci->name))) { - struct c_userlist *cu, *next; - const char *av[3]; +class CommandCSUnSuspend : public Command +{ + public: + CommandCSUnSuspend() : Command("UNSUSPEND", 1, 1) + { + } - for (cu = c->users; cu; cu = next) { - next = cu->next; + CommandResult Execute(User *u, std::vector<std::string> ¶ms) + { + ChannelInfo *ci; + const char *chan = params[0].c_str(); - if (is_oper(cu->user)) - continue; + if (chan[0] != '#') + { + notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); + return MOD_CONT; + } + if (readonly) + notice_lang(s_ChanServ, u, READ_ONLY_MODE); - av[0] = c->name; - av[1] = cu->user->nick; - av[2] = reason ? reason : "CHAN_SUSPEND_REASON"; - ircdproto->SendKick(findbot(s_ChanServ), av[0], av[1], av[2]); - do_kick(s_ChanServ, 3, av); - } + /* Only UNSUSPEND already suspended channels */ + if (!(ci = cs_findchan(chan))) + { + notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); + return MOD_CONT; } - if (WallForbid) - ircdproto->SendGlobops(s_ChanServ, - "\2%s\2 used SUSPEND on channel \2%s\2", - u->nick, ci->name); - - alog("%s: %s set SUSPEND for channel %s", s_ChanServ, u->nick, - ci->name); - notice_lang(s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan); - send_event(EVENT_CHAN_SUSPENDED, 1, chan); - } else { - alog("%s: Valid SUSPEND for %s by %s failed", s_ChanServ, ci->name, - u->nick); - notice_lang(s_ChanServ, u, CHAN_SUSPEND_FAILED, chan); - } - return MOD_CONT; -} + if (!(ci->flags & CI_SUSPENDED)) + { + notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); + return MOD_CONT; + } -/*************************************************************************/ + if (ci) + { + ci->flags &= ~CI_SUSPENDED; + if (ci->forbidreason) + { + delete [] ci->forbidreason; + ci->forbidreason = NULL; + } + if (ci->forbidby) + { + delete [] ci->forbidby; + ci->forbidby = NULL; + } -int do_unsuspend(User * u) -{ - ChannelInfo *ci; - char *chan = strtok(NULL, " "); + if (WallForbid) + ircdproto->SendGlobops(s_ChanServ, "\2%s\2 used UNSUSPEND on channel \2%s\2", u->nick, ci->name); - /* Assumes that permission checking has already been done. */ - if (!chan) { - syntax_error(s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX); - return MOD_CONT; - } - if (chan[0] != '#') { - notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); + alog("%s: %s set UNSUSPEND for channel %s", s_ChanServ, u->nick, ci->name); + notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan); + send_event(EVENT_CHAN_UNSUSPEND, 1, chan); + } + else + { + alog("%s: Valid UNSUSPEND for %s by %s failed", s_ChanServ, chan, u->nick); + notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); + } return MOD_CONT; } - if (readonly) - notice_lang(s_ChanServ, u, READ_ONLY_MODE); - /* Only UNSUSPEND already suspended channels */ - if ((ci = cs_findchan(chan)) == NULL) { - notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); - return MOD_CONT; + bool OnHelp(User *u, const std::string &subcommand) + { + if (!is_services_oper(u)) + return false; + + notice_lang(s_ChanServ, u, CHAN_SERVADMIN_HELP_UNSUSPEND); + return true; } - if (!(ci->flags & CI_SUSPENDED)) + void OnSyntaxError(User *u) { - notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); - return MOD_CONT; + syntax_error(s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX); } +}; - if (ci) { - ci->flags &= ~CI_SUSPENDED; - if (ci->forbidreason) - { - delete [] ci->forbidreason; - ci->forbidreason = NULL; - } - if (ci->forbidby) - { - delete [] ci->forbidby; - ci->forbidby = NULL; - } +class CSSuspend : public Module +{ + public: + CSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetVersion("$Id$"); + this->SetType(CORE); + + this->AddCommand(CHANSERV, new CommandCSSuspend(), MOD_UNIQUE); + this->AddCommand(CHANSERV, new CommandCSUnSuspend(), MOD_UNIQUE); - if (WallForbid) - ircdproto->SendGlobops(s_ChanServ, - "\2%s\2 used UNSUSPEND on channel \2%s\2", - u->nick, ci->name); - - alog("%s: %s set UNSUSPEND for channel %s", s_ChanServ, u->nick, - ci->name); - notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan); - send_event(EVENT_CHAN_UNSUSPEND, 1, chan); - } else { - alog("%s: Valid UNSUSPEND for %s by %s failed", s_ChanServ, - chan, u->nick); - notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); + this->SetChanHelp(myChanServHelp); + } +}; + +/** + * Add the help response to anopes /cs help output. + * @param u The user who is requesting help + **/ +void myChanServHelp(User *u) +{ + if (is_services_oper(u)) + { + notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SUSPEND); + notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNSUSPEND); } - return MOD_CONT; } MODULE_INIT("cs_suspend", CSSuspend) |