From d7d01bdc5c667a1fafd95241282b58e03b4caa5b Mon Sep 17 00:00:00 2001 From: rburchell Date: Mon, 9 Feb 2009 21:01:05 +0000 Subject: Squashed commit: merge next (1.9.1) back to trunk. SVN users, NOTE: THIS WILL NOT BUILD, NOR SHOULD YOU RUN IT YET. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1953 5417fbe8-f217-4b02-8779-1006273d7864 --- src/core/hs_setall.c | 255 +++++++++++++++++++++++++++------------------------ 1 file changed, 135 insertions(+), 120 deletions(-) (limited to 'src/core/hs_setall.c') diff --git a/src/core/hs_setall.c b/src/core/hs_setall.c index 39605fd24..2124deda2 100644 --- a/src/core/hs_setall.c +++ b/src/core/hs_setall.c @@ -15,104 +15,125 @@ #include "module.h" -int do_setall(User * u); -void myHostServHelp(User * u); -extern int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, - char *creator, time_t time); +void myHostServHelp(User *u); +extern int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time); -class HSSetAll : public Module +class CommandHSSetAll : public Command { public: - HSSetAll(const std::string &modname, const std::string &creator) : Module(modname, creator) + CommandHSSetAll() : Command("SETALL", 2, 2) { - Command *c; - - this->SetAuthor("Anope"); - this->SetVersion("$Id$"); - this->SetType(CORE); - - c = createCommand("SETALL", do_setall, is_host_setter, HOST_HELP_SETALL, -1, -1, -1, -1); - this->AddCommand(HOSTSERV, c, MOD_UNIQUE); - this->SetHostHelp(myHostServHelp); } -}; - - - -/** - * Add the help response to anopes /hs help output. - * @param u The user who is requesting help - **/ -void myHostServHelp(User * u) -{ - if (is_host_setter(u)) { - notice_lang(s_HostServ, u, HOST_HELP_CMD_SETALL); - } -} - -/** - * The /hs setall command. - * @param u The user who issued the command - * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. - **/ -int do_setall(User * u) -{ - char *nick = strtok(NULL, " "); - char *rawhostmask = strtok(NULL, " "); - char *hostmask = new char[HOSTMAX]; - - NickAlias *na; - int32 tmp_time; - char *s; - char *vIdent = NULL; - - if (!nick || !rawhostmask) { - notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ); - delete [] hostmask; - return MOD_CONT; - } + CommandResult Execute(User *u, std::vector ¶ms) + { + const char *nick = params[0].c_str(); + const char *rawhostmask = params[1].c_str(); + char *hostmask = new char[HOSTMAX]; + + NickAlias *na; + int32 tmp_time; + char *s; + + char *vIdent = NULL; + + vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ + if (vIdent) + { + rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ + if (!rawhostmask) + { + notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ); + delete [] vIdent; + delete [] hostmask; + return MOD_CONT; + } + if (strlen(vIdent) > USERMAX - 1) + { + notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + else + { + for (s = vIdent; *s; ++s) + { + if (!isvalidchar(*s)) + { + notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + } + } + if (!ircd->vident) + { + notice_lang(s_HostServ, u, HOST_NO_VIDENT); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + } - vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ - if (vIdent) { - rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ - if (!rawhostmask) { - notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ); - delete [] vIdent; + if (strlen(rawhostmask) < HOSTMAX - 1) + snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); + else + { + notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } delete [] hostmask; return MOD_CONT; } - if (strlen(vIdent) > USERMAX - 1) { - notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); - delete [] vIdent; - delete [] rawhostmask; + + if (!isValidHost(hostmask, 3)) + { + notice_lang(s_HostServ, u, HOST_SET_ERROR); + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } delete [] hostmask; return MOD_CONT; - } else { - for (s = vIdent; *s; s++) { - if (!isvalidchar(*s)) { - notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR); + } + + tmp_time = time(NULL); + + if ((na = findnick(nick))) + { + if (na->status & NS_VERBOTEN) + { + notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick); + if (vIdent) { delete [] vIdent; delete [] rawhostmask; - delete [] hostmask; - return MOD_CONT; } + delete [] hostmask; + return MOD_CONT; } + if (vIdent && ircd->vident) + alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick); + else + alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); + do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time); + if (vIdent) + notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask); + else + notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask); } - if (!ircd->vident) { - notice_lang(s_HostServ, u, HOST_NO_VIDENT); - delete [] vIdent; - delete [] rawhostmask; - delete [] hostmask; - return MOD_CONT; - } - } - - if (strlen(rawhostmask) < HOSTMAX - 1) - snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); - else { - notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); - if (vIdent) { + else + notice_lang(s_HostServ, u, HOST_NOREG, nick); + if (vIdent) + { delete [] vIdent; delete [] rawhostmask; } @@ -120,49 +141,43 @@ int do_setall(User * u) return MOD_CONT; } - if (!isValidHost(hostmask, 3)) { - notice_lang(s_HostServ, u, HOST_SET_ERROR); - if (vIdent) { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; - return MOD_CONT; - } + bool OnHelp(User *u, const std::string &subcommand) + { + if (!is_host_setter(u)) + return false; - tmp_time = time(NULL); + notice_lang(s_HostServ, u, HOST_HELP_SETALL); + return true; + } - if ((na = findnick(nick))) { - if (na->status & NS_VERBOTEN) { - notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick); - if (vIdent) { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; - return MOD_CONT; - } - if (vIdent && ircd->vident) { - alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick); - } else { - alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); - } - do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time); - if (vIdent) { - notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, - hostmask); - } else { - notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask); - } - } else { - notice_lang(s_HostServ, u, HOST_NOREG, nick); + void OnSyntaxError(User *u) + { + syntax_error(s_HostServ, u, "SETALL", HOST_SETALL_SYNTAX, s_HostServ); } - if (vIdent) { - delete [] vIdent; - delete [] rawhostmask; +}; + +class HSSetAll : public Module +{ + public: + HSSetAll(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetVersion("$Id$"); + this->SetType(CORE); + + this->AddCommand(HOSTSERV, new CommandHSSetAll(), MOD_UNIQUE); + this->SetHostHelp(myHostServHelp); } - delete [] hostmask; - return MOD_CONT; +}; + +/** + * Add the help response to anopes /hs help output. + * @param u The user who is requesting help + **/ +void myHostServHelp(User *u) +{ + if (is_host_setter(u)) + notice_lang(s_HostServ, u, HOST_HELP_CMD_SETALL); } MODULE_INIT("hs_setall", HSSetAll) -- cgit