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 void ModeChannelHalfOp::RemoveMode(chanrec* channel)
37 CUList* list = channel->GetHalfoppedUsers();
39 char moderemove[MAXBUF];
40 userrec* n = new userrec(ServerInstance);
41 n->SetFd(FD_MAGIC_NUMBER);
43 for (CUList::iterator i = list->begin(); i != list->end(); i++)
45 userrec* n = i->second;
46 copy.insert(std::make_pair(n,n));
48 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
50 sprintf(moderemove,"-%c",this->GetModeChar());
51 const char* parameters[] = { channel->name, moderemove, i->second->nick };
52 ServerInstance->SendMode(parameters, 3, n);
57 void ModeChannelHalfOp::RemoveMode(userrec* user)
61 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
63 /* If halfops are not enabled in the conf, we don't execute
64 * anything in this class at all.
66 if (!ServerInstance->Config->AllowHalfop)
69 return MODEACTION_DENY;
72 int status = channel->GetStatus(source);
74 /* Call the correct method depending on wether we're adding or removing the mode */
77 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
81 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
83 /* If the method above 'ate' the parameter by reducing it to an empty string, then
84 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
85 * the return value and is always MODEACTION_DENY if the mode is supposed to have
88 if (parameter.length())
89 return MODEACTION_ALLOW;
91 return MODEACTION_DENY;
94 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
96 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
103 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
105 if (MOD_RESULT == ACR_DENY)
107 if (MOD_RESULT == ACR_DEFAULT)
109 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
111 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
117 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
122 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
124 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
131 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
133 if (MOD_RESULT == ACR_DENY)
135 if (MOD_RESULT == ACR_DEFAULT)
137 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
139 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
145 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);