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_h.h"
22 ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
26 unsigned int ModeChannelHalfOp::GetPrefixRank()
31 ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
33 userrec* x = ServerInstance->FindNick(parameter);
36 if (channel->GetStatusFlags(x) & UCMODE_HOP)
38 return std::make_pair(true, x->nick);
42 return std::make_pair(false, parameter);
45 return std::make_pair(false, parameter);
48 void ModeChannelHalfOp::RemoveMode(chanrec* channel)
50 CUList* list = channel->GetHalfoppedUsers();
52 char moderemove[MAXBUF];
53 userrec* n = new userrec(ServerInstance);
54 n->SetFd(FD_MAGIC_NUMBER);
56 for (CUList::iterator i = list->begin(); i != list->end(); i++)
58 userrec* n = i->second;
59 copy.insert(std::make_pair(n,n));
61 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
63 sprintf(moderemove,"-%c",this->GetModeChar());
64 const char* parameters[] = { channel->name, moderemove, i->second->nick };
65 ServerInstance->SendMode(parameters, 3, n);
70 void ModeChannelHalfOp::RemoveMode(userrec* user)
74 ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
76 /* If halfops are not enabled in the conf, we don't execute
77 * anything in this class at all.
79 if (!ServerInstance->Config->AllowHalfop)
82 return MODEACTION_DENY;
85 int status = channel->GetStatus(source);
87 ServerInstance->Log(DEBUG,"Halfop handler, source=%s channel=%s parameter=%s adding=%d",source->nick, channel->name, parameter.c_str(), adding);
89 /* Call the correct method depending on wether we're adding or removing the mode */
92 parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
96 parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
98 /* If the method above 'ate' the parameter by reducing it to an empty string, then
99 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
100 * the return value and is always MODEACTION_DENY if the mode is supposed to have
103 if (parameter.length())
104 return MODEACTION_ALLOW;
106 return MODEACTION_DENY;
109 std::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)
111 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
113 ServerInstance->Log(DEBUG,"Add halfop");
120 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
122 if (MOD_RESULT == ACR_DENY)
124 if (MOD_RESULT == ACR_DEFAULT)
126 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
128 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
134 ServerInstance->Log(DEBUG,"Calling Grant");
135 return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
140 std::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)
142 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
144 ServerInstance->Log(DEBUG,"Del halfop");
151 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
153 if (MOD_RESULT == ACR_DENY)
155 if (MOD_RESULT == ACR_DEFAULT)
157 if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
159 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
165 ServerInstance->Log(DEBUG,"Calling revoke");
166 return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);