]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
Remove InspIRCd* parameters and fields
[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()  {
26
27                 Conf = new ConfigReader;
28                 Implementation eventlist[] = { I_OnUserConnect, I_OnRehash };
29                 ServerInstance->Modules->Attach(eventlist, this, 2);
30                 // for things like +x on connect, important, otherwise we have to resort to config order (bleh) -- w00t
31                 ServerInstance->Modules->SetPriority(this, PRIORITY_FIRST);
32         }
33
34
35         virtual void OnRehash(User* user)
36         {
37                 delete Conf;
38                 Conf = new ConfigReader;
39         }
40
41         virtual ~ModuleModesOnConnect()
42         {
43                 delete Conf;
44         }
45
46         virtual Version GetVersion()
47         {
48                 return Version("Sets (and unsets) modes on users when they connect", VF_VENDOR,API_VERSION);
49         }
50
51         virtual void OnUserConnect(User* user)
52         {
53                 if (!IS_LOCAL(user))
54                         return;
55
56                 // Backup and zero out the disabled usermodes, so that we can override them here.
57                 char save[64];
58                 memcpy(save, ServerInstance->Config->DisabledUModes,
59                                 sizeof(ServerInstance->Config->DisabledUModes));
60                 memset(ServerInstance->Config->DisabledUModes, 0, 64);
61
62                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
63                 {
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, ascii_case_insensitive_map)) || (InspIRCd::Match(user->host,hostn, ascii_case_insensitive_map)))
67                         {
68                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
69                                 if (!ThisModes.empty())
70                                 {
71                                         std::string buf;
72                                         std::stringstream ss(ThisModes);
73
74                                         std::vector<std::string> tokens;
75
76                                         // split ThisUserModes into modes and mode params
77                                         while (ss >> buf)
78                                                 tokens.push_back(buf);
79
80                                         std::vector<std::string> modes;
81                                         modes.push_back(user->nick);
82                                         modes.push_back(tokens[0]);
83
84                                         if (tokens.size() > 1)
85                                         {
86                                                 // process mode params
87                                                 for (unsigned int k = 1; k < tokens.size(); k++)
88                                                 {
89                                                         modes.push_back(tokens[k]);
90                                                 }
91                                         }
92
93                                         ServerInstance->Parser->CallHandler("MODE", modes, user);
94                                 }
95                                 break;
96                         }
97                 }
98
99                 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
100         }
101 };
102
103 MODULE_INIT(ModuleModesOnConnect)