]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
Fix for bug #695. For now, we cant be sure what parts of the code might still use...
[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://www.inspircd.org/wiki/index.php/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, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%', '@')
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                 if (channel->GetStatusFlags(x) & UCMODE_HOP)
37                 {
38                         return std::make_pair(true, x->nick);
39                 }
40                 else
41                 {
42                         return std::make_pair(false, parameter);
43                 }
44         }
45         return std::make_pair(false, parameter);
46 }
47
48 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
49 {
50         CUList* clist = channel->GetHalfoppedUsers();
51         CUList copy;
52
53         for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
54         {
55                 User* n = i->first;
56                 copy.insert(std::make_pair(n,n->nick));
57         }
58
59         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
60         {
61                 if (stack)
62                 {
63                         stack->Push(this->GetModeChar(), i->first->nick);
64                 }
65                 else
66                 {
67                         std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-h"); 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, bool servermode)
79 {
80         /* If halfops are not enabled in the conf, we don't execute
81          * anything in this class at all.
82          */
83         if (!ServerInstance->Config->AllowHalfop)
84         {
85                 parameter = "";
86                 return MODEACTION_DENY;
87         }
88
89         int status = channel->GetStatus(source);
90
91         /* Call the correct method depending on wether we're adding or removing the mode */
92         if (adding)
93         {
94                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
95         }
96         else
97         {
98                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
99         }
100         /* If the method above 'ate' the parameter by reducing it to an empty string, then
101          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
102          * the return value and is always MODEACTION_DENY if the mode is supposed to have
103          * a parameter.
104          */
105         if (parameter.length())
106                 return MODEACTION_ALLOW;
107         else
108                 return MODEACTION_DENY;
109 }
110
111 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
112 {
113         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
114
115         if (d)
116         {
117                 if (IS_LOCAL(user))
118                 {
119                         int MOD_RESULT = 0;
120                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
121
122                         if (MOD_RESULT == ACR_DENY)
123                                 return "";
124                         if (MOD_RESULT == ACR_DEFAULT)
125                         {
126                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
127                                 {
128                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
129                                         return "";
130                                 }
131                         }
132                 }
133
134                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
135         }
136         return "";
137 }
138
139 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
140 {
141         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
142
143         if (d)
144         {
145                 if (IS_LOCAL(user))
146                 {
147                         int MOD_RESULT = 0;
148                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
149
150                         if (MOD_RESULT == ACR_DENY)
151                                 return "";
152                         if (MOD_RESULT == ACR_DEFAULT)
153                         {
154                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
155                                 {
156                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
157                                         return "";
158                                 }
159                         }
160                 }
161
162                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
163         }
164         return "";
165 }
166