3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
13 #include "inspstring.h"
15 #include "modes/cmode_h.h"
19 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false)
23 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
25 userrec* x = ServerInstance->FindNick(parameter);
28 if (channel->GetStatus(x) == STATUS_HOP)
30 return std::make_pair(true, x->nick);
34 return std::make_pair(false, parameter);
37 return std::make_pair(false, parameter);
40 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
42 /* If halfops are not enabled in the conf, we don't execute
43 * anything in this class at all.
45 if (!ServerInstance->Config->AllowHalfop)
48 return MODEACTION_DENY;
51 int status = channel->GetStatus(source);
53 /* Call the correct method depending on wether we're adding or removing the mode */
56 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
60 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
62 /* If the method above 'ate' the parameter by reducing it to an empty string, then
63 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
64 * the return value and is always MODEACTION_DENY if the mode is supposed to have
67 return MODEACTION_ALLOW;
70 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
72 userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
79 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
81 if (MOD_RESULT == ACR_DENY)
83 if (MOD_RESULT == ACR_DEFAULT)
85 if ((status < STATUS_OP) && (!is_uline(user->server)))
87 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
93 return ServerInstance->ModeGrok->Grant(d,chan,UCMODE_HOP);
98 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
100 userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
107 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
109 if (MOD_RESULT == ACR_DENY)
111 if (MOD_RESULT == ACR_DEFAULT)
113 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
115 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
121 return ServerInstance->ModeGrok->Revoke(d,chan,UCMODE_HOP);