]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
480d69f0a5002b8b7788c7bc5efb24db18ad61eb
[user/henk/code/inspircd.git] / src / modes / cmode_h.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 #include "configreader.h"
16 #include "mode.h"
17 #include "channels.h"
18 #include "users.h"
19 #include "modules.h"
20 #include "modes/cmode_h.h"
21
22 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, NULL, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%', '@', TR_NICK)
23 {
24 }
25
26 unsigned int ModeChannelHalfOp::GetPrefixRank()
27 {
28         return HALFOP_VALUE;
29 }
30
31 ModePair ModeChannelHalfOp::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
32 {
33         User* x = ServerInstance->FindNick(parameter);
34         if (x)
35         {
36                 Membership* memb = channel->GetUser(x);
37                 if (memb && memb->hasMode('h'))
38                 {
39                         return std::make_pair(true, x->nick);
40                 }
41                 else
42                 {
43                         return std::make_pair(false, x->nick);
44                 }
45         }
46         return std::make_pair(false, parameter);
47 }
48
49 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
50 {
51         const UserMembList* clist = channel->GetUsers();
52
53         for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
54         {
55                 if (stack)
56                 {
57                         stack->Push(this->GetModeChar(), i->first->nick);
58                 }
59                 else
60                 {
61                         std::vector<std::string> parameters;
62                         parameters.push_back(channel->name);
63                         parameters.push_back("-h");
64                         parameters.push_back(i->first->nick);
65                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
66                 }
67         }
68
69 }
70
71 void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
72 {
73 }
74
75 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
76 {
77         int status = channel->GetPrefixValue(source);
78
79         /* Call the correct method depending on wether we're adding or removing the mode */
80         if (adding)
81         {
82                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
83         }
84         else
85         {
86                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
87         }
88         /* If the method above 'ate' the parameter by reducing it to an empty string, then
89          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
90          * the return value and is always MODEACTION_DENY if the mode is supposed to have
91          * a parameter.
92          */
93         if (parameter.length())
94                 return MODEACTION_ALLOW;
95         else
96                 return MODEACTION_DENY;
97 }
98
99 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
100 {
101         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
102
103         if (d)
104         {
105                 if (IS_LOCAL(user))
106                 {
107                         ModResult MOD_RESULT;
108                         FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_HALFOP));
109
110                         if (MOD_RESULT == MOD_RES_DENY)
111                                 return "";
112                         if (MOD_RESULT == MOD_RES_PASSTHRU)
113                         {
114                                 if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)))
115                                 {
116                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
117                                         return "";
118                                 }
119                         }
120                 }
121
122                 return d->nick;
123         }
124         return "";
125 }
126
127 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
128 {
129         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
130
131         if (d)
132         {
133                 if (IS_LOCAL(user))
134                 {
135                         ModResult MOD_RESULT;
136                         FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEHALFOP));
137
138                         if (MOD_RESULT == MOD_RES_DENY)
139                                 return "";
140                         if (MOD_RESULT == MOD_RES_PASSTHRU)
141                         {
142                                 if ((user != d) && ((status < OP_VALUE) && (!ServerInstance->ULine(user->server))))
143                                 {
144                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
145                                         return "";
146                                 }
147                         }
148                 }
149
150                 return d->nick;
151         }
152         return "";
153 }
154