1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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) : Module(Me)
28 Conf = new ConfigReader(ServerInstance);
29 Implementation eventlist[] = { I_OnUserConnect, I_OnRehash };
30 ServerInstance->Modules->Attach(eventlist, this, 2);
31 // for things like +x on connect, important, otherwise we have to resort to config order (bleh) -- w00t
32 ServerInstance->Modules->SetPriority(this, PRIO_FIRST);
36 virtual void OnRehash(User* user, const std::string ¶meter)
39 Conf = new ConfigReader(ServerInstance);
42 virtual ~ModuleModesOnConnect()
47 virtual Version GetVersion()
49 return Version("$Id$", VF_VENDOR,API_VERSION);
52 virtual void OnUserConnect(User* user)
57 // Backup and zero out the disabled usermodes, so that we can override them here.
59 memcpy(save, ServerInstance->Config->DisabledUModes,
60 sizeof(ServerInstance->Config->DisabledUModes));
61 memset(ServerInstance->Config->DisabledUModes, 0, 64);
63 for (int j = 0; j < Conf->Enumerate("connect"); j++)
65 std::string hostn = Conf->ReadValue("connect","allow",j);
66 /* XXX: Fixme: does not respect port, limit, etc */
67 if ((InspIRCd::MatchCIDR(user->GetIPString(),hostn, ascii_case_insensitive_map)) || (InspIRCd::Match(user->host,hostn, ascii_case_insensitive_map)))
69 std::string ThisModes = Conf->ReadValue("connect","modes",j);
70 if (!ThisModes.empty())
73 std::stringstream ss(ThisModes);
75 std::vector<std::string> tokens;
77 // split ThisUserModes into modes and mode params
79 tokens.push_back(buf);
81 std::vector<std::string> modes;
82 modes.push_back(user->nick);
83 modes.push_back(tokens[0]);
85 if (tokens.size() > 1)
87 // process mode params
88 for (unsigned int k = 1; k < tokens.size(); k++)
90 modes.push_back(tokens[k]);
94 ServerInstance->Parser->CallHandler("MODE", modes, user);
100 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
104 MODULE_INIT(ModuleModesOnConnect)