]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
So much stuff changed in this one, i forgot most of it.
[user/henk/code/inspircd.git] / src / modes / cmode_o.cpp
1 #include <string>
2 #include <vector>
3 #include "inspircd_config.h"
4 #include "configreader.h"
5 #include "hash_map.h"
6 #include "inspircd.h"
7 #include "mode.h"
8 #include "channels.h"
9 #include "users.h"
10 #include "helperfuncs.h"
11 #include "commands.h"
12 #include "modules.h"
13 #include "inspstring.h"
14 #include "hashcomp.h"
15 #include "modes/cmode_o.h"
16
17 extern time_t TIME;
18
19 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false)
20 {
21 }
22
23 ModePair ModeChannelOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
24 {
25         userrec* x = ServerInstance->FindNick(parameter);
26         if (x)
27         {
28                 if (channel->GetStatus(x) == STATUS_OP)
29                 {
30                         return std::make_pair(true, x->nick);
31                 }
32                 else
33                 {
34                         return std::make_pair(false, parameter);
35                 }
36         }
37         return std::make_pair(false, parameter);
38 }
39
40 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
41 {
42         int status = channel->GetStatus(source);
43
44         /* Call the correct method depending on wether we're adding or removing the mode */
45         if (adding)
46         {
47                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
48         }
49         else
50         {
51                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
52         }
53         /* If the method above 'ate' the parameter by reducing it to an empty string, then
54          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
55          * the return value and is always MODEACTION_DENY if the mode is supposed to have
56          * a parameter.
57          */
58         return MODEACTION_ALLOW;
59 }
60
61 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
62 {
63         userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
64
65         if (d)
66         {
67                 if (IS_LOCAL(user))
68                 {
69                         int MOD_RESULT = 0;
70                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
71
72                         if (MOD_RESULT == ACR_DENY)
73                                 return "";
74                         if (MOD_RESULT == ACR_DEFAULT)
75                         {
76                                 if ((status < STATUS_OP) && (!is_uline(user->server)))
77                                 {
78                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
79                                         return "";
80                                 }
81                         }
82                 }
83
84                 return ServerInstance->ModeGrok->Grant(d,chan,UCMODE_OP);
85         }
86         return "";
87 }
88
89 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
90 {
91         userrec *d = ServerInstance->ModeGrok->SanityChecks(user,dest,chan,status);
92
93         if (d)
94         {
95                 if (IS_LOCAL(user))
96                 {
97                         int MOD_RESULT = 0;
98                         log(DEBUG,"Call OnAccessCheck for AC_DEOP");
99                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
100
101                         log(DEBUG,"Returns %d",MOD_RESULT);
102
103                         if (MOD_RESULT == ACR_DENY)
104                                 return "";
105                         if (MOD_RESULT == ACR_DEFAULT)
106                         {
107                                 if ((status < STATUS_OP) && (!is_uline(user->server)) && (IS_LOCAL(user)))
108                                 {
109                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
110                                         return "";
111                                 }
112                         }
113                 }
114
115                 return ServerInstance->ModeGrok->Revoke(d,chan,UCMODE_OP);
116         }
117         return "";
118 }