1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
27 /* $ModDesc: Sets (and unsets) modes on users when they connect */
29 class ModuleModesOnConnect : public Module
36 ModuleModesOnConnect(InspIRCd* Me)
40 Conf = new ConfigReader(ServerInstance);
43 void Implements(char* List)
45 List[I_OnPostConnect] = List[I_OnRehash] = 1;
48 virtual void OnRehash(const std::string ¶meter)
51 Conf = new ConfigReader(ServerInstance);
54 virtual ~ModuleModesOnConnect()
59 virtual Version GetVersion()
61 return Version(1,0,0,1,VF_VENDOR);
64 virtual void OnPostConnect(userrec* user)
69 ServerInstance->Log(DEBUG,"Post connect for mode setting");
70 for (int j = 0; j < Conf->Enumerate("connect"); j++)
72 std::string hostn = Conf->ReadValue("connect","allow",j);
73 if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
75 ServerInstance->Log(DEBUG,"Found matching connect block '%s'",hostn.c_str());
76 std::string ThisModes = Conf->ReadValue("connect","modes",j);
80 stringstream ss(ThisModes);
82 vector<string> tokens;
84 // split ThisUserModes into modes and mode params
86 tokens.push_back(buf);
88 int size = tokens.size() + 1;
89 const char* modes[size];
90 modes[0] = user->nick;
91 modes[1] = tokens[0].c_str();
93 if (tokens.size() > 1)
95 // process mode params
97 for (unsigned int k = 1; k < tokens.size(); k++)
99 modes[i] = tokens[k].c_str();
104 ServerInstance->SendMode(modes, size, user);
112 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
114 class ModuleModesOnConnectFactory : public ModuleFactory
117 ModuleModesOnConnectFactory()
121 ~ModuleModesOnConnectFactory()
125 virtual Module * CreateModule(InspIRCd* Me)
127 return new ModuleModesOnConnect(Me);
133 extern "C" void * init_module( void )
135 return new ModuleModesOnConnectFactory;