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