1
0

RankMgr: Added GetRankVisuals() function.

This commit is contained in:
madmaxoft 2014-08-09 17:36:19 +02:00
parent 4b1505f39d
commit 0001a7c9fc
3 changed files with 81 additions and 5 deletions

View File

@ -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);

View File

@ -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

View File

@ -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);