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