00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "inspircd.h"
00016 #include "configreader.h"
00017 #include "mode.h"
00018 #include "channels.h"
00019 #include "users.h"
00020 #include "modules.h"
00021 #include "modes/cmode_v.h"
00022
00023 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
00024 {
00025 }
00026
00027 unsigned int ModeChannelVoice::GetPrefixRank()
00028 {
00029 return VOICE_VALUE;
00030 }
00031
00032 ModePair ModeChannelVoice::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
00033 {
00034 User* x = ServerInstance->FindNick(parameter);
00035 if (x)
00036 {
00037 if (channel->GetStatusFlags(x) & UCMODE_VOICE)
00038 {
00039 return std::make_pair(true, x->nick);
00040 }
00041 else
00042 {
00043 return std::make_pair(false, parameter);
00044 }
00045 }
00046 return std::make_pair(false, parameter);
00047 }
00048
00049 void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
00050 {
00051 CUList* clist = channel->GetVoicedUsers();
00052 CUList copy;
00053
00054 for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
00055 {
00056 User* n = i->first;
00057 copy.insert(std::make_pair(n,n->nick));
00058 }
00059
00060 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
00061 {
00062 if (stack)
00063 stack->Push(this->GetModeChar(), i->first->nick);
00064 else
00065 {
00066 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-v"); parameters.push_back(i->first->nick);
00067 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
00068 }
00069 }
00070 }
00071
00072 void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
00073 {
00074 }
00075
00076 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
00077 {
00078 int status = channel->GetStatus(source);
00079
00080
00081 if (adding)
00082 {
00083 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
00084 }
00085 else
00086 {
00087 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
00088 }
00089
00090
00091
00092
00093
00094 if (parameter.length())
00095 return MODEACTION_ALLOW;
00096 else
00097 return MODEACTION_DENY;
00098 }
00099
00100 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
00101 {
00102 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
00103
00104 if (d)
00105 {
00106 if (IS_LOCAL(user))
00107 {
00108 int MOD_RESULT = 0;
00109 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
00110
00111 if (MOD_RESULT == ACR_DENY)
00112 return "";
00113 if (MOD_RESULT == ACR_DEFAULT)
00114 {
00115 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
00116 {
00117 user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
00118 return "";
00119 }
00120 }
00121 }
00122
00123 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
00124 }
00125 return "";
00126 }
00127
00128 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
00129 {
00130 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
00131
00132 if (d)
00133 {
00134 if (IS_LOCAL(user))
00135 {
00136 int MOD_RESULT = 0;
00137 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
00138
00139 if (MOD_RESULT == ACR_DENY)
00140 return "";
00141 if (MOD_RESULT == ACR_DEFAULT)
00142 {
00143 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
00144 {
00145 user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
00146 return "";
00147 }
00148 }
00149 }
00150
00151 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);
00152 }
00153 return "";
00154 }