]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_v.cpp
45a9e1879cefe5c963eb400e91cc28508dfe29a3
[user/henk/code/inspircd.git] / src / modes / cmode_v.cpp
1
2 /*       +------------------------------------+
3  *       | Inspire Internet Relay Chat Daemon |
4  *       +------------------------------------+
5  *
6  *  InspIRCd: (C) 2002-2008 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)
50 {
51         CUList* clist = channel->GetVoicedUsers();
52         CUList copy;
53         char moderemove[MAXBUF];
54
55         for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
56         {
57                 User* n = i->first;
58                 copy.insert(std::make_pair(n,n->nick));
59         }
60
61         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
62         {
63                 sprintf(moderemove,"-%c",this->GetModeChar());
64                 const char* parameters[] = { channel->name, moderemove, i->first->nick };
65                 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
66         }
67 }
68
69 void ModeChannelVoice::RemoveMode(User*)
70 {
71 }
72
73 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
74 {
75         int status = channel->GetStatus(source);
76
77         /* Call the correct method depending on wether we're adding or removing the mode */
78         if (adding)
79         {
80                 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
81         }
82         else
83         {
84                 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
85         }
86         /* If the method above 'ate' the parameter by reducing it to an empty string, then
87          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
88          * the return value and is always MODEACTION_DENY if the mode is supposed to have
89          * a parameter.
90          */
91         if (parameter.length())
92                 return MODEACTION_ALLOW;
93         else
94                 return MODEACTION_DENY;
95 }
96
97 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
98 {
99         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
100
101         if (d)
102         {
103                 if (IS_LOCAL(user))
104                 {
105                         int MOD_RESULT = 0;
106                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
107
108                         if (MOD_RESULT == ACR_DENY)
109                                 return "";
110                         if (MOD_RESULT == ACR_DEFAULT)
111                         {
112                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
113                                 {
114                                         user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
115                                         return "";
116                                 }
117                         }
118                 }
119
120                 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
121         }
122         return "";
123 }
124
125 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
126 {
127         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
128
129         if (d)
130         {
131                 if (IS_LOCAL(user))
132                 {
133                         int MOD_RESULT = 0;
134                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
135
136                         if (MOD_RESULT == ACR_DENY)
137                                 return "";
138                         if (MOD_RESULT == ACR_DEFAULT)
139                         {
140                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
141                                 {
142                                         user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
143                                         return "";
144                                 }
145                         }
146                 }
147
148                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);
149         }
150         return "";
151 }