1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "configreader.h"
20 #include "modes/cmode_h.h"
22 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%', '@')
26 unsigned int ModeChannelHalfOp::GetPrefixRank()
31 ModePair ModeChannelHalfOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
33 User* x = ServerInstance->FindNick(parameter);
36 if (channel->GetStatusFlags(x) & UCMODE_HOP)
38 return std::make_pair(true, x->nick);
42 return std::make_pair(false, parameter);
45 return std::make_pair(false, parameter);
48 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
50 CUList* clist = channel->GetHalfoppedUsers();
52 char moderemove[MAXBUF];
54 for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
57 copy.insert(std::make_pair(n,n->nick));
60 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
64 stack->Push(this->GetModeChar(), i->first->nick);
68 sprintf(moderemove,"-%c",this->GetModeChar());
69 const char* parameters[] = { channel->name, moderemove, i->first->nick };
70 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
76 void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
80 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
82 /* If halfops are not enabled in the conf, we don't execute
83 * anything in this class at all.
85 if (!ServerInstance->Config->AllowHalfop)
88 return MODEACTION_DENY;
91 int status = channel->GetStatus(source);
93 /* Call the correct method depending on wether we're adding or removing the mode */
96 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
100 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
102 /* If the method above 'ate' the parameter by reducing it to an empty string, then
103 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
104 * the return value and is always MODEACTION_DENY if the mode is supposed to have
107 if (parameter.length())
108 return MODEACTION_ALLOW;
110 return MODEACTION_DENY;
113 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
115 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
122 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
124 if (MOD_RESULT == ACR_DENY)
126 if (MOD_RESULT == ACR_DEFAULT)
128 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
130 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
136 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
141 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
143 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
150 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
152 if (MOD_RESULT == ACR_DENY)
154 if (MOD_RESULT == ACR_DEFAULT)
156 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
158 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
164 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);