]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Update copyrights for 2009.
[user/henk/code/inspircd.git] / src / modes / cmode_o.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "configreader.h"
16 #include "mode.h"
17 #include "channels.h"
18 #include "users.h"
19 #include "modules.h"
20 #include "modes/cmode_o.h"
21
22 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@', '@')
23 {
24 }
25
26 unsigned int ModeChannelOp::GetPrefixRank()
27 {
28         return OP_VALUE;
29 }
30
31 ModePair ModeChannelOp::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
32 {
33         User* x = ServerInstance->FindNick(parameter);
34         if (x)
35         {
36                 if (channel->GetStatusFlags(x) & UCMODE_OP)
37                 {
38                         return std::make_pair(true, x->nick);
39                 }
40                 else
41                 {
42                         return std::make_pair(false, parameter);
43                 }
44         }
45         return std::make_pair(false, parameter);
46 }
47
48
49 void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
50 {
51         CUList* clist = channel->GetOppedUsers();
52         CUList copy;
53
54         for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
55         {
56                 User* n = i->first;
57                 copy.insert(std::make_pair(n,n->nick));
58         }
59
60         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
61         {
62                 if (stack)
63                         stack->Push(this->GetModeChar(), i->first->nick);
64                 else
65                 {
66                         std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-o"); parameters.push_back(i->first->nick);
67                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
68                 }
69         }
70 }
71
72 void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
73 {
74 }
75
76 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
77 {
78         int status = channel->GetStatus(source);
79
80         /* Call the correct method depending on wether we're adding or removing the mode */
81         if (adding)
82         {
83                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
84         }
85         else
86         {
87                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
88         }
89         /* If the method above 'ate' the parameter by reducing it to an empty string, then
90          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
91          * the return value and is always MODEACTION_DENY if the mode is supposed to have
92          * a parameter.
93          */
94         if (parameter.length())
95                 return MODEACTION_ALLOW;
96         else
97                 return MODEACTION_DENY;
98 }
99
100 std::string ModeChannelOp::AddOp(User *user,const char* dest,Channel *chan,int status)
101 {
102         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
103
104         if (d)
105         {
106                 if (IS_LOCAL(user))
107                 {
108                         int MOD_RESULT = 0;
109                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
110
111                         if (MOD_RESULT == ACR_DENY)
112                                 return "";
113                         if (MOD_RESULT == ACR_DEFAULT)
114                         {
115                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
116                                 {
117                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
118                                         return "";
119                                 }
120                         }
121                 }
122
123                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
124         }
125         return "";
126 }
127
128 std::string ModeChannelOp::DelOp(User *user,const char *dest,Channel *chan,int status)
129 {
130         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
131
132         if (d)
133         {
134                 if (IS_LOCAL(user))
135                 {
136                         int MOD_RESULT = 0;
137                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
138
139                         if (MOD_RESULT == ACR_DENY)
140                                 return "";
141                         if (MOD_RESULT == ACR_DEFAULT)
142                         {
143                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
144                                 {
145                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
146                                         return "";
147                                 }
148                         }
149                 }
150
151                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
152         }
153         return "";
154 }