1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 (InspIRCd* Instance) : Command(Instance, "JUMPSERVER", "o", 0, 4)
32 this->source = "m_jumpserver.so";
33 syntax = "[<server> <port> <+/-an> <reason>]";
37 redirect_all_immediately = redirect_new_users = false;
40 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
43 reason = (parameters.size() < 4) ? "Please use this server/port instead" : parameters[3];
44 redirect_all_immediately = false;
45 redirect_new_users = true;
49 /* No parameters: jumpserver disabled */
50 if (!parameters.size())
53 user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick.c_str(), redirect_to.c_str(), port);
55 user->WriteServ("NOTICE %s :*** jumpserver was not enabled.", user->nick.c_str());
65 if (parameters.size() >= 3)
67 for (const char* n = parameters[2].c_str(); *n; n++)
78 redirect_all_immediately = direction;
81 redirect_new_users = direction;
84 user->WriteServ("NOTICE %s :*** Invalid JUMPSERVER flag: %c", user->nick.c_str(), *n);
90 if (!atoi(parameters[1].c_str()))
92 user->WriteServ("NOTICE %s :*** Invalid port number", user->nick.c_str());
96 if (redirect_all_immediately)
98 /* Redirect everyone but the oper sending the command */
99 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
104 t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
105 ServerInstance->Users->QuitUser(t, reason);
111 n_done_s = ConvToStr(n_done);
115 if (redirect_new_users)
117 redirect_to = parameters[0];
118 port = atoi(parameters[1].c_str());
121 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(),
122 redirect_all_immediately ? "a" : "",
123 redirect_new_users ? "n" : "",
125 n_done ? n_done_s.c_str() : "",
126 n_done ? " user(s) redirected)" : "",
130 return CMD_LOCALONLY;
135 class ModuleJumpServer : public Module
137 CommandJumpserver* js;
139 ModuleJumpServer(InspIRCd* Me)
143 js = new CommandJumpserver(ServerInstance);
144 ServerInstance->AddCommand(js);
145 Implementation eventlist[] = { I_OnUserRegister };
146 ServerInstance->Modules->Attach(eventlist, this, 1);
149 virtual ~ModuleJumpServer()
153 virtual int OnUserRegister(User* user)
155 if (js->port && js->redirect_new_users)
157 user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead", user->nick.c_str(), js->redirect_to.c_str(), js->port);
158 ServerInstance->Users->QuitUser(user, js->reason);
165 virtual Version GetVersion()
167 return Version("$Id$", VF_VENDOR, API_VERSION);
172 MODULE_INIT(ModuleJumpServer)