1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
21 /* $ModDesc: Provides support for unreal-style SAPART command */
25 class cmd_jumpserver : public command_t
28 bool redirect_all_immediately;
29 bool redirect_new_users;
31 std::string redirect_to;
35 cmd_jumpserver (InspIRCd* Instance) : command_t(Instance, "JUMPSERVER", 'o', 0)
37 this->source = "m_jumpserver.so";
38 syntax = "[<server> <port> <+/-a> :<reason>]";
39 redirect_to = reason = "";
41 redirect_all_immediately = redirect_new_users = false;
44 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
47 reason = (pcnt < 4) ? "Please use this server/port instead" : parameters[3];
48 redirect_all_immediately = false;
49 redirect_new_users = true;
53 /* No parameters: jumpserver disabled */
57 user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick, redirect_to.c_str(), port);
59 user->WriteServ("NOTICE %s :*** jumpserver was not enabled.", user->nick);
69 for (const char* n = parameters[2]; *n; n++)
80 redirect_all_immediately = direction;
83 redirect_new_users = direction;
88 if (redirect_all_immediately)
90 /* Redirect everyone but the oper sending the command */
91 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
96 t->WriteServ("010 %s %s %s :Please use this Server/Port instead", user->nick, parameters[0], parameters[1]);
97 userrec::QuitUser(ServerInstance, t, reason);
103 n_done_s = ConvToStr(n_done);
107 if (redirect_new_users)
109 redirect_to = parameters[0];
110 port = atoi(parameters[1]);
113 user->WriteServ("NOTICE %s :*** Set jumpserver to server '%s' port '%s', flags '+%s%s'%s%s%s: %s", user->nick, parameters[0], parameters[1],
114 redirect_all_immediately ? "a" : "",
115 redirect_new_users ? "n" : "",
117 n_done ? n_done_s.c_str() : "",
118 n_done ? " user(s) redirected)" : "",
121 return CMD_LOCALONLY;
126 class ModuleJumpServer : public Module
130 ModuleJumpServer(InspIRCd* Me)
134 js = new cmd_jumpserver(ServerInstance);
135 ServerInstance->AddCommand(js);
138 virtual ~ModuleJumpServer()
142 virtual int OnUserRegister(userrec* user)
144 if (js->port && js->redirect_new_users)
146 user->WriteServ("010 %s %s %d :Please use this Server/Port instead", user->nick, js->redirect_to.c_str(), js->port);
147 userrec::QuitUser(ServerInstance, user, js->reason);
153 virtual void Implements(char* List)
155 List[I_OnUserRegister] = 1;
158 virtual Version GetVersion()
160 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
165 class ModuleJumpServerFactory : public ModuleFactory
168 ModuleJumpServerFactory()
172 ~ModuleJumpServerFactory()
176 virtual Module * CreateModule(InspIRCd* Me)
178 return new ModuleJumpServer(Me);
184 extern "C" DllExport void * init_module( void )
186 return new ModuleJumpServerFactory;