]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
9da9fa4783bbb9a8d189cbc817600e31b8ef0c17
[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://wiki.inspircd.org/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, NULL, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@', '@', TR_NICK)
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                 Membership* memb = channel->GetUser(x);
37                 if (memb && memb->hasMode('o'))
38                 {
39                         return std::make_pair(true, x->nick);
40                 }
41                 else
42                 {
43                         return std::make_pair(false, parameter);
44                 }
45         }
46         return std::make_pair(false, parameter);
47 }
48
49
50 void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
51 {
52         const UserMembList* clist = channel->GetUsers();
53
54         for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
55         {
56                 if (stack)
57                         stack->Push(this->GetModeChar(), i->first->nick);
58                 else
59                 {
60                         std::vector<std::string> parameters;
61                         parameters.push_back(channel->name);
62                         parameters.push_back("-o");
63                         parameters.push_back(i->first->nick);
64                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
65                 }
66         }
67 }
68
69 void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
70 {
71 }
72
73 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
74 {
75         int status = channel->GetPrefixValue(source);
76
77         /* Call the correct method depending on wether we're adding or removing the mode */
78         if (adding)
79         {
80                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
81         }
82         else
83         {
84                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
85         }
86         /* If the method above 'ate' the parameter by reducing it to an empty string, then
87          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
88          * the return value and is always MODEACTION_DENY if the mode is supposed to have
89          * a parameter.
90          */
91         if (parameter.length())
92                 return MODEACTION_ALLOW;
93         else
94                 return MODEACTION_DENY;
95 }
96
97 std::string ModeChannelOp::AddOp(User *user,const char* dest,Channel *chan,int status)
98 {
99         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
100
101         if (d)
102         {
103                 if (IS_LOCAL(user))
104                 {
105                         ModResult MOD_RESULT;
106                         FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_OP));
107
108                         if (MOD_RESULT == MOD_RES_DENY)
109                                 return "";
110                         if (MOD_RESULT == MOD_RES_PASSTHRU)
111                         {
112                                 if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)))
113                                 {
114                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
115                                         return "";
116                                 }
117                         }
118                 }
119
120                 return d->nick;
121         }
122         return "";
123 }
124
125 std::string ModeChannelOp::DelOp(User *user,const char *dest,Channel *chan,int status)
126 {
127         User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
128
129         if (d)
130         {
131                 if (IS_LOCAL(user))
132                 {
133                         ModResult MOD_RESULT;
134                         FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEOP));
135
136                         if (MOD_RESULT == MOD_RES_DENY)
137                                 return "";
138                         if (MOD_RESULT == MOD_RES_PASSTHRU)
139                         {
140                                 if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
141                                 {
142                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
143                                         return "";
144                                 }
145                         }
146                 }
147
148                 return d->nick;
149         }
150         return "";
151 }