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