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