summaryrefslogtreecommitdiffstats
path: root/src/RankManager.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-09-29 20:39:13 +0200
committerMattes D <github@xoft.cz>2014-09-29 20:39:13 +0200
commitd3c2c02b6b35c96b830a1e55691be9d10a4b0784 (patch)
treeb9d3abf6a0a4d65c6779b25ecec0ba89d0f21af6 /src/RankManager.cpp
parentMerge pull request #1480 from w00tc0d3/work (diff)
parentFixed a typo in the description. (diff)
downloadcuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar.gz
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar.bz2
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar.lz
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar.xz
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.tar.zst
cuberite-d3c2c02b6b35c96b830a1e55691be9d10a4b0784.zip
Diffstat (limited to '')
-rw-r--r--src/RankManager.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index e5896f8f3..c9b428e3b 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -496,6 +496,33 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
+AString cRankManager::GetPlayerName(const AString & a_PlayerUUID)
+{
+ ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
+
+ try
+ {
+ // Prepare the DB statement:
+ SQLite::Statement stmt(m_DB, "SELECT PlayerName FROM PlayerRank WHERE PlayerUUID = ?");
+ stmt.bind(1, a_PlayerUUID);
+
+ if (stmt.executeStep())
+ {
+ return stmt.getColumn(0).getText();
+ }
+ }
+ catch (SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Cannot get player name: %s", __FUNCTION__, ex.what());
+ }
+ return AString();
+}
+
+
+
+
+
AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
@@ -636,6 +663,32 @@ AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
+AStringVector cRankManager::GetAllPlayerUUIDs(void)
+{
+ ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
+
+ AStringVector res;
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PlayerUUID FROM PlayerRank");
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get players from DB: %s", __FUNCTION__, ex.what());
+ }
+ return res;
+}
+
+
+
+
+
+
AStringVector cRankManager::GetAllRanks(void)
{
ASSERT(m_IsInitialized);
@@ -1764,6 +1817,53 @@ bool cRankManager::SetDefaultRank(const AString & a_RankName)
+void cRankManager::ClearPlayerRanks(void)
+{
+ ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
+
+ try {
+ SQLite::Statement stmt(m_DB, "DELETE FROM PlayerRank");
+ stmt.exec();
+ }
+ catch (SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to remove/clear all players: %s", __FUNCTION__, ex.what());
+ }
+}
+
+
+
+
+
+bool cRankManager::UpdatePlayerName(const AString & a_PlayerUUID, const AString & a_NewPlayerName)
+{
+ ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
+
+ try
+ {
+ SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET PlayerName = ? WHERE PlayerUUID = ?");
+ stmt.bind(1, a_NewPlayerName);
+ stmt.bind(2, a_PlayerUUID);
+ if (stmt.exec() > 0)
+ {
+ // The player name was changed, returns true
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to update player name from UUID %s: %s", __FUNCTION__, a_PlayerUUID.c_str(), ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+
bool cRankManager::AreDBTablesEmpty(void)
{
return (