]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_o.cpp
a66818005eb2b198a3a0acd5735e2f925ce60ff6
[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         if (parameter.length())
81                 return MODEACTION_ALLOW;
82         else
83                 return MODEACTION_DENY;
84 }
85
86 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
87 {
88         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
89
90         if (d)
91         {
92                 if (IS_LOCAL(user))
93                 {
94                         int MOD_RESULT = 0;
95                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
96
97                         if (MOD_RESULT == ACR_DENY)
98                                 return "";
99                         if (MOD_RESULT == ACR_DEFAULT)
100                         {
101                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
102                                 {
103                                         user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
104                                         return "";
105                                 }
106                         }
107                 }
108
109                 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
110         }
111         return "";
112 }
113
114 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
115 {
116         userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
117
118         if (d)
119         {
120                 if (IS_LOCAL(user))
121                 {
122                         int MOD_RESULT = 0;
123                         ServerInstance->Log(DEBUG,"Call OnAccessCheck for AC_DEOP");
124                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
125
126                         ServerInstance->Log(DEBUG,"Returns %d",MOD_RESULT);
127
128                         if (MOD_RESULT == ACR_DENY)
129                                 return "";
130                         if (MOD_RESULT == ACR_DEFAULT)
131                         {
132                                 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
133                                 {
134                                         user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
135                                         return "";
136                                 }
137                         }
138                 }
139
140                 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
141         }
142         return "";
143 }