m_conn_umodes.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
00018 class ModuleModesOnConnect : public Module
00019 {
00020 private:
00021
00022 ConfigReader *Conf;
00023
00024 public:
00025 ModuleModesOnConnect(InspIRCd* Me) : Module(Me)
00026 {
00027
00028 Conf = new ConfigReader(ServerInstance);
00029 Implementation eventlist[] = { I_OnUserConnect, I_OnRehash };
00030 ServerInstance->Modules->Attach(eventlist, this, 2);
00031
00032 ServerInstance->Modules->SetPriority(this, PRIO_FIRST);
00033 }
00034
00035
00036 virtual void OnRehash(User* user, const std::string ¶meter)
00037 {
00038 delete Conf;
00039 Conf = new ConfigReader(ServerInstance);
00040 }
00041
00042 virtual ~ModuleModesOnConnect()
00043 {
00044 delete Conf;
00045 }
00046
00047 virtual Version GetVersion()
00048 {
00049 return Version("$Id: m_conn_umodes.cpp 10497 2008-09-10 19:44:21Z w00t $", VF_VENDOR,API_VERSION);
00050 }
00051
00052 virtual void OnUserConnect(User* user)
00053 {
00054 if (!IS_LOCAL(user))
00055 return;
00056
00057
00058 char save[64];
00059 memcpy(save, ServerInstance->Config->DisabledUModes,
00060 sizeof(ServerInstance->Config->DisabledUModes));
00061 memset(ServerInstance->Config->DisabledUModes, 0, 64);
00062
00063 for (int j = 0; j < Conf->Enumerate("connect"); j++)
00064 {
00065 std::string hostn = Conf->ReadValue("connect","allow",j);
00066
00067 if ((InspIRCd::MatchCIDR(user->GetIPString(),hostn)) || (InspIRCd::Match(user->host,hostn)))
00068 {
00069 std::string ThisModes = Conf->ReadValue("connect","modes",j);
00070 if (!ThisModes.empty())
00071 {
00072 std::string buf;
00073 std::stringstream ss(ThisModes);
00074
00075 std::vector<std::string> tokens;
00076
00077
00078 while (ss >> buf)
00079 tokens.push_back(buf);
00080
00081 std::vector<std::string> modes;
00082 modes.push_back(user->nick);
00083 modes.push_back(tokens[0]);
00084
00085 if (tokens.size() > 1)
00086 {
00087
00088 for (unsigned int k = 1; k < tokens.size(); k++)
00089 {
00090 modes.push_back(tokens[k]);
00091 }
00092 }
00093
00094 ServerInstance->Parser->CallHandler("MODE", modes, user);
00095 }
00096 break;
00097 }
00098 }
00099
00100 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
00101 }
00102 };
00103
00104 MODULE_INIT(ModuleModesOnConnect)