]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[user/henk/code/inspircd.git] / src / modes / cmode_o.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_o.h"
8
9 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@')
10 {
11 }
12
13 unsigned int ModeChannelOp::GetPrefixRank()
14 {
15         return OP_VALUE;
16 }
17
18 ModePair ModeChannelOp::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_OP)
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 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
36 {
37         int status = channel->GetStatus(source);
38
39         /* Call the correct method depending on wether we're adding or removing the mode */
40         if (adding)
41         {
42                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
43         }
44         else
45         {
46                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
47         }
48         /* If the method above 'ate' the parameter by reducing it to an empty string, then
49          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
50          * the return value and is always MODEACTION_DENY if the mode is supposed to have
51          * a parameter.
52          */
53         return MODEACTION_ALLOW;
54 }
55
56 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
57 {
58         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
59
60         if (d)
61         {
62                 if (IS_LOCAL(user))
63                 {
64                         int MOD_RESULT = 0;
65                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
66
67                         if (MOD_RESULT == ACR_DENY)
68                                 return "";
69                         if (MOD_RESULT == ACR_DEFAULT)
70                         {
71                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
72                                 {
73                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
74                                         return "";
75                                 }
76                         }
77                 }
78
79                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
80         }
81         return "";
82 }
83
84 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
85 {
86         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
87
88         if (d)
89         {
90                 if (IS_LOCAL(user))
91                 {
92                         int MOD_RESULT = 0;
93                         ServerInstance->Log(DEBUG,"Call OnAccessCheck for AC_DEOP");
94                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
95
96                         ServerInstance->Log(DEBUG,"Returns %d",MOD_RESULT);
97
98                         if (MOD_RESULT == ACR_DENY)
99                                 return "";
100                         if (MOD_RESULT == ACR_DEFAULT)
101                         {
102                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
103                                 {
104                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
105                                         return "";
106                                 }
107                         }
108                 }
109
110                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
111         }
112         return "";
113 }