]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
667402ace458e82b3f145f82f1ce049732df3ad4
[user/henk/code/inspircd.git] / src / modes / cmode_h.cpp
1 #include "configreader.h"
2 #include "inspircd.h"
3 #include "mode.h"
4 #include "channels.h"
5 #include "users.h"
6 #include "modules.h"
7 #include "modes/cmode_h.h"
8
9 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
10 {
11 }
12
13 unsigned int ModeChannelHalfOp::GetPrefixRank()
14 {
15         return HALFOP_VALUE;
16 }
17
18 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
19 {
20         userrec* x = ServerInstance->FindNick(parameter);
21         if (x)
22         {
23                 if (channel->GetStatusFlags(x) & UCMODE_HOP)
24                 {
25                         return std::make_pair(true, x->nick);
26                 }
27                 else
28                 {
29                         return std::make_pair(false, parameter);
30                 }
31         }
32         return std::make_pair(false, parameter);
33 }
34
35 void ModeChannelHalfOp::RemoveMode(chanrec* channel)
36 {
37         CUList* list = channel->GetHalfoppedUsers();
38         CUList copy;
39         char moderemove[MAXBUF];
40         userrec* n = new userrec(ServerInstance);
41         n->SetFd(FD_MAGIC_NUMBER);
42
43         for (CUList::iterator i = list->begin(); i != list->end(); i++)
44         {
45                 userrec* n = i->second;
46                 copy.insert(std::make_pair(n,n));
47         }
48         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
49         {
50                 sprintf(moderemove,"-%c",this->GetModeChar());
51                 const char* parameters[] = { channel->name, moderemove, i->second->nick };
52                 ServerInstance->SendMode(parameters, 3, n);
53         }
54         delete n;
55 }
56
57 void ModeChannelHalfOp::RemoveMode(userrec* user)
58 {
59 }
60
61 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
62 {
63         /* If halfops are not enabled in the conf, we don't execute
64          * anything in this class at all.
65          */
66         if (!ServerInstance->Config->AllowHalfop)
67         {
68                 parameter = "";
69                 return MODEACTION_DENY;
70         }
71
72         int status = channel->GetStatus(source);
73
74         /* Call the correct method depending on wether we're adding or removing the mode */
75         if (adding)
76         {
77                 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
78         }
79         else
80         {
81                 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
82         }
83         /* If the method above 'ate' the parameter by reducing it to an empty string, then
84          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
85          * the return value and is always MODEACTION_DENY if the mode is supposed to have
86          * a parameter.
87          */
88         return MODEACTION_ALLOW;
89 }
90
91 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
92 {
93         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
94
95         if (d)
96         {
97                 if (IS_LOCAL(user))
98                 {
99                         int MOD_RESULT = 0;
100                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
101
102                         if (MOD_RESULT == ACR_DENY)
103                                 return "";
104                         if (MOD_RESULT == ACR_DEFAULT)
105                         {
106                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
107                                 {
108                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
109                                         return "";
110                                 }
111                         }
112                 }
113
114                 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
115         }
116         return "";
117 }
118
119 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
120 {
121         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
122
123         if (d)
124         {
125                 if (IS_LOCAL(user))
126                 {
127                         int MOD_RESULT = 0;
128                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
129
130                         if (MOD_RESULT == ACR_DENY)
131                                 return "";
132                         if (MOD_RESULT == ACR_DEFAULT)
133                         {
134                                 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
135                                 {
136                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
137                                         return "";
138                                 }
139                         }
140                 }
141
142                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
143         }
144         return "";
145 }
146