]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_v.cpp
a89f5705f2fa65d3458be8b7bf533cb98ad16b8d
[user/henk/code/inspircd.git] / src / modes / cmode_v.cpp
1
2 /*       +------------------------------------+
3  *       | Inspire Internet Relay Chat Daemon |
4  *       +------------------------------------+
5  *
6  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
7  * See: http://www.inspircd.org/wiki/index.php/Credits
8  *
9  * This program is free but copyrighted software; see
10  *            the file COPYING for details.
11  *
12  * ---------------------------------------------------
13  */
14
15 #include "inspircd.h"
16 #include "configreader.h"
17 #include "mode.h"
18 #include "channels.h"
19 #include "users.h"
20 #include "modules.h"
21 #include "modes/cmode_v.h"
22
23 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
24 {
25 }
26
27 unsigned int ModeChannelVoice::GetPrefixRank()
28 {
29         return VOICE_VALUE;
30 }
31
32 ModePair ModeChannelVoice::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
33 {
34         User* x = ServerInstance->FindNick(parameter);
35         if (x)
36         {
37                 if (channel->GetStatusFlags(x) & UCMODE_VOICE)
38                 {
39                         return std::make_pair(true, x->nick);
40                 }
41                 else
42                 {
43                         return std::make_pair(false, parameter);
44                 }
45         }
46         return std::make_pair(false, parameter);
47 }
48
49 void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
50 {
51         CUList* clist = channel->GetVoicedUsers();
52         CUList copy;
53
54         for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
55         {
56                 User* n = i->first;
57                 copy.insert(std::make_pair(n,n->nick));
58         }
59
60         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
61         {
62                 if (stack)
63                         stack->Push(this->GetModeChar(), i->first->nick);
64                 else
65                 {
66                         std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-v"); parameters.push_back(i->first->nick);
67                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
68                 }
69         }
70 }
71
72 void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
73 {
74 }
75
76 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
77 {
78         int status = channel->GetStatus(source);
79
80         /* Call the correct method depending on wether we're adding or removing the mode */
81         if (adding)
82         {
83                 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
84         }
85         else
86         {
87                 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
88         }
89         /* If the method above 'ate' the parameter by reducing it to an empty string, then
90          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
91          * the return value and is always MODEACTION_DENY if the mode is supposed to have
92          * a parameter.
93          */
94         if (parameter.length())
95                 return MODEACTION_ALLOW;
96         else
97                 return MODEACTION_DENY;
98 }
99
100 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
101 {
102         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
103
104         if (d)
105         {
106                 if (IS_LOCAL(user))
107                 {
108                         int MOD_RESULT = 0;
109                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
110
111                         if (MOD_RESULT == ACR_DENY)
112                                 return "";
113                         if (MOD_RESULT == ACR_DEFAULT)
114                         {
115                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
116                                 {
117                                         user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
118                                         return "";
119                                 }
120                         }
121                 }
122
123                 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
124         }
125         return "";
126 }
127
128 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
129 {
130         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
131
132         if (d)
133         {
134                 if (IS_LOCAL(user))
135                 {
136                         int MOD_RESULT = 0;
137                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
138
139                         if (MOD_RESULT == ACR_DENY)
140                                 return "";
141                         if (MOD_RESULT == ACR_DEFAULT)
142                         {
143                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
144                                 {
145                                         user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
146                                         return "";
147                                 }
148                         }
149                 }
150
151                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);
152         }
153         return "";
154 }