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