summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/ManualBindings_RankManager.cpp85
-rw-r--r--src/Entities/Player.cpp5
-rw-r--r--src/RankManager.cpp100
-rw-r--r--src/RankManager.h14
4 files changed, 203 insertions, 1 deletions
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp
index 2e93ad264..3c58a0a92 100644
--- a/src/Bindings/ManualBindings_RankManager.cpp
+++ b/src/Bindings/ManualBindings_RankManager.cpp
@@ -129,6 +129,27 @@ static int tolua_cRankManager_AddRank(lua_State * L)
+/** Binds cRankManager::ClearPlayerRanks */
+static int tolua_cRankManager_ClearPlayerRanks(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Remove all players:
+ cRoot::Get()->GetRankManager().ClearPlayerRanks();
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetAllGroups */
static int tolua_cRankManager_GetAllGroups(lua_State * L)
{
@@ -183,6 +204,33 @@ static int tolua_cRankManager_GetAllPermissions(lua_State * L)
+/** Binds cRankManager::GetAllPlayerUUIDs */
+static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetAllPlayerUUIDs() -> arraytable of Player UUID's
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the player uuid's:
+ AStringVector Players = cRoot::Get()->GetRankManager().GetAllPlayerUUIDs();
+
+ // Push the results:
+ S.Push(Players);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetAllRanks */
static int tolua_cRankManager_GetAllRanks(lua_State * L)
{
@@ -400,6 +448,38 @@ static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
+/** Binds cRankManager::GetPlayerName */
+static int tolua_cRankManager_GetPlayerName(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetPlayerName(PlayerUUID) -> string
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the player name:
+ AString PlayerName = cRoot::Get()->GetRankManager().GetPlayerName(PlayerUUID);
+
+ // Push the result:
+ S.Push(PlayerName);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetRankGroups */
static int tolua_cRankManager_GetRankGroups(lua_State * L)
{
@@ -895,7 +975,7 @@ static int tolua_cRankManager_SetDefaultRank(lua_State * L)
// Set the rank, return the result:
S.Push(cRoot::Get()->GetRankManager().SetDefaultRank(RankName));
- return 0;
+ return 1;
}
@@ -972,8 +1052,10 @@ void ManualBindings::BindRankManager(lua_State * tolua_S)
tolua_function(tolua_S, "AddGroupToRank", tolua_cRankManager_AddGroupToRank);
tolua_function(tolua_S, "AddPermissionToGroup", tolua_cRankManager_AddPermissionToGroup);
tolua_function(tolua_S, "AddRank", tolua_cRankManager_AddRank);
+ tolua_function(tolua_S, "ClearPlayerRanks", tolua_cRankManager_ClearPlayerRanks);
tolua_function(tolua_S, "GetAllGroups", tolua_cRankManager_GetAllGroups);
tolua_function(tolua_S, "GetAllPermissions", tolua_cRankManager_GetAllPermissions);
+ tolua_function(tolua_S, "GetAllPlayerUUIDs", tolua_cRankManager_GetAllPlayerUUIDs);
tolua_function(tolua_S, "GetAllRanks", tolua_cRankManager_GetAllRanks);
tolua_function(tolua_S, "GetDefaultRank", tolua_cRankManager_GetDefaultRank);
tolua_function(tolua_S, "GetGroupPermissions", tolua_cRankManager_GetGroupPermissions);
@@ -981,6 +1063,7 @@ void ManualBindings::BindRankManager(lua_State * tolua_S)
tolua_function(tolua_S, "GetPlayerMsgVisuals", tolua_cRankManager_GetPlayerMsgVisuals);
tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
+ tolua_function(tolua_S, "GetPlayerName", tolua_cRankManager_GetPlayerName);
tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 66da14c0c..f58a0a016 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -2140,6 +2140,11 @@ void cPlayer::LoadRank(void)
{
m_Rank = RankMgr.GetDefaultRank();
}
+ else
+ {
+ // Update the name:
+ RankMgr.UpdatePlayerName(m_UUID, m_PlayerName);
+ }
m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
RankMgr.GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
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 (
diff --git a/src/RankManager.h b/src/RankManager.h
index f364bba6a..3f5884f2e 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -60,6 +60,10 @@ public:
If the player has no rank assigned, returns an empty string (NOT the default rank). */
AString GetPlayerRankName(const AString & a_PlayerUUID);
+ /** Returns the last name that the specified player has.
+ An empty string is returned if the player isn't in the database. */
+ AString GetPlayerName(const AString & a_PlayerUUID);
+
/** Returns the names of Groups that the specified player has assigned to them. */
AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
@@ -79,6 +83,9 @@ public:
Returns an empty vector if the rank doesn't exist. Any non-existent groups are ignored. */
AStringVector GetRankPermissions(const AString & a_RankName);
+ /** Returns the short uuids of all defined players. */
+ AStringVector GetAllPlayerUUIDs(void);
+
/** Returns the names of all defined ranks. */
AStringVector GetAllRanks(void);
@@ -211,6 +218,13 @@ public:
/** Returns the name of the default rank. */
const AString & GetDefaultRank(void) const { return m_DefaultRank; }
+ /** Removes all player ranks from the database. Note that this doesn't change the cPlayer instances
+ for the already connected players, you need to update all the instances manually. */
+ void ClearPlayerRanks(void);
+
+ /** Updates the playername that is saved with this uuid. Returns false if a error occurred */
+ bool UpdatePlayerName(const AString & a_PlayerUUID, const AString & a_NewPlayerName);
+
protected:
/** The database storage for all the data. Protected by m_CS. */