]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Stripcolor not finished yet.
[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 extern ServerConfig* Config;
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 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
30 {
31         int status = cstatus(source, channel);
32
33         /* Call the correct method depending on wether we're adding or removing the mode */
34         if (adding)
35         {
36                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
37         }
38         else
39         {
40                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
41         }
42         /* If the method above 'ate' the parameter by reducing it to an empty string, then
43          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
44          * the return value and is always MODEACTION_DENY if the mode is supposed to have
45          * a parameter.
46          */
47         return MODEACTION_ALLOW;
48 }
49
50 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
51 {
52         userrec *d = ModeParser::SanityChecks(user,dest,chan,status);
53
54         if (d)
55         {
56                 if (IS_LOCAL(user))
57                 {
58                         int MOD_RESULT = 0;
59                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
60
61                         if (MOD_RESULT == ACR_DENY)
62                                 return "";
63                         if (MOD_RESULT == ACR_DEFAULT)
64                         {
65                                 if ((status < STATUS_OP) && (!is_uline(user->server)))
66                                 {
67                                         WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
68                                         return "";
69                                 }
70                         }
71                 }
72
73                 return ModeParser::Grant(d,chan,UCMODE_OP);
74         }
75         return "";
76 }
77
78 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
79 {
80         userrec *d = ModeParser::SanityChecks(user,dest,chan,status);
81
82         if (d)
83         {
84                 if (IS_LOCAL(user))
85                 {
86                         int MOD_RESULT = 0;
87                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
88
89                         if (MOD_RESULT == ACR_DENY)
90                                 return "";
91                         if (MOD_RESULT == ACR_DEFAULT)
92                         {
93                                 if ((status < STATUS_OP) && (!is_uline(user->server)) && (IS_LOCAL(user)))
94                                 {
95                                         WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
96                                         return "";
97                                 }
98                         }
99                 }
100
101                 return ModeParser::Revoke(d,chan,UCMODE_OP);
102         }
103         return "";
104 }