]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
Add strerror(errno) to port bind failure on TreeSocket
[user/henk/code/inspircd.git] / src / modes / cmode_o.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "configreader.h"
15 #include "inspircd.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(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
32 {
33         userrec* 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(chanrec* channel)
50 {
51         CUList* list = channel->GetOppedUsers();
52         CUList copy;
53         char moderemove[MAXBUF];
54         userrec* n = new userrec(ServerInstance);
55         n->SetFd(FD_MAGIC_NUMBER);
56
57         for (CUList::iterator i = list->begin(); i != list->end(); i++)
58         {
59                 userrec* n = i->second;
60                 copy.insert(std::make_pair(n,n));
61         }
62         for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
63         {
64                 sprintf(moderemove,"-%c",this->GetModeChar());
65                 const char* parameters[] = { channel->name, moderemove, i->second->nick };
66                 ServerInstance->SendMode(parameters, 3, n);
67         }
68         delete n;
69 }
70
71 void ModeChannelOp::RemoveMode(userrec* user)
72 {
73 }
74
75 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
76 {
77         int status = channel->GetStatus(source);
78
79         /* Call the correct method depending on wether we're adding or removing the mode */
80         if (adding)
81         {
82                 parameter = this->AddOp(source, parameter.c_str(), channel, status);
83         }
84         else
85         {
86                 parameter = this->DelOp(source, parameter.c_str(), channel, status);
87         }
88         /* If the method above 'ate' the parameter by reducing it to an empty string, then
89          * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
90          * the return value and is always MODEACTION_DENY if the mode is supposed to have
91          * a parameter.
92          */
93         if (parameter.length())
94                 return MODEACTION_ALLOW;
95         else
96                 return MODEACTION_DENY;
97 }
98
99 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
100 {
101         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
102
103         if (d)
104         {
105                 if (IS_LOCAL(user))
106                 {
107                         int MOD_RESULT = 0;
108                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
109
110                         if (MOD_RESULT == ACR_DENY)
111                                 return "";
112                         if (MOD_RESULT == ACR_DEFAULT)
113                         {
114                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
115                                 {
116                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
117                                         return "";
118                                 }
119                         }
120                 }
121
122                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
123         }
124         return "";
125 }
126
127 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
128 {
129         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
130
131         if (d)
132         {
133                 if (IS_LOCAL(user))
134                 {
135                         int MOD_RESULT = 0;
136                         ServerInstance->Log(DEBUG,"Call OnAccessCheck for AC_DEOP");
137                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
138
139                         ServerInstance->Log(DEBUG,"Returns %d",MOD_RESULT);
140
141                         if (MOD_RESULT == ACR_DENY)
142                                 return "";
143                         if (MOD_RESULT == ACR_DEFAULT)
144                         {
145                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
146                                 {
147                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
148                                         return "";
149                                 }
150                         }
151                 }
152
153                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
154         }
155         return "";
156 }