1
0
Fork 0

cRankManager: Added ClearPlayerRanks()

This commit is contained in:
Howaner 2014-09-28 15:16:11 +02:00
parent 27331da017
commit 63c53a8e23
4 changed files with 46 additions and 0 deletions

View File

@ -2033,6 +2033,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
AddGroupToRank = { Params = "GroupName, RankName", Return = "bool", Notes = "Adds the specified group to the specified rank. Returns true on success, false on failure - if the group name or the rank name is not found." },
AddPermissionToGroup = { Params = "Permission, GroupName", Return = "bool", Notes = "Adds the specified permission to the specified group. Returns true on success, false on failure - if the group name is not found." },
AddRank = { Params = "RankName, MsgPrefix, MsgSuffix, MsgNameColorCode", Return = "", Notes = "Adds a new rank of the specified name and with the specified message visuals. Logs an info message and does nothing if the rank already exists." },
ClearPlayerRanks = { Params = "", Return = "", Notes = "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." },
GetAllGroups = { Params = "", Return = "array-table of groups' names", Notes = "Returns an array-table containing the names of all the groups that are known to the manager." },
GetAllPermissions = { Params = "", Return = "array-table of permissions", Notes = "Returns an array-table containing all the permissions that are known to the manager." },
GetAllPlayers = { Params = "", Return = "array-table of playernames", Notes = "Returns the short uuids of all defined players." },

View File

@ -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)
{
@ -1031,6 +1052,7 @@ 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, "GetAllPlayers", tolua_cRankManager_GetAllPlayers);

View File

@ -1817,6 +1817,25 @@ 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);

View File

@ -217,6 +217,10 @@ 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);