]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
Spellig mistak.
[user/henk/code/inspircd.git] / src / modes / cmode_h.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 "configreader.h"
15 #include "inspircd.h"
16 #include "mode.h"
17 #include "channels.h"
18 #include "users.h"
19 #include "modules.h"
20 #include "modes/cmode_h.h"
21
22 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
23 {
24 }
25
26 unsigned int ModeChannelHalfOp::GetPrefixRank()
27 {
28         return HALFOP_VALUE;
29 }
30
31 ModePair ModeChannelHalfOp::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_HOP)
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 ModeChannelHalfOp::RemoveMode(chanrec* channel)
49 {
50         CUList* list = channel->GetHalfoppedUsers();
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->second;
59                 copy.insert(std::make_pair(n,n));
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->second->nick };
65                 ServerInstance->SendMode(parameters, 3, n);
66         }
67         delete n;
68 }
69
70 void ModeChannelHalfOp::RemoveMode(userrec* user)
71 {
72 }
73
74 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
75 {
76         /* If halfops are not enabled in the conf, we don't execute
77          * anything in this class at all.
78          */
79         if (!ServerInstance->Config->AllowHalfop)
80         {
81                 parameter = "";
82                 return MODEACTION_DENY;
83         }
84
85         int status = channel->GetStatus(source);
86
87         ServerInstance->Log(DEBUG,"Halfop handler, source=%s channel=%s parameter=%s adding=%d",source->nick, channel->name, parameter.c_str(), adding);
88
89         /* Call the correct method depending on wether we're adding or removing the mode */
90         if (adding)
91         {
92                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
93         }
94         else
95         {
96                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
97         }
98         /* If the method above 'ate' the parameter by reducing it to an empty string, then
99          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
100          * the return value and is always MODEACTION_DENY if the mode is supposed to have
101          * a parameter.
102          */
103         if (parameter.length())
104                 return MODEACTION_ALLOW;
105         else
106                 return MODEACTION_DENY;
107 }
108
109 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
110 {
111         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
112
113         ServerInstance->Log(DEBUG,"Add halfop");
114
115         if (d)
116         {
117                 if (IS_LOCAL(user))
118                 {
119                         int MOD_RESULT = 0;
120                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
121
122                         if (MOD_RESULT == ACR_DENY)
123                                 return "";
124                         if (MOD_RESULT == ACR_DEFAULT)
125                         {
126                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
127                                 {
128                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
129                                         return "";
130                                 }
131                         }
132                 }
133
134                 ServerInstance->Log(DEBUG,"Calling Grant");
135                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
136         }
137         return "";
138 }
139
140 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
141 {
142         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
143
144         ServerInstance->Log(DEBUG,"Del halfop");
145
146         if (d)
147         {
148                 if (IS_LOCAL(user))
149                 {
150                         int MOD_RESULT = 0;
151                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
152
153                         if (MOD_RESULT == ACR_DENY)
154                                 return "";
155                         if (MOD_RESULT == ACR_DEFAULT)
156                         {
157                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
158                                 {
159                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
160                                         return "";
161                                 }
162                         }
163                 }
164
165                 ServerInstance->Log(DEBUG,"Calling revoke");
166                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
167         }
168         return "";
169 }
170