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