]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modes / cmode_h.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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_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(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_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(Channel* channel)
49 {
50         CUList* list = channel->GetHalfoppedUsers();
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
69 void ModeChannelHalfOp::RemoveMode(User*)
70 {
71 }
72
73 ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
74 {
75         /* If halfops are not enabled in the conf, we don't execute
76          * anything in this class at all.
77          */
78         if (!ServerInstance->Config->AllowHalfop)
79         {
80                 parameter = "";
81                 return MODEACTION_DENY;
82         }
83
84         int status = channel->GetStatus(source);
85
86         /* Call the correct method depending on wether we're adding or removing the mode */
87         if (adding)
88         {
89                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
90         }
91         else
92         {
93                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
94         }
95         /* If the method above 'ate' the parameter by reducing it to an empty string, then
96          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
97          * the return value and is always MODEACTION_DENY if the mode is supposed to have
98          * a parameter.
99          */
100         if (parameter.length())
101                 return MODEACTION_ALLOW;
102         else
103                 return MODEACTION_DENY;
104 }
105
106 std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
107 {
108         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
109
110         if (d)
111         {
112                 if (IS_LOCAL(user))
113                 {
114                         int MOD_RESULT = 0;
115                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
116
117                         if (MOD_RESULT == ACR_DENY)
118                                 return "";
119                         if (MOD_RESULT == ACR_DEFAULT)
120                         {
121                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
122                                 {
123                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
124                                         return "";
125                                 }
126                         }
127                 }
128
129                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
130         }
131         return "";
132 }
133
134 std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
135 {
136         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
137
138         if (d)
139         {
140                 if (IS_LOCAL(user))
141                 {
142                         int MOD_RESULT = 0;
143                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
144
145                         if (MOD_RESULT == ACR_DENY)
146                                 return "";
147                         if (MOD_RESULT == ACR_DEFAULT)
148                         {
149                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
150                                 {
151                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
152                                         return "";
153                                 }
154                         }
155                 }
156
157                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
158         }
159         return "";
160 }
161