]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
f1cc8bc6b863a814c0c137dbc9f364a687b8bd92
[user/henk/code/inspircd.git] / src / modules / m_conn_umodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "wildcard.h"
19
20 /* $ModDesc: Sets (and unsets) modes on users when they connect */
21
22 class ModuleModesOnConnect : public Module
23 {
24  private:
25
26         ConfigReader *Conf;
27
28  public:
29         ModuleModesOnConnect(InspIRCd* Me)
30                 : Module(Me)
31         {
32                 
33                 Conf = new ConfigReader(ServerInstance);
34         }
35
36         void Implements(char* List)
37         {
38                 List[I_OnPostConnect] = List[I_OnRehash] = 1;
39         }
40
41         virtual void OnRehash(userrec* user, const std::string &parameter)
42         {
43                 DELETE(Conf);
44                 Conf = new ConfigReader(ServerInstance);
45         }
46         
47         virtual ~ModuleModesOnConnect()
48         {
49                 DELETE(Conf);
50         }
51         
52         virtual Version GetVersion()
53         {
54                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
55         }
56         
57         virtual void OnPostConnect(userrec* user)
58         {
59                 if (!IS_LOCAL(user))
60                         return;
61
62                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
63                 {
64                         std::string hostn = Conf->ReadValue("connect","allow",j);
65                         if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
66                         {
67                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
68                                 if (!ThisModes.empty())
69                                 {
70                                         std::string buf;
71                                         stringstream ss(ThisModes);
72
73                                         vector<string> tokens;
74
75                                         // split ThisUserModes into modes and mode params
76                                         while (ss >> buf)
77                                                 tokens.push_back(buf);
78
79                                         int size = tokens.size() + 1;
80                                         const char** modes = new const char*[size];
81                                         modes[0] = user->nick;
82                                         modes[1] = tokens[0].c_str();
83
84                                         if (tokens.size() > 1)
85                                         {
86                                                 // process mode params
87                                                 int i = 2;
88                                                 for (unsigned int k = 1; k < tokens.size(); k++)
89                                                 {
90                                                         modes[i] = tokens[k].c_str();
91                                                         i++;
92                                                 }
93                                         }
94
95                                         ServerInstance->Parser->CallHandler("MODE", modes, size, user);
96                                         delete [] modes;
97                                 }
98                                 break;
99                         }
100                 }
101         }
102 };
103
104 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
105
106 class ModuleModesOnConnectFactory : public ModuleFactory
107 {
108  public:
109         ModuleModesOnConnectFactory()
110         {
111         }
112         
113         ~ModuleModesOnConnectFactory()
114         {
115         }
116         
117         virtual Module * CreateModule(InspIRCd* Me)
118         {
119                 return new ModuleModesOnConnect(Me);
120         }
121         
122 };
123
124
125 extern "C" DllExport void * init_module( void )
126 {
127         return new ModuleModesOnConnectFactory;
128 }
129