diff options
author | madmaxoft <github@xoft.cz> | 2014-08-09 17:36:19 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-08-09 17:36:19 +0200 |
commit | 0001a7c9fc2359078968565a8ab464509362b776 (patch) | |
tree | e075ad4035364380a3ee26aa1714996a7ff364bb /src | |
parent | Merge remote-tracking branch 'origin/master' into Ranks (diff) | |
download | cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar.gz cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar.bz2 cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar.lz cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar.xz cuberite-0001a7c9fc2359078968565a8ab464509362b776.tar.zst cuberite-0001a7c9fc2359078968565a8ab464509362b776.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/ManualBindings_RankManager.cpp | 40 | ||||
-rw-r--r-- | src/RankManager.cpp | 37 | ||||
-rw-r--r-- | src/RankManager.h | 9 |
3 files changed, 81 insertions, 5 deletions
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp index daa810cd4..d17672dcb 100644 --- a/src/Bindings/ManualBindings_RankManager.cpp +++ b/src/Bindings/ManualBindings_RankManager.cpp @@ -100,8 +100,8 @@ static int tolua_cRankManager_AddRank(lua_State * L) cLuaState S(L); if ( !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || - !S.CheckParamEnd(3) + !S.CheckParamString(2, 5) || + !S.CheckParamEnd(6) ) { return 0; @@ -396,6 +396,41 @@ static int tolua_cRankManager_GetRankGroups(lua_State * L) +/** Binds cRankManager::GetRankVisuals */ +static int tolua_cRankManager_GetRankVisuals(lua_State * L) +{ + // function signature: + // cRankManager:GetRankVisuals(RankName) -> MsgPrefix, MsgSuffix, MsgNameColorCode + + cLuaState S(L); + if ( + !S.CheckParamUserTable(1, "cRankManager") || + !S.CheckParamString(2) || + !S.CheckParamEnd(3) + ) + { + return 0; + } + + // Get the params: + AString RankName; + S.GetStackValue(2, RankName); + + // Get the visuals: + AString MsgPrefix, MsgSuffix, MsgNameColorCode; + cRoot::Get()->GetRankManager().GetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode); + + // Push the results: + S.Push(MsgPrefix); + S.Push(MsgSuffix); + S.Push(MsgNameColorCode); + return 3; +} + + + + + /** Binds cRankManager::GetRankPermissions */ static int tolua_cRankManager_GetRankPermissions(lua_State * L) { @@ -848,6 +883,7 @@ void ManualBindings::BindRankManager(lua_State * tolua_S) tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions); tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName); tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups); + tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals); tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions); tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists); tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank); diff --git a/src/RankManager.cpp b/src/RankManager.cpp index 8a3b19c15..3627afadb 100644 --- a/src/RankManager.cpp +++ b/src/RankManager.cpp @@ -1123,14 +1123,13 @@ void cRankManager::SetRankVisuals( const AString & a_MsgNameColorCode ) { - AStringVector res; try { SQLite::Statement stmt(m_DB, "UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?"); stmt.bind(1, a_MsgPrefix); stmt.bind(2, a_MsgSuffix); - stmt.bind(1, a_MsgNameColorCode); - stmt.bind(2, a_RankName); + stmt.bind(3, a_MsgNameColorCode); + stmt.bind(4, a_RankName); if (!stmt.executeStep()) { LOGINFO("%s: Rank %s not found, visuals not set.", __FUNCTION__, a_RankName.c_str()); @@ -1146,6 +1145,38 @@ void cRankManager::SetRankVisuals( +bool cRankManager::GetRankVisuals( + const AString & a_RankName, + AString & a_MsgPrefix, + AString & a_MsgSuffix, + AString & a_MsgNameColorCode +) +{ + try + { + SQLite::Statement stmt(m_DB, "SELECT MsgPrefix, MsgSuffix, MsgNameColorCode FROM Rank WHERE Name = ?"); + stmt.bind(1, a_RankName); + if (!stmt.executeStep()) + { + // Rank not found + 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) + { + LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what()); + } + return false; +} + + + + + bool cRankManager::RankExists(const AString & a_RankName) { try diff --git a/src/RankManager.h b/src/RankManager.h index e13febdac..0a43bfe5d 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -121,6 +121,15 @@ public: const AString & a_MsgNameColorCode ); + /** Returns the message visuals of an existing rank. + Returns true if successful, false on error (rank doesn't exist). */ + bool GetRankVisuals( + const AString & a_RankName, + AString & a_MsgPrefix, + AString & a_MsgSuffix, + AString & a_MsgNameColorCode + ); + /** Returns true iff the specified rank exists in the DB. */ bool RankExists(const AString & a_RankName); |