]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
- Tear out a useless load of XLine clutters that did nothing much except confuse...
[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 "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         }
32
33         void Implements(char* List)
34         {
35                 List[I_OnPostConnect] = List[I_OnRehash] = 1;
36         }
37
38         virtual void OnRehash(User* user, const std::string &parameter)
39         {
40                 DELETE(Conf);
41                 Conf = new ConfigReader(ServerInstance);
42         }
43         
44         virtual ~ModuleModesOnConnect()
45         {
46                 DELETE(Conf);
47         }
48         
49         virtual Version GetVersion()
50         {
51                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
52         }
53         
54         virtual void OnPostConnect(User* user)
55         {
56                 if (!IS_LOCAL(user))
57                         return;
58
59                 for (int j = 0; j < Conf->Enumerate("connect"); j++)
60                 {
61                         std::string hostn = Conf->ReadValue("connect","allow",j);
62                         if ((match(user->GetIPString(),hostn.c_str(),true)) || (match(user->host,hostn.c_str())))
63                         {
64                                 std::string ThisModes = Conf->ReadValue("connect","modes",j);
65                                 if (!ThisModes.empty())
66                                 {
67                                         std::string buf;
68                                         stringstream ss(ThisModes);
69
70                                         vector<string> tokens;
71
72                                         // split ThisUserModes into modes and mode params
73                                         while (ss >> buf)
74                                                 tokens.push_back(buf);
75
76                                         int size = tokens.size() + 1;
77                                         const char** modes = new const char*[size];
78                                         modes[0] = user->nick;
79                                         modes[1] = tokens[0].c_str();
80
81                                         if (tokens.size() > 1)
82                                         {
83                                                 // process mode params
84                                                 int i = 2;
85                                                 for (unsigned int k = 1; k < tokens.size(); k++)
86                                                 {
87                                                         modes[i] = tokens[k].c_str();
88                                                         i++;
89                                                 }
90                                         }
91
92                                         ServerInstance->Parser->CallHandler("MODE", modes, size, user);
93                                         delete [] modes;
94                                 }
95                                 break;
96                         }
97                 }
98         }
99 };
100
101 MODULE_INIT(ModuleModesOnConnect)