]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Remove m_halfop from list in compat linking mode
[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  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                 ThisOpersModes = user->oper->getConfig("modes");
53                 if (!ThisOpersModes.empty())
54                 {
55                         ApplyModes(user, ThisOpersModes);
56                 }
57         }
58
59         void ApplyModes(User *u, std::string &smodes)
60         {
61                 char first = *(smodes.c_str());
62                 if ((first != '+') && (first != '-'))
63                         smodes = "+" + smodes;
64
65                 std::string buf;
66                 std::stringstream ss(smodes);
67                 std::vector<std::string> tokens;
68
69                 // split into modes and mode params
70                 while (ss >> buf)
71                         tokens.push_back(buf);
72
73                 std::vector<std::string> modes;
74                 modes.push_back(u->nick);
75
76                 // process mode params
77                 for (unsigned int k = 0; k < tokens.size(); k++)
78                 {
79                         modes.push_back(tokens[k]);
80                 }
81
82                 ServerInstance->SendMode(modes, u);
83                 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
84         }
85 };
86
87 MODULE_INIT(ModuleModesOnOper)