]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_v.cpp
7b14d84d435552bfd6a17405ae203a50d6e65d54
[user/henk/code/inspircd.git] / src / modes / cmode_v.cpp
1 #include <string>
2 #include <vector>
3 #include "inspircd_config.h"
4 #include "configreader.h"
5 #include "hash_map.h"
6 #include "inspircd.h"
7 #include "mode.h"
8 #include "channels.h"
9 #include "users.h"
10
11 #include "commands.h"
12 #include "modules.h"
13 #include "inspstring.h"
14 #include "hashcomp.h"
15 #include "modes/cmode_v.h"
16
17 ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
18 {
19 }
20
21 unsigned int ModeChannelVoice::GetPrefixRank()
22 {
23         return VOICE_VALUE;
24 }
25
26 ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
27 {
28         userrec* x = ServerInstance->FindNick(parameter);
29         if (x)
30         {
31                 if (channel->GetStatus(x) == STATUS_VOICE)
32                 {
33                         return std::make_pair(true, x->nick);
34                 }
35                 else
36                 {
37                         return std::make_pair(false, parameter);
38                 }
39         }
40         return std::make_pair(false, parameter);
41 }
42
43 ModeAction ModeChannelVoice::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
44 {
45         int status = channel->GetStatus(source);
46
47         /* Call the correct method depending on wether we're adding or removing the mode */
48         if (adding)
49         {
50                 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
51         }
52         else
53         {
54                 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
55         }
56         /* If the method above 'ate' the parameter by reducing it to an empty string, then
57          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
58          * the return value and is always MODEACTION_DENY if the mode is supposed to have
59          * a parameter.
60          */
61         return MODEACTION_ALLOW;
62 }
63
64 std::string ModeChannelVoice::AddVoice(userrec *user,const char* dest,chanrec *chan,int status)
65 {
66         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
67
68         if (d)
69         {
70                 if (IS_LOCAL(user))
71                 {
72                         int MOD_RESULT = 0;
73                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
74
75                         if (MOD_RESULT == ACR_DENY)
76                                 return "";
77                         if (MOD_RESULT == ACR_DEFAULT)
78                         {
79                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
80                                 {
81                                         user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
82                                         return "";
83                                 }
84                         }
85                 }
86
87                 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
88         }
89         return "";
90 }
91
92 std::string ModeChannelVoice::DelVoice(userrec *user,const char *dest,chanrec *chan,int status)
93 {
94         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
95
96         if (d)
97         {
98                 if (IS_LOCAL(user))
99                 {
100                         int MOD_RESULT = 0;
101                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
102
103                         if (MOD_RESULT == ACR_DENY)
104                                 return "";
105                         if (MOD_RESULT == ACR_DEFAULT)
106                         {
107                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
108                                 {
109                                         user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
110                                         return "";
111                                 }
112                         }
113                 }
114
115                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);
116         }
117         return "";
118 }