m_jumpserver.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00020 class CommandJumpserver : public Command
00021 {
00022 public:
00023 bool redirect_all_immediately;
00024 bool redirect_new_users;
00025 bool direction;
00026 std::string redirect_to;
00027 std::string reason;
00028 int port;
00029
00030 CommandJumpserver (InspIRCd* Instance) : Command(Instance, "JUMPSERVER", "o", 0)
00031 {
00032 this->source = "m_jumpserver.so";
00033 syntax = "[<server> <port> <+/-a> :<reason>]";
00034 redirect_to.clear();
00035 reason.clear();
00036 port = 0;
00037 redirect_all_immediately = redirect_new_users = false;
00038 }
00039
00040 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
00041 {
00042 int n_done = 0;
00043 reason = (parameters.size() < 4) ? "Please use this server/port instead" : parameters[3];
00044 redirect_all_immediately = false;
00045 redirect_new_users = true;
00046 direction = true;
00047 std::string n_done_s;
00048
00049
00050 if (!parameters.size())
00051 {
00052 if (port)
00053 user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick.c_str(), redirect_to.c_str(), port);
00054 else
00055 user->WriteServ("NOTICE %s :*** jumpserver was not enabled.", user->nick.c_str());
00056
00057 port = 0;
00058 redirect_to.clear();
00059 return CMD_LOCALONLY;
00060 }
00061
00062 port = 0;
00063 redirect_to.clear();
00064
00065 if (parameters.size() >= 3)
00066 {
00067 for (const char* n = parameters[2].c_str(); *n; n++)
00068 {
00069 switch (*n)
00070 {
00071 case '+':
00072 direction = true;
00073 break;
00074 case '-':
00075 direction = false;
00076 break;
00077 case 'a':
00078 redirect_all_immediately = direction;
00079 break;
00080 case 'n':
00081 redirect_new_users = direction;
00082 break;
00083 }
00084 }
00085
00086 if (redirect_all_immediately)
00087 {
00088
00089 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
00090 {
00091 User* t = *i;
00092 if (!IS_OPER(t))
00093 {
00094 t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
00095 ServerInstance->Users->QuitUser(t, reason);
00096 n_done++;
00097 }
00098 }
00099 if (n_done)
00100 {
00101 n_done_s = ConvToStr(n_done);
00102 }
00103 }
00104
00105 if (redirect_new_users)
00106 {
00107 redirect_to = parameters[0];
00108 port = atoi(parameters[1].c_str());
00109 }
00110
00111 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(),
00112 redirect_all_immediately ? "a" : "",
00113 redirect_new_users ? "n" : "",
00114 n_done ? " (" : "",
00115 n_done ? n_done_s.c_str() : "",
00116 n_done ? " user(s) redirected)" : "",
00117 reason.c_str());
00118 }
00119
00120 return CMD_LOCALONLY;
00121 }
00122 };
00123
00124
00125 class ModuleJumpServer : public Module
00126 {
00127 CommandJumpserver* js;
00128 public:
00129 ModuleJumpServer(InspIRCd* Me)
00130 : Module(Me)
00131 {
00132
00133 js = new CommandJumpserver(ServerInstance);
00134 ServerInstance->AddCommand(js);
00135 Implementation eventlist[] = { I_OnUserRegister };
00136 ServerInstance->Modules->Attach(eventlist, this, 1);
00137 }
00138
00139 virtual ~ModuleJumpServer()
00140 {
00141 }
00142
00143 virtual int OnUserRegister(User* user)
00144 {
00145 if (js->port && js->redirect_new_users)
00146 {
00147 user->WriteNumeric(10, "%s %s %d :Please use this Server/Port instead", user->nick.c_str(), js->redirect_to.c_str(), js->port);
00148 ServerInstance->Users->QuitUser(user, js->reason);
00149 return 0;
00150 }
00151 return 0;
00152 }
00153
00154
00155 virtual Version GetVersion()
00156 {
00157 return Version("$Id: m_jumpserver.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR, API_VERSION);
00158 }
00159
00160 };
00161
00162 MODULE_INIT(ModuleJumpServer)