]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Roadmap item "Fix jointhrottle to not try 'throttle' clients during a netmerge (requi...
[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                 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
32                 ServerInstance->Modules->Attach(eventlist, this, 2);
33         }
34
35
36         virtual void OnRehash(User* user, const std::string &parameter)
37         {
38                 delete Conf;
39                 Conf = new ConfigReader(ServerInstance);
40         }
41         
42         virtual ~ModuleModesOnOper()
43         {
44                 delete Conf;
45         }
46         
47         virtual Version GetVersion()
48         {
49                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
50         }
51         
52         virtual void OnPostOper(User* user, const std::string &opertype)
53         {
54                 // whenever a user opers, go through the oper types, find their <type:modes>,
55                 // and if they have one apply their modes. The mode string can contain +modes
56                 // to add modes to the user or -modes to take modes from the user.
57                 for (int j =0; j < Conf->Enumerate("type"); j++)
58                 {
59                         std::string typen = Conf->ReadValue("type","name",j);
60                         if (!strcmp(typen.c_str(),user->oper))
61                         {
62                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
63                                 if (!ThisOpersModes.empty())
64                                 {
65                                         char first = *(ThisOpersModes.c_str());
66                                         if ((first != '+') && (first != '-'))
67                                                 ThisOpersModes = "+" + ThisOpersModes;
68
69                                         std::string buf;
70                                         stringstream ss(ThisOpersModes);
71                                         vector<string> tokens;
72
73                                         // split ThisOperModes into modes and mode params
74                                         while (ss >> buf)
75                                                 tokens.push_back(buf);
76
77                                         int size = tokens.size() + 1;
78                                         const char** modes = new const char*[size];
79                                         modes[0] = user->nick;
80
81                                         // process mode params
82                                         int i = 1;
83                                         for (unsigned int k = 0; k < tokens.size(); k++)
84                                         {
85                                                 modes[i] = tokens[k].c_str();
86                                                 i++;
87                                         }
88
89                                         std::deque<std::string> n;
90                                         Event rmode((char *)&n, NULL, "send_mode_explicit");
91                                         for (unsigned int j = 0; j < tokens.size(); j++)
92                                                 n.push_back(modes[j]);
93
94                                         rmode.Send(ServerInstance);
95                                         ServerInstance->SendMode(modes, size, user);
96                                         delete [] modes;
97                                 }
98                                 break;
99                         }
100                 }
101         }
102 };
103
104 MODULE_INIT(ModuleModesOnOper)