3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
14 #include "inspstring.h"
16 #include "modes/cmode_h.h"
18 extern InspIRCd* ServerInstance;
20 extern std::vector<Module*> modules;
21 extern std::vector<ircd_module*> factory;
25 ModeChannelHalfOp::ModeChannelHalfOp() : ModeHandler('h', 1, 1, true, MODETYPE_CHANNEL, false)
29 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
31 userrec* x = ServerInstance->FindNick(parameter);
34 if (channel->GetStatus(x) == STATUS_HOP)
36 return std::make_pair(true, x->nick);
40 return std::make_pair(false, parameter);
43 return std::make_pair(false, parameter);
46 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
48 /* If halfops are not enabled in the conf, we don't execute
49 * anything in this class at all.
51 if (!ServerInstance->Config->AllowHalfop)
54 return MODEACTION_DENY;
57 int status = channel->GetStatus(source);
59 /* Call the correct method depending on wether we're adding or removing the mode */
62 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
66 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
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
73 return MODEACTION_ALLOW;
76 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
78 userrec *d = ModeParser::SanityChecks(user,dest,chan,status);
85 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
87 if (MOD_RESULT == ACR_DENY)
89 if (MOD_RESULT == ACR_DEFAULT)
91 if ((status < STATUS_OP) && (!is_uline(user->server)))
93 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
99 return ModeParser::Grant(d,chan,UCMODE_HOP);
104 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
106 userrec *d = ModeParser::SanityChecks(user,dest,chan,status);
113 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
115 if (MOD_RESULT == ACR_DENY)
117 if (MOD_RESULT == ACR_DEFAULT)
119 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
121 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
127 return ModeParser::Revoke(d,chan,UCMODE_HOP);