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 and the /JUMPSERVER command. */
26 /** Handle /JUMPSERVER
28 class CommandJumpserver : public Command
31 bool redirect_new_users;
32 std::string redirect_to;
36 CommandJumpserver(Module* Creator) : Command(Creator, "JUMPSERVER", 0, 4)
38 flags_needed = 'o'; syntax = "[<server> <port> <+/-an> <reason>]";
40 redirect_new_users = false;
43 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
46 reason = (parameters.size() < 4) ? "Please use this server/port instead" : parameters[3];
47 bool redirect_all_immediately = false;
48 redirect_new_users = true;
49 bool direction = true;
52 /* No parameters: jumpserver disabled */
53 if (!parameters.size())
56 user->WriteNotice("*** Disabled jumpserver (previously set to '" + redirect_to + ":" + ConvToStr(port) + "')");
58 user->WriteNotice("*** Jumpserver was not enabled.");
68 if (parameters.size() >= 3)
70 for (std::string::const_iterator n = parameters[2].begin(); n != parameters[2].end(); ++n)
81 redirect_all_immediately = direction;
84 redirect_new_users = direction;
87 user->WriteNotice("*** Invalid JUMPSERVER flag: " + ConvToStr(*n));
93 if (!atoi(parameters[1].c_str()))
95 user->WriteNotice("*** Invalid port number");
99 if (redirect_all_immediately)
101 /* Redirect everyone but the oper sending the command */
102 for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); ++i)
107 t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", t->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
108 ServerInstance->Users->QuitUser(t, reason);
114 n_done_s = ConvToStr(n_done);
118 if (redirect_new_users)
120 redirect_to = parameters[0];
121 port = atoi(parameters[1].c_str());
124 user->WriteNotice("*** Set jumpserver to server '" + parameters[0] + "' port '" + parameters[1] + "', flags '+" +
125 (redirect_all_immediately ? "a" : "") + (redirect_new_users ? "n'" : "'") +
126 (n_done ? " (" + n_done_s + "user(s) redirected): " : ": ") + reason);
133 class ModuleJumpServer : public Module
135 CommandJumpserver js;
137 ModuleJumpServer() : js(this)
143 ServerInstance->Modules->AddService(js);
144 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash };
145 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
148 virtual ModResult OnUserRegister(LocalUser* user)
150 if (js.port && js.redirect_new_users)
152 user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead",
153 user->nick.c_str(), js.redirect_to.c_str(), js.port);
154 ServerInstance->Users->QuitUser(user, js.reason);
155 return MOD_RES_PASSTHRU;
157 return MOD_RES_PASSTHRU;
160 virtual void OnRehash(User* user)
162 // Emergency way to unlock
163 if (!user) js.redirect_new_users = false;
166 virtual Version GetVersion()
168 return Version("Provides support for the RPL_REDIR numeric and the /JUMPSERVER command.", VF_VENDOR);
172 MODULE_INIT(ModuleJumpServer)