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