]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Actually make +ovhk removable with DelMode (just in case somebody wants to, or we...
[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
36 void ModeChannelOp::RemoveMode(chanrec* channel)
37 {
38         CUList* list = channel->GetOppedUsers();
39         CUList copy;
40         char moderemove[MAXBUF];
41         userrec* n = new userrec(ServerInstance);
42         n->SetFd(FD_MAGIC_NUMBER);
43
44         for (CUList::iterator i = list->begin(); i != list->end(); i++)
45         {
46                 userrec* n = i->second;
47                 copy.insert(std::make_pair(n,n));
48         }
49         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
50         {
51                 sprintf(moderemove,"-%c",this->GetModeChar());
52                 const char* parameters[] = { channel->name, moderemove, i->second->nick };
53                 ServerInstance->SendMode(parameters, 3, n);
54         }
55         delete n;
56 }
57
58 void ModeChannelOp::RemoveMode(userrec* user)
59 {
60 }
61
62 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
63 {
64         int status = channel->GetStatus(source);
65
66         /* Call the correct method depending on wether we're adding or removing the mode */
67         if (adding)
68         {
69                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
70         }
71         else
72         {
73                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
74         }
75         /* If the method above 'ate' the parameter by reducing it to an empty string, then
76          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
77          * the return value and is always MODEACTION_DENY if the mode is supposed to have
78          * a parameter.
79          */
80         return MODEACTION_ALLOW;
81 }
82
83 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
84 {
85         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
86
87         if (d)
88         {
89                 if (IS_LOCAL(user))
90                 {
91                         int MOD_RESULT = 0;
92                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
93
94                         if (MOD_RESULT == ACR_DENY)
95                                 return "";
96                         if (MOD_RESULT == ACR_DEFAULT)
97                         {
98                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
99                                 {
100                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
101                                         return "";
102                                 }
103                         }
104                 }
105
106                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
107         }
108         return "";
109 }
110
111 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
112 {
113         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
114
115         if (d)
116         {
117                 if (IS_LOCAL(user))
118                 {
119                         int MOD_RESULT = 0;
120                         ServerInstance->Log(DEBUG,"Call OnAccessCheck for AC_DEOP");
121                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
122
123                         ServerInstance->Log(DEBUG,"Returns %d",MOD_RESULT);
124
125                         if (MOD_RESULT == ACR_DENY)
126                                 return "";
127                         if (MOD_RESULT == ACR_DEFAULT)
128                         {
129                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
130                                 {
131                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
132                                         return "";
133                                 }
134                         }
135                 }
136
137                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
138         }
139         return "";
140 }