3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
13 #include "inspstring.h"
15 #include "modes/cmode_h.h"
17 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false)
21 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
23 userrec* x = ServerInstance->FindNick(parameter);
26 if (channel->GetStatus(x) == STATUS_HOP)
28 return std::make_pair(true, x->nick);
32 return std::make_pair(false, parameter);
35 return std::make_pair(false, parameter);
38 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
40 /* If halfops are not enabled in the conf, we don't execute
41 * anything in this class at all.
43 if (!ServerInstance->Config->AllowHalfop)
46 return MODEACTION_DENY;
49 int status = channel->GetStatus(source);
51 /* Call the correct method depending on wether we're adding or removing the mode */
54 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
58 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
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
65 return MODEACTION_ALLOW;
68 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
70 userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
77 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
79 if (MOD_RESULT == ACR_DENY)
81 if (MOD_RESULT == ACR_DEFAULT)
83 if ((status < STATUS_OP) && (!is_uline(user->server)))
85 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
91 return ServerInstance->ModeGrok->Grant(d,chan,UCMODE_HOP);
96 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
98 userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
105 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
107 if (MOD_RESULT == ACR_DENY)
109 if (MOD_RESULT == ACR_DEFAULT)
111 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
113 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
119 return ServerInstance->ModeGrok->Revoke(d,chan,UCMODE_HOP);