2 /* +------------------------------------+
3 * | Inspire Internet Relay Chat Daemon |
4 * +------------------------------------+
6 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
7 * See: http://wiki.inspircd.org/Credits
9 * This program is free but copyrighted software; see
10 * the file COPYING for details.
12 * ---------------------------------------------------
16 #include "configreader.h"
21 #include "modes/cmode_v.h"
23 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, NULL, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+', '%', TR_NICK)
27 unsigned int ModeChannelVoice::GetPrefixRank()
32 ModePair ModeChannelVoice::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
34 User* x = ServerInstance->FindNick(parameter);
37 Membership* memb = channel->GetUser(x);
38 if (memb && memb->hasMode('v'))
40 return std::make_pair(true, x->nick);
44 return std::make_pair(false, parameter);
47 return std::make_pair(false, parameter);
50 void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
52 const UserMembList* clist = channel->GetUsers();
54 for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
57 stack->Push(this->GetModeChar(), i->first->nick);
60 std::vector<std::string> parameters;
61 parameters.push_back(channel->name);
62 parameters.push_back("-v");
63 parameters.push_back(i->first->nick);
64 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
69 void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
73 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
75 int status = channel->GetPrefixValue(source);
77 /* Call the correct method depending on wether we're adding or removing the mode */
80 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
84 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
86 /* If the method above 'ate' the parameter by reducing it to an empty string, then
87 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
88 * the return value and is always MODEACTION_DENY if the mode is supposed to have
91 if (parameter.length())
92 return MODEACTION_ALLOW;
94 return MODEACTION_DENY;
97 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
99 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
105 ModResult MOD_RESULT;
106 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_VOICE));
108 if (MOD_RESULT == MOD_RES_DENY)
110 if (MOD_RESULT == MOD_RES_PASSTHRU)
112 if ((status < HALFOP_VALUE) && (!ServerInstance->ULine(user->server)))
114 user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
125 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
127 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
133 ModResult MOD_RESULT;
134 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEVOICE));
136 if (MOD_RESULT == MOD_RES_DENY)
138 if (MOD_RESULT == MOD_RES_PASSTHRU)
140 if ((status < HALFOP_VALUE) && (!ServerInstance->ULine(user->server)))
142 user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick.c_str(), chan->name.c_str());