1 #include "configreader.h"
7 #include "modes/cmode_v.h"
9 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
13 unsigned int ModeChannelVoice::GetPrefixRank()
18 ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
20 userrec* x = ServerInstance->FindNick(parameter);
23 if (channel->GetStatusFlags(x) & UCMODE_VOICE)
25 return std::make_pair(true, x->nick);
29 return std::make_pair(false, parameter);
32 return std::make_pair(false, parameter);
35 void ModeChannelVoice::RemoveMode(chanrec* channel)
37 CUList* list = channel->GetVoicedUsers();
39 char moderemove[MAXBUF];
40 userrec* n = new userrec(ServerInstance);
41 n->SetFd(FD_MAGIC_NUMBER);
43 for (CUList::iterator i = list->begin(); i != list->end(); i++)
45 userrec* n = i->second;
46 copy.insert(std::make_pair(n,n));
48 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
50 sprintf(moderemove,"-%c",this->GetModeChar());
51 const char* parameters[] = { channel->name, moderemove, i->second->nick };
52 ServerInstance->SendMode(parameters, 3, n);
57 void ModeChannelVoice::RemoveMode(userrec* user)
61 ModeAction ModeChannelVoice::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
63 int status = channel->GetStatus(source);
65 /* Call the correct method depending on wether we're adding or removing the mode */
68 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
72 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
74 /* If the method above 'ate' the parameter by reducing it to an empty string, then
75 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
76 * the return value and is always MODEACTION_DENY if the mode is supposed to have
79 if (parameter.length())
80 return MODEACTION_ALLOW;
82 return MODEACTION_DENY;
85 std::string ModeChannelVoice::AddVoice(userrec *user,const char* dest,chanrec *chan,int status)
87 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
94 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
96 if (MOD_RESULT == ACR_DENY)
98 if (MOD_RESULT == ACR_DEFAULT)
100 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
102 user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
108 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
113 std::string ModeChannelVoice::DelVoice(userrec *user,const char *dest,chanrec *chan,int status)
115 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
122 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
124 if (MOD_RESULT == ACR_DENY)
126 if (MOD_RESULT == ACR_DEFAULT)
128 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
130 user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
136 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);