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