]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[user/henk/code/inspircd.git] / src / modules / m_opermodes.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
21 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
22
23 class ModuleModesOnOper : public Module
24 {
25  private:
26
27         
28         ConfigReader *Conf;
29
30  public:
31         ModuleModesOnOper(InspIRCd* Me)
32                 : Module(Me)
33         {
34                 
35                 Conf = new ConfigReader(ServerInstance);
36         }
37
38         void Implements(char* List)
39         {
40                 List[I_OnPostOper] = 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 ~ModuleModesOnOper()
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 OnPostOper(userrec* user, const std::string &opertype)
60         {
61                 // whenever a user opers, go through the oper types, find their <type:modes>,
62                 // and if they have one apply their modes. The mode string can contain +modes
63                 // to add modes to the user or -modes to take modes from the user.
64                 for (int j =0; j < Conf->Enumerate("type"); j++)
65                 {
66                         std::string typen = Conf->ReadValue("type","name",j);
67                         if (!strcmp(typen.c_str(),user->oper))
68                         {
69                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
70                                 char first = *(ThisOpersModes.c_str());
71                                 if ((first != '+') && (first != '-'))
72                                         ThisOpersModes = "+" + ThisOpersModes;
73                                 if (ThisOpersModes != "")
74                                 {
75                                         std::string buf;
76                                         stringstream ss(ThisOpersModes);
77
78                                         vector<string> tokens;
79
80                                         // split ThisOperModes into modes and mode params
81                                         while (ss >> buf)
82                                                 tokens.push_back(buf);
83
84                                         int size = tokens.size() + 1;
85                                         char** modes = new char*[size];
86                                         modes[0] = user->nick;
87                                         modes[1] = (char*)tokens[0].c_str();
88
89                                         if (tokens.size() > 1)
90                                         {
91                                                 // process mode params
92                                                 int i = 2;
93                                                 for (unsigned int k = 1; k < tokens.size(); k++)
94                                                 {
95                                                         modes[i] = (char*)tokens[k].c_str();
96                                                         i++;
97                                                 }
98                                         }
99                                         std::deque<std::string> n;
100                                         Event rmode((char *)&n, NULL, "send_mode");
101                                         for (unsigned int j = 0; j < tokens.size(); j++)
102                                         {
103                                                 n.push_back(modes[j]);
104                                         }
105                                         rmode.Send(ServerInstance);
106                                         ServerInstance->SendMode((const char**)modes, size, user);
107                                         delete [] modes;
108                                 }
109                                 break;
110                         }
111                 }
112         }
113 };
114
115 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
116
117 class ModuleModesOnOperFactory : public ModuleFactory
118 {
119  public:
120         ModuleModesOnOperFactory()
121         {
122         }
123         
124         ~ModuleModesOnOperFactory()
125         {
126         }
127         
128         virtual Module * CreateModule(InspIRCd* Me)
129         {
130                 return new ModuleModesOnOper(Me);
131         }
132         
133 };
134
135
136 extern "C" DllExport void * init_module( void )
137 {
138         return new ModuleModesOnOperFactory;
139 }
140