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