mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Store a set of list mode pointers in Membership instead of characters.
This commit is contained in:
parent
bc2098a492
commit
ec217059c3
@ -52,7 +52,7 @@ public:
|
||||
/** List of prefix mode letters this member has,
|
||||
* sorted by prefix rank, highest first
|
||||
*/
|
||||
std::string modes;
|
||||
std::set<PrefixMode*, PrefixMode::Sorter> modes;
|
||||
|
||||
/** Id of this Membership, set by the protocol module, other components should never read or
|
||||
* write this field.
|
||||
@ -86,15 +86,18 @@ public:
|
||||
*/
|
||||
bool HasMode(const PrefixMode* pm) const
|
||||
{
|
||||
return (modes.find(pm->GetModeChar()) != std::string::npos);
|
||||
return std::find(modes.begin(), modes.end(), pm) != modes.end();
|
||||
}
|
||||
|
||||
/** Returns the highest prefix mode for this membership or nullptr if no prefix mode is set. */
|
||||
PrefixMode* GetMode() const { return modes.empty() ? nullptr : *modes.begin(); }
|
||||
|
||||
/** Returns the rank of this member.
|
||||
* The rank of a member is defined as the rank given by the 'strongest' prefix mode a
|
||||
* member has. See the PrefixMode class description for more info.
|
||||
* @return The rank of the member
|
||||
*/
|
||||
unsigned int GetRank();
|
||||
unsigned int GetRank() { return modes.empty() ? 0 : (*modes.begin())->GetPrefixRank(); }
|
||||
|
||||
/** Add a prefix character to a user.
|
||||
* Only the core should call this method, usually from
|
||||
@ -115,6 +118,9 @@ public:
|
||||
*/
|
||||
char GetPrefixChar() const;
|
||||
|
||||
/** Get the mode character of the highest prefix mode this user has on the channel or 0 if no prefix modes are set. */
|
||||
char GetModeChar() const { return modes.empty() ? 0 : (*modes.begin())->GetModeChar(); }
|
||||
|
||||
/** Return all prefix chars this member has.
|
||||
* @return A list of all prefix characters. The prefixes will always
|
||||
* be in rank order, greatest first, as certain IRC clients require
|
||||
@ -122,6 +128,9 @@ public:
|
||||
*/
|
||||
std::string GetAllPrefixChars() const;
|
||||
|
||||
/** Returns all prefix modes this member has ordered descending by rank. */
|
||||
std::string GetAllPrefixModes() const;
|
||||
|
||||
/** Sends a server notice to this user in the context of this channel.
|
||||
* @param text The contents of the message to send.
|
||||
*/
|
||||
|
@ -377,6 +377,15 @@ protected:
|
||||
bool selfremove = true;
|
||||
|
||||
public:
|
||||
/** Sorts a container of PrefixMode* objects descending by their rank. */
|
||||
struct Sorter
|
||||
{
|
||||
bool operator()(const PrefixMode* lhs, const PrefixMode* rhs) const
|
||||
{
|
||||
return lhs->GetPrefixRank() > rhs->GetPrefixRank();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param Creator The module creating this mode
|
||||
|
@ -443,10 +443,9 @@ char Membership::GetPrefixChar() const
|
||||
char pf = 0;
|
||||
unsigned int bestrank = 0;
|
||||
|
||||
for (const auto& modechr : modes)
|
||||
for (const auto& mh : modes)
|
||||
{
|
||||
PrefixMode* mh = ServerInstance->Modes.FindPrefixMode(modechr);
|
||||
if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
|
||||
if (mh->GetPrefixRank() > bestrank && mh->GetPrefix())
|
||||
{
|
||||
bestrank = mh->GetPrefixRank();
|
||||
pf = mh->GetPrefix();
|
||||
@ -455,30 +454,30 @@ char Membership::GetPrefixChar() const
|
||||
return pf;
|
||||
}
|
||||
|
||||
unsigned int Membership::GetRank()
|
||||
{
|
||||
if (!modes.empty())
|
||||
{
|
||||
PrefixMode* mh = ServerInstance->Modes.FindPrefixMode(modes[0]);
|
||||
if (mh)
|
||||
return mh->GetPrefixRank();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Membership::GetAllPrefixChars() const
|
||||
{
|
||||
std::string ret;
|
||||
for (const auto& modechr : modes)
|
||||
for (const auto& mh : modes)
|
||||
{
|
||||
PrefixMode* mh = ServerInstance->Modes.FindPrefixMode(modechr);
|
||||
if (mh && mh->GetPrefix())
|
||||
if (mh->GetPrefix())
|
||||
ret.push_back(mh->GetPrefix());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Membership::GetAllPrefixModes() const
|
||||
{
|
||||
std::string ret;
|
||||
for (const auto& mh : modes)
|
||||
{
|
||||
if (mh->GetModeChar())
|
||||
ret.push_back(mh->GetModeChar());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int Channel::GetPrefixValue(User* user)
|
||||
{
|
||||
MemberMap::iterator m = userlist.find(user);
|
||||
@ -489,22 +488,10 @@ unsigned int Channel::GetPrefixValue(User* user)
|
||||
|
||||
bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding)
|
||||
{
|
||||
char prefix = delta_mh->GetModeChar();
|
||||
for (unsigned int i = 0; i < modes.length(); i++)
|
||||
{
|
||||
char mchar = modes[i];
|
||||
PrefixMode* mh = ServerInstance->Modes.FindPrefixMode(mchar);
|
||||
if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
|
||||
{
|
||||
modes = modes.substr(0,i) +
|
||||
(adding ? std::string(1, prefix) : "") +
|
||||
modes.substr(mchar == prefix ? i+1 : i);
|
||||
return adding != (mchar == prefix);
|
||||
}
|
||||
}
|
||||
if (adding)
|
||||
modes.push_back(prefix);
|
||||
return adding;
|
||||
return modes.insert(delta_mh).second;
|
||||
else
|
||||
return modes.erase(delta_mh);
|
||||
}
|
||||
|
||||
void Membership::WriteNotice(const std::string& text) const
|
||||
|
@ -106,10 +106,9 @@ CmdResult CommandKick::Handle(User* user, const Params& parameters)
|
||||
{
|
||||
unsigned int them = srcmemb->GetRank();
|
||||
unsigned int req = HALFOP_VALUE;
|
||||
for (std::string::size_type i = 0; i < memb->modes.length(); i++)
|
||||
for (const auto& mh : memb->modes)
|
||||
{
|
||||
ModeHandler* mh = ServerInstance->Modes.FindMode(memb->modes[i], MODETYPE_CHANNEL);
|
||||
if (mh && mh->GetLevelRequired(true) > req)
|
||||
if (mh->GetLevelRequired(true) > req)
|
||||
req = mh->GetLevelRequired(true);
|
||||
}
|
||||
|
||||
|
@ -57,12 +57,7 @@ public:
|
||||
|
||||
modechangelist.clear();
|
||||
for (const auto& mode : memb.modes)
|
||||
{
|
||||
PrefixMode* const pm = ServerInstance->Modes.FindPrefixMode(mode);
|
||||
if (!pm)
|
||||
continue; // Shouldn't happen
|
||||
modechangelist.push_add(pm, memb.user->nick);
|
||||
}
|
||||
modechangelist.push_add(mode, memb.user->nick);
|
||||
|
||||
if (modechangelist.empty())
|
||||
{
|
||||
|
@ -535,7 +535,7 @@ void CommandWho::SendWhoLine(LocalUser* source, const std::vector<std::string>&
|
||||
if (oplevels.empty())
|
||||
BuildOpLevels();
|
||||
|
||||
wholine.push(memb && !memb->modes.empty() ? oplevels[memb->modes.front()] : "n/a");
|
||||
wholine.push(memb && memb->GetModeChar() ? oplevels[memb->GetModeChar()] : "n/a");
|
||||
}
|
||||
|
||||
// Include the user's real name.
|
||||
|
@ -183,7 +183,7 @@ namespace Stats
|
||||
{
|
||||
data << "<channelmember><uid>" << memb->user->uuid << "</uid><privs>"
|
||||
<< Sanitize(memb->GetAllPrefixChars()) << "</privs><modes>"
|
||||
<< memb->modes << "</modes>";
|
||||
<< memb->GetAllPrefixModes() << "</modes>";
|
||||
DumpMeta(data, memb);
|
||||
data << "</channelmember>";
|
||||
}
|
||||
|
@ -185,7 +185,8 @@ public:
|
||||
|
||||
void add(Membership* memb)
|
||||
{
|
||||
add(memb, memb->modes.begin(), memb->modes.end());
|
||||
const std::string modes = memb->GetAllPrefixModes();
|
||||
add(memb, modes.begin(), modes.end());
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
@ -538,7 +538,7 @@ void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created_by
|
||||
if (!memb->modes.empty())
|
||||
{
|
||||
params.push(ConvToStr(memb->chan->age));
|
||||
params.push(memb->modes);
|
||||
params.push(memb->GetAllPrefixModes());
|
||||
}
|
||||
params.Broadcast();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user