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