]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_halfop.cpp
Replace copyright headers with headers granting specific authors copyright
[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 #include "inspircd.h"
21
22 class ModeChannelHalfOp : public ModeHandler
23 {
24  public:
25         ModeChannelHalfOp(Module* parent);
26         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
27         unsigned int GetPrefixRank();
28         void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
29         void RemoveMode(User* user, irc::modestacker* stack = NULL);
30
31         ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
32         {
33                 if (!adding && src->nick == value)
34                         return MOD_RES_ALLOW;
35                 return MOD_RES_PASSTHRU;
36         }
37 };
38
39 ModeChannelHalfOp::ModeChannelHalfOp(Module* parent) : ModeHandler(parent, "halfop", 'h', PARAM_ALWAYS, MODETYPE_CHANNEL)
40 {
41         list = true;
42         prefix = '%';
43         levelrequired = OP_VALUE;
44         m_paramtype = TR_NICK;
45 }
46
47 unsigned int ModeChannelHalfOp::GetPrefixRank()
48 {
49         return HALFOP_VALUE;
50 }
51
52 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
53 {
54         const UserMembList* clist = channel->GetUsers();
55
56         for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
57         {
58                 if (stack)
59                 {
60                         stack->Push(this->GetModeChar(), i->first->nick);
61                 }
62                 else
63                 {
64                         std::vector<std::string> parameters;
65                         parameters.push_back(channel->name);
66                         parameters.push_back("-h");
67                         parameters.push_back(i->first->nick);
68                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
69                 }
70         }
71
72 }
73
74 void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
75 {
76 }
77
78 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
79 {
80         return MODEACTION_ALLOW;
81 }
82
83 class ModuleHalfop : public Module
84 {
85         ModeChannelHalfOp mh;
86  public:
87         ModuleHalfop() : mh(this)
88         {
89                 if (!ServerInstance->Modes->AddMode(&mh))
90                         throw ModuleException("Could not add new modes!");
91         }
92
93         ~ModuleHalfop()
94         {
95                 ServerInstance->Modes->DelMode(&mh);
96         }
97
98         Version GetVersion()
99         {
100                 return Version("Channel half-operator mode provider", VF_VENDOR);
101         }
102 };
103
104 MODULE_INIT(ModuleHalfop)