summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-08-08 09:56:28 +0200
committermadmaxoft <github@xoft.cz>2014-08-08 09:56:28 +0200
commit670e94bfeb62a51ca64ffaa0e45086e1ca91057c (patch)
tree2d42fa3886b6ba33d76d3dbd5d93f4521e0d7dfa /src
parentRankMgr: Added SQL integer datatypes. (diff)
downloadcuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar.gz
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar.bz2
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar.lz
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar.xz
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.tar.zst
cuberite-670e94bfeb62a51ca64ffaa0e45086e1ca91057c.zip
Diffstat (limited to 'src')
-rw-r--r--src/RankManager.cpp26
-rw-r--r--src/RankManager.h38
2 files changed, 36 insertions, 28 deletions
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 18ed65b26..e77fb22b9 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -13,7 +13,7 @@
-/*
+//*
// This code is for internal testing while developing the cRankManager class
static class cRankMgrTest
{
@@ -38,7 +38,7 @@ public:
std::cout << " Rank: '" << m_Mgr.GetPlayerRankName(UUID) << "'." << std::endl;
// List all the permission groups for the player:
- AStringVector Groups = m_Mgr.GetPlayerPermissionGroups(UUID);
+ AStringVector Groups = m_Mgr.GetPlayerGroups(UUID);
std::cout << " Groups(" << Groups.size() << "):" << std::endl;
for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
{
@@ -72,9 +72,9 @@ cRankManager::cRankManager(void) :
// Create the DB tables, if they don't exist:
m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionGroup (GroupID INTEGER PRIMARY KEY, Name)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermissionGroups (RankID INTEGER, GroupID INTEGER)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (GroupID INTEGER, Permission)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermGroup (PermGroupID INTEGER PRIMARY KEY, Name)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (PermGroupID INTEGER, Permission)");
// TODO: Check if tables empty, add some defaults then
}
@@ -100,15 +100,15 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
-AStringVector cRankManager::GetPlayerPermissionGroups(const AString & a_PlayerUUID)
+AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
// Prepare the DB statement:
SQLite::Statement stmt(m_DB,
- "SELECT PermissionGroup.Name FROM PermissionGroup "
- "LEFT JOIN RankPermissionGroups "
- "ON PermissionGroup.GroupID = RankPermissionGroups.GroupID "
+ "SELECT Group.Name FROM Group "
+ "LEFT JOIN RankGroups "
+ "ON Group.GroupID = RankGroups.GroupID "
"LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "ON PlayerRank.RankID = RankGroups.RankID "
"WHERE PlayerRank.PlayerUUID = ?"
);
stmt.bind(1, a_PlayerUUID);
@@ -131,10 +131,10 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
// Prepare the DB statement:
SQLite::Statement stmt(m_DB,
"SELECT PermissionItem.Permission FROM PermissionItem "
- "LEFT JOIN RankPermissionGroups "
- "ON PermissionItem.GroupID = RankPermissionGroups.GroupID "
+ "LEFT JOIN RankGroups "
+ "ON PermissionItem.GroupID = RankGroups.GroupID "
"LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "ON PlayerRank.RankID = RankGroups.RankID "
"WHERE PlayerRank.PlayerUUID = ?"
);
stmt.bind(1, a_PlayerUUID);
diff --git a/src/RankManager.h b/src/RankManager.h
index 1eaeb97a1..0b1db2fb8 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -22,23 +22,26 @@ public:
/** Returns the name of the rank that the specified player has assigned to them. */
AString GetPlayerRankName(const AString & a_PlayerUUID);
- /** Returns the names of PermissionGroups that the specified player has assigned to them. */
- AStringVector GetPlayerPermissionGroups(const AString & a_PlayerUUID);
+ /** Returns the names of Groups that the specified player has assigned to them. */
+ AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
/** Returns the permissions that the specified player has assigned to them. */
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
/** Returns the names of groups that the specified rank has assigned to it. */
- AStringVector GetRankPermissionGroups(const AString & a_RankName);
+ AStringVector GetRankGroups(const AString & a_RankName);
- /** Returns the permissions that the specified permission group has assigned to it. */
- AStringVector GetPermissionGroupPermissiont(const AString & a_GroupName);
+ /** Returns the permissions that the specified group has assigned to it. */
+ AStringVector GetGroupPermissions(const AString & a_GroupName);
+
+ /** Returns all permissions that the specified rank has assigned to it, through all its groups. */
+ AStringVector GetRankPermissions(const AString & a_RankName);
/** Returns the names of all defined ranks. */
AStringVector GetAllRanks(void);
/** Returns the names of all permission groups. */
- AStringVector GetAllPermissionGroups(void);
+ AStringVector GetAllGroups(void);
/** Returns all the distinct permissions that are stored in the DB. */
AStringVector GetAllPermissions(void);
@@ -60,37 +63,42 @@ public:
);
/** Adds a new permission group. No action if such a group already exists. */
- void AddPermissionGroup(const AString & a_GroupName);
+ void AddGroup(const AString & a_GroupName);
/** Adds the specified permission group to the specified rank.
Fails if the rank or group names are not found.
Returns true if successful, false on error. */
- bool AddPermissionGroupToRank(const AString & a_RankName, const AString & a_GroupName);
+ bool AddGroupToRank(const AString & a_RankName, const AString & a_GroupName);
/** Adds the specified permission to the specified permission group.
Fails if the permission group name is not found.
Returns true if successful, false on error. */
- bool AddPermissionToPermissionGroup(const AString & a_Permission, const AString & a_GroupName);
+ bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
/** Removes the specified rank.
All players assigned to that rank will be re-assigned to a_ReplacementRankName, unless it is empty. */
void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
- /** Removes the specified permission group. */
- void RemovePermissionGroup(const AString & a_PermissionGroup);
+ /** Removes the specified group completely.
+ The group will first be removed from all ranks using it, and then removed itself. */
+ void RemoveGroup(const AString & a_GroupName);
+
+ /** Removes the specified group from the specified rank.
+ The group will stay defined, even if no rank is using it. */
+ void RemoveGroupFromRank(const AString & a_RankName, const AString & a_GroupName);
- /** Removes the specified permission from the specified permission group. */
- void RemovePermission(const AString & a_Permission, const AString & a_PermissionGroup);
+ /** Removes the specified permission from the specified group. */
+ void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName);
/** Renames the specified rank. No action if the rank name is not found.
Fails if the new name is already used.
Returns true on success, false on failure. */
bool RenameRank(const AString & a_OldName, const AString & a_NewName);
- /** Renames the specified permission group. No action if the rank name is not found.
+ /** Renames the specified group. No action if the rank name is not found.
Fails if the new name is already used.
Returns true on success, false on failure. */
- bool RenamePermissionGroup(const AString & a_OldName, const AString & a_NewName);
+ bool RenameGroup(const AString & a_OldName, const AString & a_NewName);
/** Sets the specified player's rank.
If the player already had rank assigned to them, it is overwritten with the new rank.