RankMgr: Default rank is applied to players without any rank.
This commit is contained in:
parent
da67dd39ed
commit
8630b20c52
@ -2051,8 +2051,12 @@ void cPlayer::LoadRank(void)
|
|||||||
// Load the values from cRankManager:
|
// Load the values from cRankManager:
|
||||||
cRankManager & RankMgr = cRoot::Get()->GetRankManager();
|
cRankManager & RankMgr = cRoot::Get()->GetRankManager();
|
||||||
m_Rank = RankMgr.GetPlayerRankName(m_UUID);
|
m_Rank = RankMgr.GetPlayerRankName(m_UUID);
|
||||||
|
if (m_Rank.empty())
|
||||||
|
{
|
||||||
|
m_Rank = RankMgr.GetDefaultRank();
|
||||||
|
}
|
||||||
m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
|
m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
|
||||||
RankMgr.GetPlayerMsgVisuals(m_UUID, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
|
RankMgr.GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
|
||||||
|
|
||||||
// Break up the individual permissions on each dot, into m_SplitPermissions:
|
// Break up the individual permissions on each dot, into m_SplitPermissions:
|
||||||
m_SplitPermissions.clear();
|
m_SplitPermissions.clear();
|
||||||
|
@ -534,34 +534,12 @@ AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
|
|||||||
|
|
||||||
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
|
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
|
||||||
{
|
{
|
||||||
ASSERT(m_IsInitialized);
|
AString Rank = GetPlayerRankName(a_PlayerUUID);
|
||||||
cCSLock Lock(m_CS);
|
if (Rank.empty())
|
||||||
|
|
||||||
AStringVector res;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Prepare the DB statement:
|
Rank = m_DefaultRank;
|
||||||
SQLite::Statement stmt(m_DB,
|
|
||||||
"SELECT DISTINCT(PermissionItem.Permission) FROM PermissionItem "
|
|
||||||
"LEFT JOIN RankPermGroup "
|
|
||||||
"ON PermissionItem.PermGroupID = RankPermGroup.PermGroupID "
|
|
||||||
"LEFT JOIN PlayerRank "
|
|
||||||
"ON PlayerRank.RankID = RankPermGroup.RankID "
|
|
||||||
"WHERE PlayerRank.PlayerUUID = ?"
|
|
||||||
);
|
|
||||||
stmt.bind(1, a_PlayerUUID);
|
|
||||||
|
|
||||||
// Execute and get results:
|
|
||||||
while (stmt.executeStep())
|
|
||||||
{
|
|
||||||
res.push_back(stmt.getColumn(0).getText());
|
|
||||||
}
|
}
|
||||||
}
|
return GetRankPermissions(Rank);
|
||||||
catch (const SQLite::Exception & ex)
|
|
||||||
{
|
|
||||||
LOGWARNING("%s: Cannot get player permissions: %s", __FUNCTION__, ex.what());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -742,39 +720,16 @@ bool cRankManager::GetPlayerMsgVisuals(
|
|||||||
AString & a_MsgNameColorCode
|
AString & a_MsgNameColorCode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT(m_IsInitialized);
|
AString Rank = GetPlayerRankName(a_PlayerUUID);
|
||||||
cCSLock Lock(m_CS);
|
if (Rank.empty())
|
||||||
|
|
||||||
AStringVector res;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
SQLite::Statement stmt(m_DB,
|
// Rank not found, return failure:
|
||||||
"SELECT Rank.MsgPrefix, Rank.MsgSuffix, Rank.MsgNameColorCode FROM Rank "
|
|
||||||
"LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID "
|
|
||||||
"WHERE PlayerRank.PlayerUUID = ?"
|
|
||||||
);
|
|
||||||
stmt.bind(1, a_PlayerUUID);
|
|
||||||
if (!stmt.executeStep())
|
|
||||||
{
|
|
||||||
LOGD("%s: Player UUID %s not found in the DB, returning empty values.", __FUNCTION__, a_PlayerUUID.c_str());
|
|
||||||
a_MsgPrefix.clear();
|
a_MsgPrefix.clear();
|
||||||
a_MsgSuffix.clear();
|
a_MsgSuffix.clear();
|
||||||
a_MsgNameColorCode.clear();
|
a_MsgNameColorCode.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
a_MsgPrefix = stmt.getColumn(0).getText();
|
return GetRankVisuals(Rank, a_MsgPrefix, a_MsgSuffix, a_MsgNameColorCode);
|
||||||
a_MsgSuffix = stmt.getColumn(1).getText();
|
|
||||||
a_MsgNameColorCode = stmt.getColumn(2).getText();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (const SQLite::Exception & ex)
|
|
||||||
{
|
|
||||||
LOGWARNING("%s: Failed to get ranks from DB: %s. Returning empty values.", __FUNCTION__, ex.what());
|
|
||||||
}
|
|
||||||
a_MsgPrefix.clear();
|
|
||||||
a_MsgSuffix.clear();
|
|
||||||
a_MsgNameColorCode.clear();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,13 +56,15 @@ public:
|
|||||||
The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */
|
The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */
|
||||||
void Initialize(cMojangAPI & a_MojangAPI);
|
void Initialize(cMojangAPI & a_MojangAPI);
|
||||||
|
|
||||||
/** Returns the name of the rank that the specified player has assigned to them. */
|
/** Returns the name of the rank that the specified player has assigned to them.
|
||||||
|
If the player has no rank assigned, returns an empty string (NOT the default rank). */
|
||||||
AString GetPlayerRankName(const AString & a_PlayerUUID);
|
AString GetPlayerRankName(const AString & a_PlayerUUID);
|
||||||
|
|
||||||
/** Returns the names of Groups that the specified player has assigned to them. */
|
/** Returns the names of Groups that the specified player has assigned to them. */
|
||||||
AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
|
AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
|
||||||
|
|
||||||
/** Returns the permissions that the specified player has assigned to them. */
|
/** Returns the permissions that the specified player has assigned to them.
|
||||||
|
If the player has no rank assigned to them, returns the default rank's permissions. */
|
||||||
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
|
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
|
||||||
|
|
||||||
/** Returns the names of groups that the specified rank has assigned to it.
|
/** Returns the names of groups that the specified rank has assigned to it.
|
||||||
|
Loading…
Reference in New Issue
Block a user