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