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