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