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