1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
14 #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(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
33 userrec* 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(chanrec* channel)
51 CUList* list = channel->GetOppedUsers();
53 char moderemove[MAXBUF];
54 userrec* n = new userrec(ServerInstance);
55 n->SetFd(FD_MAGIC_NUMBER);
57 for (CUList::iterator i = list->begin(); i != list->end(); i++)
59 userrec* n = i->second;
60 copy.insert(std::make_pair(n,n));
62 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
64 sprintf(moderemove,"-%c",this->GetModeChar());
65 const char* parameters[] = { channel->name, moderemove, i->second->nick };
66 ServerInstance->SendMode(parameters, 3, n);
71 void ModeChannelOp::RemoveMode(userrec* user)
75 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
77 int status = channel->GetStatus(source);
79 /* Call the correct method depending on wether we're adding or removing the mode */
82 parameter = this->AddOp(source, parameter.c_str(), channel, status);
86 parameter = this->DelOp(source, parameter.c_str(), channel, status);
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
93 if (parameter.length())
94 return MODEACTION_ALLOW;
96 return MODEACTION_DENY;
99 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
101 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
108 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
110 if (MOD_RESULT == ACR_DENY)
112 if (MOD_RESULT == ACR_DEFAULT)
114 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
116 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
122 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
127 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
129 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
136 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
138 if (MOD_RESULT == ACR_DENY)
140 if (MOD_RESULT == ACR_DEFAULT)
142 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
144 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
150 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);