2 /* +------------------------------------+
3 * | Inspire Internet Relay Chat Daemon |
4 * +------------------------------------+
6 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
7 * See: http://www.inspircd.org/wiki/index.php/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, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
27 unsigned int ModeChannelVoice::GetPrefixRank()
32 ModePair ModeChannelVoice::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
34 User* x = ServerInstance->FindNick(parameter);
37 if (channel->GetStatusFlags(x) & UCMODE_VOICE)
39 return std::make_pair(true, x->nick);
43 return std::make_pair(false, parameter);
46 return std::make_pair(false, parameter);
49 void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
51 CUList* clist = channel->GetVoicedUsers();
53 char moderemove[MAXBUF];
55 for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
58 copy.insert(std::make_pair(n,n->nick));
61 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
64 stack->Push(this->GetModeChar(), i->first->nick);
67 sprintf(moderemove,"-%c",this->GetModeChar());
68 const char* parameters[] = { channel->name, moderemove, i->first->nick };
69 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
74 void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
78 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
80 int status = channel->GetStatus(source);
82 /* Call the correct method depending on wether we're adding or removing the mode */
85 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
89 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
91 /* If the method above 'ate' the parameter by reducing it to an empty string, then
92 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
93 * the return value and is always MODEACTION_DENY if the mode is supposed to have
96 if (parameter.length())
97 return MODEACTION_ALLOW;
99 return MODEACTION_DENY;
102 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
104 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
111 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
113 if (MOD_RESULT == ACR_DENY)
115 if (MOD_RESULT == ACR_DEFAULT)
117 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
119 user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
125 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
130 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
132 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
139 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
141 if (MOD_RESULT == ACR_DENY)
143 if (MOD_RESULT == ACR_DEFAULT)
145 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
147 user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
153 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);