]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modes / cmode_o.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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)
50 {
51         CUList* list = channel->GetOppedUsers();
52         CUList copy;
53         char moderemove[MAXBUF];
54
55         for (CUList::iterator i = list->begin(); i != list->end(); i++)
56         {
57                 User* n = i->first;
58                 copy.insert(std::make_pair(n,n->nick));
59         }
60
61         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
62         {
63                 sprintf(moderemove,"-%c",this->GetModeChar());
64                 const char* parameters[] = { channel->name, moderemove, i->first->nick };
65                 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
66         }
67 }
68
69 void ModeChannelOp::RemoveMode(User*)
70 {
71 }
72
73 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
74 {
75         int status = channel->GetStatus(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                         int MOD_RESULT = 0;
106                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
107
108                         if (MOD_RESULT == ACR_DENY)
109                                 return "";
110                         if (MOD_RESULT == ACR_DEFAULT)
111                         {
112                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
113                                 {
114                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
115                                         return "";
116                                 }
117                         }
118                 }
119
120                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
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                         int MOD_RESULT = 0;
134                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
135
136                         if (MOD_RESULT == ACR_DENY)
137                                 return "";
138                         if (MOD_RESULT == ACR_DEFAULT)
139                         {
140                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
141                                 {
142                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
143                                         return "";
144                                 }
145                         }
146                 }
147
148                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
149         }
150         return "";
151 }