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