]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_v.cpp
Fixes for bug #493, tidyups to clearing of channel modes on losing FJOIN. Module...
[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, irc::modestacker* stack)
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                 if (stack)
64                         stack->Push(this->GetModeChar(), i->first->nick);
65                 else
66                 {
67                         sprintf(moderemove,"-%c",this->GetModeChar());
68                         const char* parameters[] = { channel->name, moderemove, i->first->nick };
69                         ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
70                 }
71         }
72 }
73
74 void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
75 {
76 }
77
78 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
79 {
80         int status = channel->GetStatus(source);
81
82         /* Call the correct method depending on wether we're adding or removing the mode */
83         if (adding)
84         {
85                 parameter = this->AddVoice(source, parameter.c_str(), channel, status);
86         }
87         else
88         {
89                 parameter = this->DelVoice(source, parameter.c_str(), channel, status);
90         }
91         /* If the method above 'ate' the parameter by reducing it to an empty string, then
92          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
93          * the return value and is always MODEACTION_DENY if the mode is supposed to have
94          * a parameter.
95          */
96         if (parameter.length())
97                 return MODEACTION_ALLOW;
98         else
99                 return MODEACTION_DENY;
100 }
101
102 std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
103 {
104         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
105
106         if (d)
107         {
108                 if (IS_LOCAL(user))
109                 {
110                         int MOD_RESULT = 0;
111                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
112
113                         if (MOD_RESULT == ACR_DENY)
114                                 return "";
115                         if (MOD_RESULT == ACR_DEFAULT)
116                         {
117                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
118                                 {
119                                         user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, chan->name);
120                                         return "";
121                                 }
122                         }
123                 }
124
125                 return ServerInstance->Modes->Grant(d,chan,UCMODE_VOICE);
126         }
127         return "";
128 }
129
130 std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
131 {
132         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
133
134         if (d)
135         {
136                 if (IS_LOCAL(user))
137                 {
138                         int MOD_RESULT = 0;
139                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
140
141                         if (MOD_RESULT == ACR_DENY)
142                                 return "";
143                         if (MOD_RESULT == ACR_DEFAULT)
144                         {
145                                 if ((status < STATUS_HOP) && (!ServerInstance->ULine(user->server)))
146                                 {
147                                         user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick, chan->name);
148                                         return "";
149                                 }
150                         }
151                 }
152
153                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_VOICE);
154         }
155         return "";
156 }