Change Membership:hasMode() to accept a PrefixMode

This commit is contained in:
Attila Molnar 2016-08-30 16:19:31 +02:00
parent cf6a8ee7e3
commit e093134393
8 changed files with 17 additions and 12 deletions

View File

@ -70,13 +70,13 @@ class CoreExport Membership : public Extensible, public insp::intrusive_list_nod
*/
Membership(User* u, Channel* c) : user(u), chan(c) {}
/** Returns true if this member has a given prefix mode set
* @param m The prefix mode letter to check
/** Check if this member has a given prefix mode set
* @param pm Prefix mode to check
* @return True if the member has the prefix mode set, false otherwise
*/
inline bool hasMode(char m) const
bool HasMode(const PrefixMode* pm) const
{
return modes.find(m) != std::string::npos;
return (modes.find(pm->GetModeChar()) != std::string::npos);
}
/** Returns the rank of this member.

View File

@ -353,7 +353,8 @@ void DataKeeper::SaveMemberData(Channel* chan, std::vector<OwnedModesExts>& memb
for (size_t j = 0; j < handledmodes[MODETYPE_CHANNEL].size(); j++)
{
ModeHandler* mh = handledmodes[MODETYPE_CHANNEL][j].mh;
if ((mh->IsPrefixMode()) && (memb->hasMode(mh->GetModeChar())))
const PrefixMode* const pm = mh->IsPrefixMode();
if ((pm) && (memb->HasMode(pm)))
currdata.modelist.push_back(InstanceData(j, memb->user->uuid)); // Need to pass the user's uuid to the mode parser to set the mode later
}

View File

@ -867,7 +867,7 @@ void PrefixMode::RemoveMode(Channel* chan, Modes::ChangeList& changelist)
const Channel::MemberMap& userlist = chan->GetUsers();
for (Channel::MemberMap::const_iterator i = userlist.begin(); i != userlist.end(); ++i)
{
if (i->second->hasMode(this->GetModeChar()))
if (i->second->HasMode(this))
changelist.push_remove(this, i->first->nick);
}
}

View File

@ -34,7 +34,7 @@ class ModuleBadChannelExtban : public Module
{
std::string rm(mask, 2);
char status = 0;
ModeHandler* mh = ServerInstance->Modes->FindPrefix(rm[0]);
const PrefixMode* const mh = ServerInstance->Modes->FindPrefix(rm[0]);
if (mh)
{
rm.assign(mask, 3, std::string::npos);
@ -44,7 +44,7 @@ class ModuleBadChannelExtban : public Module
{
if (InspIRCd::Match((*i)->chan->name, rm))
{
if (!status || (*i)->hasMode(status))
if ((!status) || ((*i)->HasMode(mh)))
return MOD_RES_DENY;
}
}

View File

@ -139,7 +139,7 @@ class ModuleOjoin : public Module
ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
{
// Don't do anything if they're not +Y
if (!memb->hasMode(np.GetModeChar()))
if (!memb->HasMode(&np))
return MOD_RES_PASSTHRU;
// Let them do whatever they want to themselves.

View File

@ -77,7 +77,7 @@ class ModuleOperPrefixMode : public Module
if ((!IS_LOCAL(memb->user)) || (!memb->user->IsOper()) || (memb->user->IsModeSet(hideopermode)))
return;
if (memb->hasMode(opm.GetModeChar()))
if (memb->HasMode(&opm))
return;
// The user was force joined and OnUserPreJoin() did not run. Set the operprefix now.

View File

@ -70,7 +70,7 @@ class CommandRMode : public Command
{
if (!InspIRCd::Match(it->first->nick, pattern))
continue;
if (it->second->hasMode(modeletter) && !((it->first == user) && (pm->GetPrefixRank() > VOICE_VALUE)))
if (it->second->HasMode(pm) && !((it->first == user) && (pm->GetPrefixRank() > VOICE_VALUE)))
changelist.push_remove(mh, it->first->nick);
}
}

View File

@ -73,6 +73,10 @@ class ModuleServProtectMode : public Module, public Whois::EventListener, public
*/
if (!adding && chan && IS_LOCAL(user) && !param.empty())
{
const PrefixMode* const pm = mh->IsPrefixMode();
if (!pm)
return MOD_RES_PASSTHRU;
/* Check if the parameter is a valid nick/uuid
*/
User *u = ServerInstance->FindNick(param);
@ -83,7 +87,7 @@ class ModuleServProtectMode : public Module, public Whois::EventListener, public
* This includes any prefix permission mode, even those registered in other modules, e.g. +qaohv. Using ::ModeString()
* here means that the number of modes is restricted to only modes the user has, limiting it to as short a loop as possible.
*/
if (u->IsModeSet(bm) && memb && memb->hasMode(mh->GetModeChar()))
if ((u->IsModeSet(bm)) && (memb) && (memb->HasMode(pm)))
{
/* BZZZT, Denied! */
user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You are not permitted to remove privileges from %s services", ServerInstance->Config->Network.c_str()));