1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 /* $ModDesc: Sets (and unsets) modes on users when they connect */
18 class ModuleModesOnConnect : public Module
25 ModuleModesOnConnect(InspIRCd* Me)
29 Conf = new ConfigReader(ServerInstance);
30 Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
31 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual void OnRehash(User* user, const std::string ¶meter)
38 Conf = new ConfigReader(ServerInstance);
41 virtual ~ModuleModesOnConnect()
46 virtual Version GetVersion()
48 return Version("$Id$", VF_VENDOR,API_VERSION);
51 virtual void OnPostConnect(User* user)
56 // Backup and zero out the disabled usermodes, so that we can override them here.
58 memcpy(save, ServerInstance->Config->DisabledUModes,
59 sizeof(ServerInstance->Config->DisabledUModes));
60 memset(ServerInstance->Config->DisabledUModes, 0, 64);
62 for (int j = 0; j < Conf->Enumerate("connect"); j++)
64 std::string hostn = Conf->ReadValue("connect","allow",j);
65 /* XXX: Fixme: does not respect port, limit, etc */
66 if ((InspIRCd::MatchCIDR(user->GetIPString(),hostn)) || (InspIRCd::Match(user->host,hostn)))
68 std::string ThisModes = Conf->ReadValue("connect","modes",j);
69 if (!ThisModes.empty())
72 std::stringstream ss(ThisModes);
74 std::vector<std::string> tokens;
76 // split ThisUserModes into modes and mode params
78 tokens.push_back(buf);
80 std::vector<std::string> modes;
81 modes.push_back(user->nick);
82 modes.push_back(tokens[0]);
84 if (tokens.size() > 1)
86 // process mode params
87 for (unsigned int k = 1; k < tokens.size(); k++)
89 modes.push_back(tokens[k]);
93 ServerInstance->Parser->CallHandler("MODE", modes, user);
99 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
103 MODULE_INIT(ModuleModesOnConnect)