]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Fix these to use new hook system (u_listmode wasnt fixed yet)
[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         void Implements(char* List)
36         {
37                 List[I_OnPostOper] = 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 ~ModuleModesOnOper()
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 OnPostOper(User* user, const std::string &opertype)
57         {
58                 // whenever a user opers, go through the oper types, find their <type:modes>,
59                 // and if they have one apply their modes. The mode string can contain +modes
60                 // to add modes to the user or -modes to take modes from the user.
61                 for (int j =0; j < Conf->Enumerate("type"); j++)
62                 {
63                         std::string typen = Conf->ReadValue("type","name",j);
64                         if (!strcmp(typen.c_str(),user->oper))
65                         {
66                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
67                                 if (!ThisOpersModes.empty())
68                                 {
69                                         char first = *(ThisOpersModes.c_str());
70                                         if ((first != '+') && (first != '-'))
71                                                 ThisOpersModes = "+" + ThisOpersModes;
72
73                                         std::string buf;
74                                         stringstream ss(ThisOpersModes);
75                                         vector<string> tokens;
76
77                                         // split ThisOperModes into modes and mode params
78                                         while (ss >> buf)
79                                                 tokens.push_back(buf);
80
81                                         int size = tokens.size() + 1;
82                                         const char** modes = new const char*[size];
83                                         modes[0] = user->nick;
84
85                                         // process mode params
86                                         int i = 1;
87                                         for (unsigned int k = 0; k < tokens.size(); k++)
88                                         {
89                                                 modes[i] = tokens[k].c_str();
90                                                 i++;
91                                         }
92
93                                         std::deque<std::string> n;
94                                         Event rmode((char *)&n, NULL, "send_mode_explicit");
95                                         for (unsigned int j = 0; j < tokens.size(); j++)
96                                                 n.push_back(modes[j]);
97
98                                         rmode.Send(ServerInstance);
99                                         ServerInstance->SendMode(modes, size, user);
100                                         delete [] modes;
101                                 }
102                                 break;
103                         }
104                 }
105         }
106 };
107
108 MODULE_INIT(ModuleModesOnOper)