]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
ab017b15724e52e9ad573f82cb2280c184770fc5
[user/henk/code/inspircd.git] / src / modules / m_conn_umodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "wildcard.h"
16
17 /* $ModDesc: Sets (and unsets) modes on users when they connect */
18
19 class ModuleModesOnConnect : public Module
20 {
21  private:
22
23         ConfigReader *Conf;
24
25  public:
26         ModuleModesOnConnect(InspIRCd* Me)
27                 : Module(Me)
28         {
29                 
30                 Conf = new ConfigReader(ServerInstance);
31                 Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
32                 ServerInstance->Modules->Attach(eventlist, this, 2);
33         }
34
35
36         virtual void OnRehash(User* user, const std::string &parameter)
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(1,2,0,1,VF_VENDOR,API_VERSION);
50         }
51         
52         virtual void OnPostConnect(User* user)
53         {
54                 if (!IS_LOCAL(user))
55                         return;
56
57                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
58                 {
59                         std::string hostn = Conf->ReadValue("connect","allow",j);
60                         /* XXX: Fixme: does not respect port, limit, etc */
61                         if ((match(user->GetIPString(),hostn,true)) || (match(user->host,hostn)))
62                         {
63                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
64                                 if (!ThisModes.empty())
65                                 {
66                                         std::string buf;
67                                         std::stringstream ss(ThisModes);
68
69                                         std::vector<std::string> tokens;
70
71                                         // split ThisUserModes into modes and mode params
72                                         while (ss >> buf)
73                                                 tokens.push_back(buf);
74
75                                         std::vector<std::string> modes;
76                                         modes.push_back(user->nick);
77                                         modes.push_back(tokens[0]);
78
79                                         if (tokens.size() > 1)
80                                         {
81                                                 // process mode params
82                                                 for (unsigned int k = 1; k < tokens.size(); k++)
83                                                 {
84                                                         modes.push_back(tokens[k]);
85                                                 }
86                                         }
87
88                                         ServerInstance->Parser->CallHandler("MODE", modes, user);
89                                 }
90                                 break;
91                         }
92                 }
93         }
94 };
95
96 MODULE_INIT(ModuleModesOnConnect)