1 #include "configreader.h"
7 #include "modes/cmode_h.h"
9 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
13 unsigned int ModeChannelHalfOp::GetPrefixRank()
18 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
20 userrec* x = ServerInstance->FindNick(parameter);
23 if (channel->GetStatusFlags(x) & UCMODE_HOP)
25 return std::make_pair(true, x->nick);
29 return std::make_pair(false, parameter);
32 return std::make_pair(false, parameter);
35 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
37 /* If halfops are not enabled in the conf, we don't execute
38 * anything in this class at all.
40 if (!ServerInstance->Config->AllowHalfop)
43 return MODEACTION_DENY;
46 int status = channel->GetStatus(source);
48 /* Call the correct method depending on wether we're adding or removing the mode */
51 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
55 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
57 /* If the method above 'ate' the parameter by reducing it to an empty string, then
58 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
59 * the return value and is always MODEACTION_DENY if the mode is supposed to have
62 return MODEACTION_ALLOW;
65 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
67 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
74 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
76 if (MOD_RESULT == ACR_DENY)
78 if (MOD_RESULT == ACR_DEFAULT)
80 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
82 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
88 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
93 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
95 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
102 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
104 if (MOD_RESULT == ACR_DENY)
106 if (MOD_RESULT == ACR_DEFAULT)
108 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
110 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
116 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);