]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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()
27                         {
28
29                 Conf = new ConfigReader;
30                 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
31                 ServerInstance->Modules->Attach(eventlist, this, 2);
32         }
33
34
35         virtual void OnRehash(User* user)
36         {
37                 delete Conf;
38                 Conf = new ConfigReader;
39         }
40
41         virtual ~ModuleModesOnOper()
42         {
43                 delete Conf;
44         }
45
46         virtual Version GetVersion()
47         {
48                 return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR, API_VERSION);
49         }
50
51         virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
52         {
53                 // whenever a user opers, go through the oper types, find their <type:modes>,
54                 // and if they have one apply their modes. The mode string can contain +modes
55                 // to add modes to the user or -modes to take modes from the user.
56                 for (int j =0; j < Conf->Enumerate("type"); j++)
57                 {
58                         std::string typen = Conf->ReadValue("type","name",j);
59                         if (typen == user->oper)
60                         {
61                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
62                                 if (!ThisOpersModes.empty())
63                                 {
64                                         ApplyModes(user, ThisOpersModes);
65                                 }
66                                 break;
67                         }
68                 }
69
70                 if (!opername.empty()) // if user is local ..
71                 {
72                         for (int j = 0; j < Conf->Enumerate("oper"); j++)
73                         {
74                                 if (opername == Conf->ReadValue("oper", "name", j))
75                                 {
76                                         std::string ThisOpersModes = Conf->ReadValue("oper", "modes", j);
77                                         if (!ThisOpersModes.empty())
78                                         {
79                                                 ApplyModes(user, ThisOpersModes);
80                                         }
81                                         break;
82                                 }
83                         }
84                 }
85         }
86
87         void ApplyModes(User *u, std::string &smodes)
88         {
89                 char first = *(smodes.c_str());
90                 if ((first != '+') && (first != '-'))
91                         smodes = "+" + smodes;
92
93                 std::string buf;
94                 std::stringstream ss(smodes);
95                 std::vector<std::string> tokens;
96
97                 // split into modes and mode params
98                 while (ss >> buf)
99                         tokens.push_back(buf);
100
101                 std::vector<std::string> modes;
102                 modes.push_back(u->nick);
103
104                 // process mode params
105                 for (unsigned int k = 0; k < tokens.size(); k++)
106                 {
107                         modes.push_back(tokens[k]);
108                 }
109
110                 ServerInstance->SendMode(modes, u);
111                 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
112         }
113 };
114
115 MODULE_INIT(ModuleModesOnOper)