2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* $ModDesc: Provides support for the RPL_REDIR numeric */
26 /** Handle /JUMPSERVER
28 class CommandJumpserver : public Command
31 bool redirect_all_immediately;
32 bool redirect_new_users;
34 std::string redirect_to;
38 CommandJumpserver(Module* Creator) : Command(Creator, "JUMPSERVER", 0, 4)
40 flags_needed = 'o'; syntax = "[<server> <port> <+/-an> <reason>]";
44 redirect_all_immediately = redirect_new_users = false;
47 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
50 reason = (parameters.size() < 4) ? "Please use this server/port instead" : parameters[3];
51 redirect_all_immediately = false;
52 redirect_new_users = true;
56 /* No parameters: jumpserver disabled */
57 if (!parameters.size())
60 user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick.c_str(), redirect_to.c_str(), port);
62 user->WriteServ("NOTICE %s :*** jumpserver was not enabled.", user->nick.c_str());
72 if (parameters.size() >= 3)
74 for (const char* n = parameters[2].c_str(); *n; n++)
85 redirect_all_immediately = direction;
88 redirect_new_users = direction;
91 user->WriteServ("NOTICE %s :*** Invalid JUMPSERVER flag: %c", user->nick.c_str(), *n);
97 if (!atoi(parameters[1].c_str()))
99 user->WriteServ("NOTICE %s :*** Invalid port number", user->nick.c_str());
103 if (redirect_all_immediately)
105 /* Redirect everyone but the oper sending the command */
106 for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
111 t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
112 ServerInstance->Users->QuitUser(t, reason);
118 n_done_s = ConvToStr(n_done);
122 if (redirect_new_users)
124 redirect_to = parameters[0];
125 port = atoi(parameters[1].c_str());
128 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(),
129 redirect_all_immediately ? "a" : "",
130 redirect_new_users ? "n" : "",
132 n_done ? n_done_s.c_str() : "",
133 n_done ? " user(s) redirected)" : "",
142 class ModuleJumpServer : public Module
144 CommandJumpserver js;
146 ModuleJumpServer() : js(this)
148 ServerInstance->AddCommand(&js);
149 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash };
150 ServerInstance->Modules->Attach(eventlist, this, 2);
153 virtual ~ModuleJumpServer()
157 virtual ModResult OnUserRegister(LocalUser* user)
159 if (js.port && js.redirect_new_users)
161 user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead",
162 user->nick.c_str(), js.redirect_to.c_str(), js.port);
163 ServerInstance->Users->QuitUser(user, js.reason);
164 return MOD_RES_PASSTHRU;
166 return MOD_RES_PASSTHRU;
169 virtual void OnRehash(User* user)
171 // Emergency way to unlock
172 if (!user) js.redirect_new_users = false;
175 virtual Version GetVersion()
177 return Version("Provides support for the RPL_REDIR numeric", VF_VENDOR);
182 MODULE_INIT(ModuleJumpServer)