]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Use FindNickOnly in a few commands to prevent enumerating users via UID walking
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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  public:
21         ModuleModesOnOper()
22         {
23                 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
24                 ServerInstance->Modules->Attach(eventlist, this, 2);
25         }
26
27
28         virtual void OnRehash(User* user)
29         {
30         }
31
32         virtual ~ModuleModesOnOper()
33         {
34         }
35
36         virtual Version GetVersion()
37         {
38                 return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR);
39         }
40
41         virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
42         {
43                 // whenever a user opers, go through the oper types, find their <type:modes>,
44                 // and if they have one apply their modes. The mode string can contain +modes
45                 // to add modes to the user or -modes to take modes from the user.
46                 std::string ThisOpersModes = user->oper->getConfig("modes");
47                 if (!ThisOpersModes.empty())
48                 {
49                         ApplyModes(user, ThisOpersModes);
50                 }
51         }
52
53         void ApplyModes(User *u, std::string &smodes)
54         {
55                 char first = *(smodes.c_str());
56                 if ((first != '+') && (first != '-'))
57                         smodes = "+" + smodes;
58
59                 std::string buf;
60                 std::stringstream ss(smodes);
61                 std::vector<std::string> tokens;
62
63                 // split into modes and mode params
64                 while (ss >> buf)
65                         tokens.push_back(buf);
66
67                 std::vector<std::string> modes;
68                 modes.push_back(u->nick);
69
70                 // process mode params
71                 for (unsigned int k = 0; k < tokens.size(); k++)
72                 {
73                         modes.push_back(tokens[k]);
74                 }
75
76                 ServerInstance->SendGlobalMode(modes, u);
77         }
78 };
79
80 MODULE_INIT(ModuleModesOnOper)