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