1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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, NULL, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%', '@', TR_NICK)
26 unsigned int ModeChannelHalfOp::GetPrefixRank()
31 ModePair ModeChannelHalfOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
33 User* x = ServerInstance->FindNick(parameter);
36 Membership* memb = channel->GetUser(x);
37 if (memb && memb->hasMode('h'))
39 return std::make_pair(true, x->nick);
43 return std::make_pair(false, x->nick);
46 return std::make_pair(false, parameter);
49 void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
51 const UserMembList* clist = channel->GetUsers();
53 for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
57 stack->Push(this->GetModeChar(), i->first->nick);
61 std::vector<std::string> parameters;
62 parameters.push_back(channel->name);
63 parameters.push_back("-h");
64 parameters.push_back(i->first->nick);
65 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
71 void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
75 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
77 int status = channel->GetPrefixValue(source);
79 /* Call the correct method depending on wether we're adding or removing the mode */
82 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
86 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
88 /* If the method above 'ate' the parameter by reducing it to an empty string, then
89 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
90 * the return value and is always MODEACTION_DENY if the mode is supposed to have
93 if (parameter.length())
94 return MODEACTION_ALLOW;
96 return MODEACTION_DENY;
99 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
101 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
107 ModResult MOD_RESULT;
108 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_HALFOP));
110 if (MOD_RESULT == MOD_RES_DENY)
112 if (MOD_RESULT == MOD_RES_PASSTHRU)
114 if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)))
116 user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
127 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
129 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
135 ModResult MOD_RESULT;
136 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEHALFOP));
138 if (MOD_RESULT == MOD_RES_DENY)
140 if (MOD_RESULT == MOD_RES_PASSTHRU)
142 if ((user != d) && ((status < OP_VALUE) && (!ServerInstance->ULine(user->server))))
144 user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());