parent
9c5797f27d
commit
b5998873e4
@ -2125,6 +2125,37 @@ static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S)
|
||||
{
|
||||
// Function signature: cPlayer:GetRestrictions() -> {restrictions-array}
|
||||
|
||||
// Check the params:
|
||||
cLuaState L(tolua_S);
|
||||
if (
|
||||
!L.CheckParamUserType(1, "cPlayer") ||
|
||||
!L.CheckParamEnd (2)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
cPlayer * self = (cPlayer *)tolua_tousertype(tolua_S, 1, nullptr);
|
||||
if (self == nullptr)
|
||||
{
|
||||
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Push the permissions:
|
||||
L.Push(self->GetRestrictions());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
|
||||
{
|
||||
// Function signature: cPlayer:OpenWindow(Window)
|
||||
@ -3756,6 +3787,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
||||
|
||||
tolua_beginmodule(tolua_S, "cPlayer");
|
||||
tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
|
||||
tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions);
|
||||
tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow);
|
||||
tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
@ -1414,14 +1414,23 @@ bool cPlayer::HasPermission(const AString & a_Permission)
|
||||
|
||||
AStringVector Split = StringSplit(a_Permission, ".");
|
||||
|
||||
// Iterate over all granted permissions; if any matches, then return success:
|
||||
for (AStringVectorVector::const_iterator itr = m_SplitPermissions.begin(), end = m_SplitPermissions.end(); itr != end; ++itr)
|
||||
// Iterate over all restrictions; if any matches, then return failure:
|
||||
for (auto & Restriction: m_SplitRestrictions)
|
||||
{
|
||||
if (PermissionMatches(Split, *itr))
|
||||
if (PermissionMatches(Split, Restriction))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} // for Restriction - m_SplitRestrictions[]
|
||||
|
||||
// Iterate over all granted permissions; if any matches, then return success:
|
||||
for (auto & Permission: m_SplitPermissions)
|
||||
{
|
||||
if (PermissionMatches(Split, Permission))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // for itr - m_SplitPermissions[]
|
||||
} // for Permission - m_SplitPermissions[]
|
||||
|
||||
// No granted permission matches
|
||||
return false;
|
||||
@ -2169,15 +2178,24 @@ void cPlayer::LoadRank(void)
|
||||
RankMgr->UpdatePlayerName(m_UUID, m_PlayerName);
|
||||
}
|
||||
m_Permissions = RankMgr->GetPlayerPermissions(m_UUID);
|
||||
m_Restrictions = RankMgr->GetPlayerRestrictions(m_UUID);
|
||||
RankMgr->GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
|
||||
|
||||
// Break up the individual permissions on each dot, into m_SplitPermissions:
|
||||
m_SplitPermissions.clear();
|
||||
m_SplitPermissions.reserve(m_Permissions.size());
|
||||
for (AStringVector::const_iterator itr = m_Permissions.begin(), end = m_Permissions.end(); itr != end; ++itr)
|
||||
for (auto & Permission: m_Permissions)
|
||||
{
|
||||
m_SplitPermissions.push_back(StringSplit(*itr, "."));
|
||||
} // for itr - m_Permissions[]
|
||||
m_SplitPermissions.push_back(StringSplit(Permission, "."));
|
||||
} // for Permission - m_Permissions[]
|
||||
|
||||
// Break up the individual restrictions on each dot, into m_SplitRestrictions:
|
||||
m_SplitRestrictions.clear();
|
||||
m_SplitRestrictions.reserve(m_Restrictions.size());
|
||||
for (auto & Restriction: m_Restrictions)
|
||||
{
|
||||
m_SplitRestrictions.push_back(StringSplit(Restriction, "."));
|
||||
} // for itr - m_Restrictions[]
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,7 +254,10 @@ public:
|
||||
static bool PermissionMatches(const AStringVector & a_Permission, const AStringVector & a_Template); // Exported in ManualBindings with AString params
|
||||
|
||||
/** Returns all the permissions that the player has assigned to them. */
|
||||
const AStringVector & GetPermissions(void) { return m_Permissions; } // Exported in ManualBindings.cpp
|
||||
const AStringVector & GetPermissions(void) const { return m_Permissions; } // Exported in ManualBindings.cpp
|
||||
|
||||
/** Returns all the restrictions that the player has assigned to them. */
|
||||
const AStringVector & GetRestrictions(void) const { return m_Restrictions; } // Exported in ManualBindings.cpp
|
||||
|
||||
// tolua_begin
|
||||
|
||||
@ -500,10 +503,18 @@ protected:
|
||||
/** All the permissions that this player has, based on their rank. */
|
||||
AStringVector m_Permissions;
|
||||
|
||||
/** All the restrictions that this player has, based on their rank. */
|
||||
AStringVector m_Restrictions;
|
||||
|
||||
/** All the permissions that this player has, based on their rank, split into individual dot-delimited parts.
|
||||
This is used mainly by the HasPermission() function to optimize the lookup. */
|
||||
AStringVectorVector m_SplitPermissions;
|
||||
|
||||
/** All the restrictions that this player has, based on their rank, split into individual dot-delimited parts.
|
||||
This is used mainly by the HasPermission() function to optimize the lookup. */
|
||||
AStringVectorVector m_SplitRestrictions;
|
||||
|
||||
|
||||
// Message visuals:
|
||||
AString m_MsgPrefix, m_MsgSuffix;
|
||||
AString m_MsgNameColorCode;
|
||||
|
Loading…
Reference in New Issue
Block a user