1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 /* $ModDesc: Sets (and unsets) modes on users when they connect */
22 class ModuleModesOnConnect : public Module
29 ModuleModesOnConnect(InspIRCd* Me)
33 Conf = new ConfigReader(ServerInstance);
36 void Implements(char* List)
38 List[I_OnPostConnect] = List[I_OnRehash] = 1;
41 virtual void OnRehash(userrec* user, const std::string ¶meter)
44 Conf = new ConfigReader(ServerInstance);
47 virtual ~ModuleModesOnConnect()
52 virtual Version GetVersion()
54 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
57 virtual void OnPostConnect(userrec* user)
62 for (int j = 0; j < Conf->Enumerate("connect"); j++)
64 std::string hostn = Conf->ReadValue("connect","allow",j);
65 if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
67 std::string ThisModes = Conf->ReadValue("connect","modes",j);
68 if (!ThisModes.empty())
71 stringstream ss(ThisModes);
73 vector<string> tokens;
75 // split ThisUserModes into modes and mode params
77 tokens.push_back(buf);
79 int size = tokens.size() + 1;
80 const char** modes = new const char*[size];
81 modes[0] = user->nick;
82 modes[1] = tokens[0].c_str();
84 if (tokens.size() > 1)
86 // process mode params
88 for (unsigned int k = 1; k < tokens.size(); k++)
90 modes[i] = tokens[k].c_str();
95 ServerInstance->Parser->CallHandler("MODE", modes, size, user);
104 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
106 class ModuleModesOnConnectFactory : public ModuleFactory
109 ModuleModesOnConnectFactory()
113 ~ModuleModesOnConnectFactory()
117 virtual Module * CreateModule(InspIRCd* Me)
119 return new ModuleModesOnConnect(Me);
125 extern "C" DllExport void * init_module( void )
127 return new ModuleModesOnConnectFactory;