]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_halfop.cpp
Merge pull request #1084 from SaberUK/insp20+fix-parallel-debug-install
[user/henk/code/inspircd.git] / src / modules / m_halfop.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 /* $ModDesc: Channel half-operator mode provider */
21
22 #include "inspircd.h"
23
24 class ModeChannelHalfOp : public ModeHandler
25 {
26  public:
27         ModeChannelHalfOp(Module* parent);
28         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
29         unsigned int GetPrefixRank();
30         void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
31         void RemoveMode(User* user, irc::modestacker* stack = NULL);
32
33         ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
34         {
35                 if (!adding && src->nick == value)
36                         return MOD_RES_ALLOW;
37                 return MOD_RES_PASSTHRU;
38         }
39 };
40
41 ModeChannelHalfOp::ModeChannelHalfOp(Module* parent) : ModeHandler(parent, "halfop", 'h', PARAM_ALWAYS, MODETYPE_CHANNEL)
42 {
43         list = true;
44         prefix = '%';
45         levelrequired = OP_VALUE;
46         m_paramtype = TR_NICK;
47 }
48
49 unsigned int ModeChannelHalfOp::GetPrefixRank()
50 {
51         return HALFOP_VALUE;
52 }
53
54 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
55 {
56         const UserMembList* clist = channel->GetUsers();
57
58         for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
59         {
60                 if (stack)
61                 {
62                         stack->Push(this->GetModeChar(), i->first->nick);
63                 }
64                 else
65                 {
66                         std::vector<std::string> parameters;
67                         parameters.push_back(channel->name);
68                         parameters.push_back("-h");
69                         parameters.push_back(i->first->nick);
70                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
71                 }
72         }
73
74 }
75
76 void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
77 {
78 }
79
80 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
81 {
82         return MODEACTION_ALLOW;
83 }
84
85 class ModuleHalfop : public Module
86 {
87         ModeChannelHalfOp mh;
88  public:
89         ModuleHalfop() : mh(this)
90         {
91         }
92
93         void init()
94         {
95                 ServerInstance->Modules->AddService(mh);
96         }
97
98         Version GetVersion()
99         {
100                 return Version("Channel half-operator mode provider", VF_VENDOR);
101         }
102 };
103
104 MODULE_INIT(ModuleHalfop)