X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_jumpserver.cpp;h=d8492fd5e2aeda292c7b1308dbac241ec0315f8f;hb=1c1c5fc3f01c42a09d34594989679bbc8fb21c0d;hp=0bb198a4d0e3aa5dee8b254f204a2a9f984f734a;hpb=b03f6ce251aa3a64a2351bdb39aed4751824b7dc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_jumpserver.cpp b/src/modules/m_jumpserver.cpp index 0bb198a4d..d8492fd5e 100644 --- a/src/modules/m_jumpserver.cpp +++ b/src/modules/m_jumpserver.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -13,9 +13,9 @@ #include "inspircd.h" -/* $ModDesc: Provides support for unreal-style SAPART command */ +/* $ModDesc: Provides support for the RPL_REDIR numeric */ -/** Handle /SAPART +/** Handle /JUMPSERVER */ class CommandJumpserver : public Command { @@ -27,10 +27,9 @@ class CommandJumpserver : public Command std::string reason; int port; - CommandJumpserver (InspIRCd* Instance) : Command(Instance, "JUMPSERVER", "o", 0) + CommandJumpserver (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "JUMPSERVER", "o", 0, 4) { - this->source = "m_jumpserver.so"; - syntax = "[ <+/-a> :]"; + syntax = "[ <+/-an> ]"; redirect_to.clear(); reason.clear(); port = 0; @@ -56,104 +55,116 @@ class CommandJumpserver : public Command port = 0; redirect_to.clear(); - return CMD_LOCALONLY; + return CMD_SUCCESS; } port = 0; redirect_to.clear(); - for (const char* n = parameters[2].c_str(); *n; n++) + if (parameters.size() >= 3) { - switch (*n) + for (const char* n = parameters[2].c_str(); *n; n++) { - case '+': - direction = true; - break; - case '-': - direction = false; - break; - case 'a': - redirect_all_immediately = direction; - break; - case 'n': - redirect_new_users = direction; - break; + switch (*n) + { + case '+': + direction = true; + break; + case '-': + direction = false; + break; + case 'a': + redirect_all_immediately = direction; + break; + case 'n': + redirect_new_users = direction; + break; + default: + user->WriteServ("NOTICE %s :*** Invalid JUMPSERVER flag: %c", user->nick.c_str(), *n); + return CMD_FAILURE; + break; + } } - } - if (redirect_all_immediately) - { - /* Redirect everyone but the oper sending the command */ - for (std::vector::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) + if (!atoi(parameters[1].c_str())) { - User* t = *i; - if (!IS_OPER(t)) + user->WriteServ("NOTICE %s :*** Invalid port number", user->nick.c_str()); + return CMD_FAILURE; + } + + if (redirect_all_immediately) + { + /* Redirect everyone but the oper sending the command */ + for (std::vector::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) { - t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str()); - ServerInstance->Users->QuitUser(t, reason); - n_done++; + User* t = *i; + if (!IS_OPER(t)) + { + t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str()); + ServerInstance->Users->QuitUser(t, reason); + n_done++; + } + } + if (n_done) + { + n_done_s = ConvToStr(n_done); } } - if (n_done) + + if (redirect_new_users) { - n_done_s = ConvToStr(n_done); + redirect_to = parameters[0]; + port = atoi(parameters[1].c_str()); } - } - if (redirect_new_users) - { - redirect_to = parameters[0]; - port = atoi(parameters[1].c_str()); + user->WriteServ("NOTICE %s :*** Set jumpserver to server '%s' port '%s', flags '+%s%s'%s%s%s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str(), + redirect_all_immediately ? "a" : "", + redirect_new_users ? "n" : "", + n_done ? " (" : "", + n_done ? n_done_s.c_str() : "", + n_done ? " user(s) redirected)" : "", + reason.c_str()); } - user->WriteServ("NOTICE %s :*** Set jumpserver to server '%s' port '%s', flags '+%s%s'%s%s%s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str(), - redirect_all_immediately ? "a" : "", - redirect_new_users ? "n" : "", - n_done ? " (" : "", - n_done ? n_done_s.c_str() : "", - n_done ? " user(s) redirected)" : "", - reason.c_str()); - - return CMD_LOCALONLY; + return CMD_SUCCESS; } }; class ModuleJumpServer : public Module { - CommandJumpserver* js; + CommandJumpserver js; public: ModuleJumpServer(InspIRCd* Me) - : Module(Me) + : Module(Me), js(Me, this) { - - js = new CommandJumpserver(ServerInstance); - ServerInstance->AddCommand(js); + ServerInstance->AddCommand(&js); Implementation eventlist[] = { I_OnUserRegister }; ServerInstance->Modules->Attach(eventlist, this, 1); } - + virtual ~ModuleJumpServer() { } - virtual int OnUserRegister(User* user) + virtual ModResult OnUserRegister(User* user) { - if (js->port && js->redirect_new_users) + if (js.port && js.redirect_new_users) { - user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead", user->nick.c_str(), js->redirect_to.c_str(), js->port); - ServerInstance->Users->QuitUser(user, js->reason); - return 0; + user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead", + user->nick.c_str(), js.redirect_to.c_str(), js.port); + ServerInstance->Users->QuitUser(user, js.reason); + return MOD_RES_PASSTHRU; } - return 0; + return MOD_RES_PASSTHRU; } virtual Version GetVersion() { - return Version(1,2,0,1,VF_VENDOR,API_VERSION); + return Version("$Id$", VF_VENDOR, API_VERSION); } - + }; MODULE_INIT(ModuleJumpServer)