1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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_v.h"
22 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
26 unsigned int ModeChannelVoice::GetPrefixRank()
31 ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
33 userrec* x = ServerInstance->FindNick(parameter);
36 if (channel->GetStatusFlags(x) & UCMODE_VOICE)
38 return std::make_pair(true, x->nick);
42 return std::make_pair(false, parameter);
45 return std::make_pair(false, parameter);
48 void ModeChannelVoice::RemoveMode(chanrec* channel)
50 CUList* list = channel->GetVoicedUsers();
52 char moderemove[MAXBUF];
54 for (CUList::iterator i = list->begin(); i != list->end(); i++)
56 userrec* n = i->first;
57 copy.insert(std::make_pair(n,n->nick));
60 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
62 sprintf(moderemove,"-%c",this->GetModeChar());
63 const char* parameters[] = { channel->name, moderemove, i->first->nick };
64 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
68 void ModeChannelVoice::RemoveMode(userrec* user)
72 ModeAction ModeChannelVoice::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
74 int status = channel->GetStatus(source);
76 /* Call the correct method depending on wether we're adding or removing the mode */
79 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
83 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
85 /* If the method above 'ate' the parameter by reducing it to an empty string, then
86 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
87 * the return value and is always MODEACTION_DENY if the mode is supposed to have
90 if (parameter.length())
91 return MODEACTION_ALLOW;
93 return MODEACTION_DENY;
96 std::string ModeChannelVoice::AddVoice(userrec *user,const char* dest,chanrec *chan,int status)
98 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
105 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
107 if (MOD_RESULT == ACR_DENY)
109 if (MOD_RESULT == ACR_DEFAULT)
111 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
113 user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
119 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
124 std::string ModeChannelVoice::DelVoice(userrec *user,const char *dest,chanrec *chan,int status)
126 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
133 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
135 if (MOD_RESULT == ACR_DENY)
137 if (MOD_RESULT == ACR_DEFAULT)
139 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
141 user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
147 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);