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 * ---------------------------------------------------
22 /* $ModDesc: Sets (and unsets) modes on users when they connect */
24 class ModuleModesOnConnect : public Module
31 ModuleModesOnConnect(InspIRCd* Me)
35 Conf = new ConfigReader(ServerInstance);
38 void Implements(char* List)
40 List[I_OnPostConnect] = List[I_OnRehash] = 1;
43 virtual void OnRehash(userrec* user, const std::string ¶meter)
46 Conf = new ConfigReader(ServerInstance);
49 virtual ~ModuleModesOnConnect()
54 virtual Version GetVersion()
56 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
59 virtual void OnPostConnect(userrec* user)
64 ServerInstance->Log(DEBUG,"Post connect for mode setting");
65 for (int j = 0; j < Conf->Enumerate("connect"); j++)
67 std::string hostn = Conf->ReadValue("connect","allow",j);
68 if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
70 ServerInstance->Log(DEBUG,"Found matching connect block '%s'",hostn.c_str());
71 std::string ThisModes = Conf->ReadValue("connect","modes",j);
75 stringstream ss(ThisModes);
77 vector<string> tokens;
79 // split ThisUserModes into modes and mode params
81 tokens.push_back(buf);
83 int size = tokens.size() + 1;
84 const char* modes[size];
85 modes[0] = user->nick;
86 modes[1] = tokens[0].c_str();
88 if (tokens.size() > 1)
90 // process mode params
92 for (unsigned int k = 1; k < tokens.size(); k++)
94 modes[i] = tokens[k].c_str();
99 ServerInstance->Log(DEBUG,"Call mode handler to set modes");
100 ServerInstance->Parser->CallHandler("MODE", modes, size, user);
108 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
110 class ModuleModesOnConnectFactory : public ModuleFactory
113 ModuleModesOnConnectFactory()
117 ~ModuleModesOnConnectFactory()
121 virtual Module * CreateModule(InspIRCd* Me)
123 return new ModuleModesOnConnect(Me);
129 extern "C" void * init_module( void )
131 return new ModuleModesOnConnectFactory;