]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[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 "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(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->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 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         /* Call the correct method depending on wether we're adding or removing the mode */
88         if (adding)
89         {
90                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
91         }
92         else
93         {
94                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
95         }
96         /* If the method above 'ate' the parameter by reducing it to an empty string, then
97          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
98          * the return value and is always MODEACTION_DENY if the mode is supposed to have
99          * a parameter.
100          */
101         if (parameter.length())
102                 return MODEACTION_ALLOW;
103         else
104                 return MODEACTION_DENY;
105 }
106
107 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
108 {
109         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
110
111         if (d)
112         {
113                 if (IS_LOCAL(user))
114                 {
115                         int MOD_RESULT = 0;
116                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
117
118                         if (MOD_RESULT == ACR_DENY)
119                                 return "";
120                         if (MOD_RESULT == ACR_DEFAULT)
121                         {
122                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
123                                 {
124                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
125                                         return "";
126                                 }
127                         }
128                 }
129
130                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
131         }
132         return "";
133 }
134
135 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
136 {
137         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
138
139         if (d)
140         {
141                 if (IS_LOCAL(user))
142                 {
143                         int MOD_RESULT = 0;
144                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
145
146                         if (MOD_RESULT == ACR_DENY)
147                                 return "";
148                         if (MOD_RESULT == ACR_DEFAULT)
149                         {
150                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
151                                 {
152                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
153                                         return "";
154                                 }
155                         }
156                 }
157
158                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
159         }
160         return "";
161 }
162