]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operprefix.cpp
b0cb0e4e9d8876b4183528eb5bbf316adec3b61a
[user/henk/code/inspircd.git] / src / modules / m_operprefix.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 /*
22  * Originally by Chernov-Phoenix Alexey (Phoenix@RusNet) mailto:phoenix /email address separator/ pravmail.ru
23  */
24
25 /* $ModDesc: Gives opers cmode +y which provides a staff prefix. */
26
27 #include "inspircd.h"
28
29 #define OPERPREFIX_VALUE 1000000
30
31 class OperPrefixMode : public ModeHandler
32 {
33         public:
34                 OperPrefixMode(Module* Creator) : ModeHandler(Creator, "operprefix", 'y', PARAM_ALWAYS, MODETYPE_CHANNEL)
35                 {
36                         std::string pfx = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!");
37                         list = true;
38                         prefix = pfx.empty() ? '!' : pfx[0];
39                         levelrequired = OPERPREFIX_VALUE;
40                         m_paramtype = TR_NICK;
41                 }
42
43                 unsigned int GetPrefixRank()
44                 {
45                         return OPERPREFIX_VALUE;
46                 }
47
48                 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
49                 {
50                         if (IS_SERVER(source) || (source && ServerInstance->ULine(source->server)))
51                                 return MODEACTION_ALLOW;
52                         else
53                         {
54                                 if (source && channel)
55                                         source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only servers are permitted to change channel mode '%c'", source->nick.c_str(), channel->name.c_str(), 'y');
56                                 return MODEACTION_DENY;
57                         }
58                 }
59
60                 bool NeedsOper() { return true; }
61 };
62
63 class ModuleOperPrefixMode : public Module
64 {
65  private:
66         OperPrefixMode opm;
67  public:
68         ModuleOperPrefixMode()
69                 : opm(this)
70         {
71         }
72
73         void init()
74         {
75                 ServerInstance->Modules->AddService(opm);
76
77                 Implementation eventlist[] = { I_OnPostJoin, I_OnOper };
78                 ServerInstance->Modules->Attach(eventlist, this, 2);
79         }
80
81         void PushChanMode(Channel* channel, User* user)
82         {
83                 char modeline[] = "+y";
84                 std::vector<std::string> modechange;
85                 modechange.push_back(channel->name);
86                 modechange.push_back(modeline);
87                 modechange.push_back(user->nick);
88                 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
89         }
90
91         void OnPostJoin(Membership* memb)
92         {
93                 if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
94                         PushChanMode(memb->chan, memb->user);
95         }
96
97         // XXX: is there a better way to do this?
98         ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
99         {
100                 /* force event propagation to its ModeHandler */
101                 if (!IS_SERVER(user) && chan && (mode == 'y'))
102                         return MOD_RES_ALLOW;
103                 return MOD_RES_PASSTHRU;
104         }
105
106         void OnOper(User *user, const std::string&)
107         {
108                 if (user && !user->IsModeSet('H'))
109                 {
110                         for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
111                         {
112                                 PushChanMode(*v, user);
113                         }
114                 }
115         }
116
117         ~ModuleOperPrefixMode()
118         {
119         }
120
121         Version GetVersion()
122         {
123                 return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
124         }
125 };
126
127 MODULE_INIT(ModuleOperPrefixMode)