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