]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
Remove "servermode" parameter, replace with IS_FAKE() which is more reliable
[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                 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)
79 {
80         int status = channel->GetStatus(source);
81
82         /* Call the correct method depending on wether we're adding or removing the mode */
83         if (adding)
84         {
85                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
86         }
87         else
88         {
89                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
90         }
91         /* If the method above 'ate' the parameter by reducing it to an empty string, then
92          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
93          * the return value and is always MODEACTION_DENY if the mode is supposed to have
94          * a parameter.
95          */
96         if (parameter.length())
97                 return MODEACTION_ALLOW;
98         else
99                 return MODEACTION_DENY;
100 }
101
102 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
103 {
104         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
105
106         if (d)
107         {
108                 if (IS_LOCAL(user))
109                 {
110                         int MOD_RESULT = 0;
111                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
112
113                         if (MOD_RESULT == ACR_DENY)
114                                 return "";
115                         if (MOD_RESULT == ACR_DEFAULT)
116                         {
117                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
118                                 {
119                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
120                                         return "";
121                                 }
122                         }
123                 }
124
125                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
126         }
127         return "";
128 }
129
130 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
131 {
132         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
133
134         if (d)
135         {
136                 if (IS_LOCAL(user))
137                 {
138                         int MOD_RESULT = 0;
139                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
140
141                         if (MOD_RESULT == ACR_DENY)
142                                 return "";
143                         if (MOD_RESULT == ACR_DEFAULT)
144                         {
145                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
146                                 {
147                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
148                                         return "";
149                                 }
150                         }
151                 }
152
153                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
154         }
155         return "";
156 }
157