]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
Someone is getting slapped for this; the new hidesplits/hidebans behavior doesn't...
[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                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
65                 {
66                         std::string hostn = Conf->ReadValue("connect","allow",j);
67                         if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
68                         {
69                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
70                                 if (ThisModes != "")
71                                 {
72                                         std::string buf;
73                                         stringstream ss(ThisModes);
74
75                                         vector<string> tokens;
76
77                                         // split ThisUserModes into modes and mode params
78                                         while (ss >> buf)
79                                                 tokens.push_back(buf);
80
81                                         int size = tokens.size() + 1;
82                                         const char* modes[size];
83                                         modes[0] = user->nick;
84                                         modes[1] = tokens[0].c_str();
85
86                                         if (tokens.size() > 1)
87                                         {
88                                                 // process mode params
89                                                 int i = 2;
90                                                 for (unsigned int k = 1; k < tokens.size(); k++)
91                                                 {
92                                                         modes[i] = tokens[k].c_str();
93                                                         i++;
94                                                 }
95                                         }
96
97                                         ServerInstance->Parser->CallHandler("MODE", modes, size, user);
98                                 }
99                                 break;
100                         }
101                 }
102         }
103 };
104
105 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
106
107 class ModuleModesOnConnectFactory : public ModuleFactory
108 {
109  public:
110         ModuleModesOnConnectFactory()
111         {
112         }
113         
114         ~ModuleModesOnConnectFactory()
115         {
116         }
117         
118         virtual Module * CreateModule(InspIRCd* Me)
119         {
120                 return new ModuleModesOnConnect(Me);
121         }
122         
123 };
124
125
126 extern "C" void * init_module( void )
127 {
128         return new ModuleModesOnConnectFactory;
129 }
130