1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for the RPL_REDIR numeric */
18 /** Handle /JUMPSERVER
20 class CommandJumpserver : public Command
23 bool redirect_all_immediately;
24 bool redirect_new_users;
26 std::string redirect_to;
30 CommandJumpserver(Module* Creator) : Command(Creator, "JUMPSERVER", 0, 4)
32 flags_needed = 'o'; syntax = "[<server> <port> <+/-an> <reason>]";
36 redirect_all_immediately = redirect_new_users = false;
39 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
42 reason = (parameters.size() < 4) ? "Please use this server/port instead" : parameters[3];
43 redirect_all_immediately = false;
44 redirect_new_users = true;
48 /* No parameters: jumpserver disabled */
49 if (!parameters.size())
52 user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick.c_str(), redirect_to.c_str(), port);
54 user->WriteServ("NOTICE %s :*** jumpserver was not enabled.", user->nick.c_str());
64 if (parameters.size() >= 3)
66 for (const char* n = parameters[2].c_str(); *n; n++)
77 redirect_all_immediately = direction;
80 redirect_new_users = direction;
83 user->WriteServ("NOTICE %s :*** Invalid JUMPSERVER flag: %c", user->nick.c_str(), *n);
89 if (!atoi(parameters[1].c_str()))
91 user->WriteServ("NOTICE %s :*** Invalid port number", user->nick.c_str());
95 if (redirect_all_immediately)
97 /* Redirect everyone but the oper sending the command */
98 for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
103 t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
104 ServerInstance->Users->QuitUser(t, reason);
110 n_done_s = ConvToStr(n_done);
114 if (redirect_new_users)
116 redirect_to = parameters[0];
117 port = atoi(parameters[1].c_str());
120 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(),
121 redirect_all_immediately ? "a" : "",
122 redirect_new_users ? "n" : "",
124 n_done ? n_done_s.c_str() : "",
125 n_done ? " user(s) redirected)" : "",
134 class ModuleJumpServer : public Module
136 CommandJumpserver js;
138 ModuleJumpServer() : js(this)
140 ServerInstance->AddCommand(&js);
141 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash };
142 ServerInstance->Modules->Attach(eventlist, this, 2);
145 virtual ~ModuleJumpServer()
149 virtual ModResult OnUserRegister(LocalUser* user)
151 if (js.port && js.redirect_new_users)
153 user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead",
154 user->nick.c_str(), js.redirect_to.c_str(), js.port);
155 ServerInstance->Users->QuitUser(user, js.reason);
156 return MOD_RES_PASSTHRU;
158 return MOD_RES_PASSTHRU;
161 virtual void OnRehash(User* user)
163 // Emergency way to unlock
164 if (!user) js.redirect_new_users = false;
167 virtual Version GetVersion()
169 return Version("Provides support for the RPL_REDIR numeric", VF_VENDOR);
174 MODULE_INIT(ModuleJumpServer)