]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
fea793c0416b66f24bb6c44e4529b1366adb63a4
[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 "inspircd.h"
15
16 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
17
18 class ModuleModesOnOper : public Module
19 {
20  private:
21
22         
23         ConfigReader *Conf;
24
25  public:
26         ModuleModesOnOper(InspIRCd* Me)
27                 : Module(Me)
28         {
29                 
30                 Conf = new ConfigReader(ServerInstance);
31         }
32
33         void Implements(char* List)
34         {
35                 List[I_OnPostOper] = List[I_OnRehash] = 1;
36         }
37
38         virtual void OnRehash(userrec* user, const std::string &parameter)
39         {
40                 DELETE(Conf);
41                 Conf = new ConfigReader(ServerInstance);
42         }
43         
44         virtual ~ModuleModesOnOper()
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 OnPostOper(userrec* user, const std::string &opertype)
55         {
56                 // whenever a user opers, go through the oper types, find their <type:modes>,
57                 // and if they have one apply their modes. The mode string can contain +modes
58                 // to add modes to the user or -modes to take modes from the user.
59                 for (int j =0; j < Conf->Enumerate("type"); j++)
60                 {
61                         std::string typen = Conf->ReadValue("type","name",j);
62                         if (!strcmp(typen.c_str(),user->oper))
63                         {
64                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
65                                 if (!ThisOpersModes.empty())
66                                 {
67                                         char first = *(ThisOpersModes.c_str());
68                                         if ((first != '+') && (first != '-'))
69                                                 ThisOpersModes = "+" + ThisOpersModes;
70
71                                         std::string buf;
72                                         stringstream ss(ThisOpersModes);
73                                         vector<string> tokens;
74
75                                         // split ThisOperModes into modes and mode params
76                                         while (ss >> buf)
77                                                 tokens.push_back(buf);
78
79                                         int size = tokens.size() + 1;
80                                         const char** modes = new const char*[size];
81                                         modes[0] = user->nick;
82
83                                         // process mode params
84                                         int i = 1;
85                                         for (unsigned int k = 0; k < tokens.size(); k++)
86                                         {
87                                                 modes[i] = tokens[k].c_str();
88                                                 i++;
89                                         }
90
91                                         std::deque<std::string> n;
92                                         Event rmode((char *)&n, NULL, "send_mode_explicit");
93                                         for (unsigned int j = 0; j < tokens.size(); j++)
94                                                 n.push_back(modes[j]);
95
96                                         rmode.Send(ServerInstance);
97                                         ServerInstance->SendMode(modes, size, user);
98                                         delete [] modes;
99                                 }
100                                 break;
101                         }
102                 }
103         }
104 };
105
106 MODULE_INIT(ModuleModesOnOper)