]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
195321bfb73f222ad6332e16e945468dffbe48e0
[user/henk/code/inspircd.git] / src / modules / m_conn_umodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Sets (and unsets) modes on users when they connect */
17
18 class ModuleModesOnConnect : public Module
19 {
20  private:
21
22         ConfigReader *Conf;
23
24  public:
25         ModuleModesOnConnect(InspIRCd* Me) : Module(Me)
26         {
27
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, PRIORITY_FIRST);
33         }
34
35
36         virtual void OnRehash(User* user)
37         {
38                 delete Conf;
39                 Conf = new ConfigReader(ServerInstance);
40         }
41
42         virtual ~ModuleModesOnConnect()
43         {
44                 delete Conf;
45         }
46
47         virtual Version GetVersion()
48         {
49                 return Version("Sets (and unsets) modes on users when they connect", VF_VENDOR,API_VERSION);
50         }
51
52         virtual void OnUserConnect(User* user)
53         {
54                 if (!IS_LOCAL(user))
55                         return;
56
57                 // Backup and zero out the disabled usermodes, so that we can override them here.
58                 char save[64];
59                 memcpy(save, ServerInstance->Config->DisabledUModes,
60                                 sizeof(ServerInstance->Config->DisabledUModes));
61                 memset(ServerInstance->Config->DisabledUModes, 0, 64);
62
63                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
64                 {
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)))
68                         {
69                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
70                                 if (!ThisModes.empty())
71                                 {
72                                         std::string buf;
73                                         std::stringstream ss(ThisModes);
74
75                                         std::vector<std::string> tokens;
76
77                                         // split ThisUserModes into modes and mode params
78                                         while (ss >> buf)
79                                                 tokens.push_back(buf);
80
81                                         std::vector<std::string> modes;
82                                         modes.push_back(user->nick);
83                                         modes.push_back(tokens[0]);
84
85                                         if (tokens.size() > 1)
86                                         {
87                                                 // process mode params
88                                                 for (unsigned int k = 1; k < tokens.size(); k++)
89                                                 {
90                                                         modes.push_back(tokens[k]);
91                                                 }
92                                         }
93
94                                         ServerInstance->Parser->CallHandler("MODE", modes, user);
95                                 }
96                                 break;
97                         }
98                 }
99
100                 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
101         }
102 };
103
104 MODULE_INIT(ModuleModesOnConnect)