]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
1b037043910821fe5db9dc01d9c03ae52e78ef66
[user/henk/code/inspircd.git] / src / modes / cmode_h.cpp
1 #include <string>
2 #include <vector>
3 #include "inspircd_config.h"
4 #include "configreader.h"
5 #include "hash_map.h"
6 #include "inspircd.h"
7 #include "mode.h"
8 #include "channels.h"
9 #include "users.h"
10
11 #include "commands.h"
12 #include "modules.h"
13 #include "inspstring.h"
14 #include "hashcomp.h"
15 #include "modes/cmode_h.h"
16
17 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
18 {
19 }
20
21 unsigned int ModeChannelHalfOp::GetPrefixRank()
22 {
23         return HALFOP_VALUE;
24 }
25
26 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
27 {
28         userrec* x = ServerInstance->FindNick(parameter);
29         if (x)
30         {
31                 if (channel->GetStatus(x) == STATUS_HOP)
32                 {
33                         return std::make_pair(true, x->nick);
34                 }
35                 else
36                 {
37                         return std::make_pair(false, parameter);
38                 }
39         }
40         return std::make_pair(false, parameter);
41 }
42
43 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
44 {
45         /* If halfops are not enabled in the conf, we don't execute
46          * anything in this class at all.
47          */
48         if (!ServerInstance->Config->AllowHalfop)
49         {
50                 parameter = "";
51                 return MODEACTION_DENY;
52         }
53
54         int status = channel->GetStatus(source);
55
56         /* Call the correct method depending on wether we're adding or removing the mode */
57         if (adding)
58         {
59                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
60         }
61         else
62         {
63                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
64         }
65         /* If the method above 'ate' the parameter by reducing it to an empty string, then
66          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
67          * the return value and is always MODEACTION_DENY if the mode is supposed to have
68          * a parameter.
69          */
70         return MODEACTION_ALLOW;
71 }
72
73 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
74 {
75         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
76
77         if (d)
78         {
79                 if (IS_LOCAL(user))
80                 {
81                         int MOD_RESULT = 0;
82                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
83
84                         if (MOD_RESULT == ACR_DENY)
85                                 return "";
86                         if (MOD_RESULT == ACR_DEFAULT)
87                         {
88                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
89                                 {
90                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
91                                         return "";
92                                 }
93                         }
94                 }
95
96                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
97         }
98         return "";
99 }
100
101 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
102 {
103         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
104
105         if (d)
106         {
107                 if (IS_LOCAL(user))
108                 {
109                         int MOD_RESULT = 0;
110                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
111
112                         if (MOD_RESULT == ACR_DENY)
113                                 return "";
114                         if (MOD_RESULT == ACR_DEFAULT)
115                         {
116                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
117                                 {
118                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
119                                         return "";
120                                 }
121                         }
122                 }
123
124                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
125         }
126         return "";
127 }
128