1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "configreader.h"
20 #include "modes/cmode_o.h"
22 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@', '@')
26 unsigned int ModeChannelOp::GetPrefixRank()
31 ModePair ModeChannelOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
33 User* x = ServerInstance->FindNick(parameter);
36 if (channel->GetStatusFlags(x) & UCMODE_OP)
38 return std::make_pair(true, x->nick);
42 return std::make_pair(false, parameter);
45 return std::make_pair(false, parameter);
49 void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
51 CUList* clist = channel->GetOppedUsers();
54 for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
57 copy.insert(std::make_pair(n,n->nick));
60 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
63 stack->Push(this->GetModeChar(), i->first->nick);
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);
72 void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
76 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
78 int status = channel->GetStatus(source);
80 /* Call the correct method depending on wether we're adding or removing the mode */
83 parameter = this->AddOp(source, parameter.c_str(), channel, status);
87 parameter = this->DelOp(source, parameter.c_str(), channel, status);
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
94 if (parameter.length())
95 return MODEACTION_ALLOW;
97 return MODEACTION_DENY;
100 std::string ModeChannelOp::AddOp(User *user,const char* dest,Channel *chan,int status)
102 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
109 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
111 if (MOD_RESULT == ACR_DENY)
113 if (MOD_RESULT == ACR_DEFAULT)
115 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
117 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
123 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
128 std::string ModeChannelOp::DelOp(User *user,const char *dest,Channel *chan,int status)
130 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
137 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
139 if (MOD_RESULT == ACR_DENY)
141 if (MOD_RESULT == ACR_DEFAULT)
143 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
145 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
151 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);