summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Player.cpp6
-rw-r--r--src/RankManager.cpp69
-rw-r--r--src/RankManager.h6
3 files changed, 21 insertions, 60 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 7992204da..b0dd40615 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -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();
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 0cee7724b..65ce33b92 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -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
- {
- 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;
- }
- catch (const SQLite::Exception & ex)
+ AString Rank = GetPlayerRankName(a_PlayerUUID);
+ if (Rank.empty())
{
- LOGWARNING("%s: Failed to get ranks from DB: %s. Returning empty values.", __FUNCTION__, ex.what());
+ // Rank not found, return failure:
+ a_MsgPrefix.clear();
+ a_MsgSuffix.clear();
+ a_MsgNameColorCode.clear();
+ return false;
}
- a_MsgPrefix.clear();
- a_MsgSuffix.clear();
- a_MsgNameColorCode.clear();
- return false;
+ return GetRankVisuals(Rank, a_MsgPrefix, a_MsgSuffix, a_MsgNameColorCode);
}
diff --git a/src/RankManager.h b/src/RankManager.h
index b93a1157d..f364bba6a 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -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.