]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operprefix.cpp
Replace copyright headers with headers granting specific authors copyright
[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, char pfx) : ModeHandler(Creator, "operprefix", 'y', PARAM_ALWAYS, MODETYPE_CHANNEL)
35                 {
36                         list = true;
37                         prefix = pfx;
38                         levelrequired = OPERPREFIX_VALUE;
39                         m_paramtype = TR_NICK;
40                 }
41
42                 unsigned int GetPrefixRank()
43                 {
44                         return OPERPREFIX_VALUE;
45                 }
46
47                 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
48                 {
49                         if (IS_SERVER(source) || (source && ServerInstance->ULine(source->server)))
50                                 return MODEACTION_ALLOW;
51                         else
52                         {
53                                 if (source && channel)
54                                         source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only servers are permitted to change channel mode '%c'", source->nick.c_str(), channel->name.c_str(), 'y');
55                                 return MODEACTION_DENY;
56                         }
57                 }
58
59                 bool NeedsOper() { return true; }
60 };
61
62 class ModuleOperPrefixMode : public Module
63 {
64  private:
65         OperPrefixMode* opm;
66  public:
67         ModuleOperPrefixMode()  {
68                 ConfigReader Conf;
69                 std::string pfx = Conf.ReadValue("operprefix", "prefix", "!", 0, false);
70
71                 opm = new OperPrefixMode(this, pfx[0]);
72                 if ((!ServerInstance->Modes->AddMode(opm)))
73                         throw ModuleException("Could not add a new mode!");
74
75                 Implementation eventlist[] = { I_OnPostJoin, I_OnUserQuit, I_OnUserKick, I_OnUserPart, I_OnOper };
76                 ServerInstance->Modules->Attach(eventlist, this, 5);
77         }
78
79         void PushChanMode(Channel* channel, User* user)
80         {
81                 char modeline[] = "+y";
82                 std::vector<std::string> modechange;
83                 modechange.push_back(channel->name);
84                 modechange.push_back(modeline);
85                 modechange.push_back(user->nick);
86                 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
87         }
88
89         void OnPostJoin(Membership* memb)
90         {
91                 if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
92                         PushChanMode(memb->chan, memb->user);
93         }
94
95         // XXX: is there a better way to do this?
96         ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
97         {
98                 /* force event propagation to its ModeHandler */
99                 if (!IS_SERVER(user) && chan && (mode == 'y'))
100                         return MOD_RES_ALLOW;
101                 return MOD_RES_PASSTHRU;
102         }
103
104         void OnOper(User *user, const std::string&)
105         {
106                 if (user && !user->IsModeSet('H'))
107                 {
108                         for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
109                         {
110                                 PushChanMode(*v, user);
111                         }
112                 }
113         }
114
115         ~ModuleOperPrefixMode()
116         {
117                 delete opm;
118         }
119
120         Version GetVersion()
121         {
122                 return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
123         }
124 };
125
126 MODULE_INIT(ModuleOperPrefixMode)