1
0
Fork 0

RankMgr: Default rank is applied to players without any rank.

This commit is contained in:
Mattes D 2014-08-24 20:00:45 +02:00
parent da67dd39ed
commit 8630b20c52
3 changed files with 21 additions and 60 deletions

View File

@ -2051,8 +2051,12 @@ void cPlayer::LoadRank(void)
// Load the values from cRankManager:
cRankManager & RankMgr = cRoot::Get()->GetRankManager();
m_Rank = RankMgr.GetPlayerRankName(m_UUID);
if (m_Rank.empty())
{
m_Rank = RankMgr.GetDefaultRank();
}
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:
m_SplitPermissions.clear();

View File

@ -534,34 +534,12 @@ AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
cCSLock Lock(m_CS);
AStringVector res;
try
AString Rank = GetPlayerRankName(a_PlayerUUID);
if (Rank.empty())
{
// Prepare the DB statement:
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());
}
Rank = m_DefaultRank;
}
catch (const SQLite::Exception & ex)
{
LOGWARNING("%s: Cannot get player permissions: %s", __FUNCTION__, ex.what());
}
return res;
return GetRankPermissions(Rank);
}
@ -742,39 +720,16 @@ bool cRankManager::GetPlayerMsgVisuals(
AString & a_MsgNameColorCode
)
{
ASSERT(m_IsInitialized);
cCSLock Lock(m_CS);
AStringVector res;
try
AString Rank = GetPlayerRankName(a_PlayerUUID);
if (Rank.empty())
{
SQLite::Statement stmt(m_DB,
"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_MsgSuffix.clear();
a_MsgNameColorCode.clear();
return false;
}
a_MsgPrefix = stmt.getColumn(0).getText();
a_MsgSuffix = stmt.getColumn(1).getText();
a_MsgNameColorCode = stmt.getColumn(2).getText();
return true;
// Rank not found, return failure:
a_MsgPrefix.clear();
a_MsgSuffix.clear();
a_MsgNameColorCode.clear();
return false;
}
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;
return GetRankVisuals(Rank, a_MsgPrefix, a_MsgSuffix, a_MsgNameColorCode);
}

View File

@ -56,13 +56,15 @@ public:
The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */
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);
/** Returns the names of Groups that the specified player has assigned to them. */
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);
/** Returns the names of groups that the specified rank has assigned to it.