From 40e15c5ad517a6f860b39d1b225596424c3d2506 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 5 Aug 2014 18:37:00 +0200 Subject: RankMgr: Initial interface declaration. --- src/RankManager.h | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/RankManager.h (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h new file mode 100644 index 000000000..cda6beee9 --- /dev/null +++ b/src/RankManager.h @@ -0,0 +1,103 @@ + +// RankManager.h + +// Declares the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players + + + + +#pragma once + +#include "SQLiteCpp/Database.h" + + + + + +class cRankManager +{ +public: + cRankManager(void); + + /** 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 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); + + /** Returns the permissions that the specified permission group has assigned to it. */ + AStringVector GetPermissionGroupPermissiont(const AString & a_GroupName); + + /** Returns the names of all defined ranks. */ + AStringVector GetAllRanks(void); + + /** Returns the names of all permission groups. */ + AStringVector GetAllPermissionGroups(void); + + /** Returns all the distinct permissions that are stored in the DB. */ + AStringVector GetAllPermissions(void); + + /** Returns the message visuals (prefix, postfix, color) for the specified player. */ + void GetPlayerMsgVisuals( + const AString & a_PlayerUUID, + AString & a_MsgPrefix, + AString & a_MsgPostfix, + AString & a_MsgNameColorCode + ); + + /** Adds a new rank. No action if the rank already exists. */ + void AddRank(const AString & a_RankName); + + /** Adds a new permission group. No action if such a group already exists. */ + void AddPermissionGroup(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); + + /** 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); + + /** 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 permission from the specified permission group. */ + void RemovePermission(const AString & a_Permission, const AString & a_PermissionGroup); + + /** 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. + 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); + + /** Sets the specified player's rank. + If the player already had rank assigned to them, it is overwritten with the new rank. + Note that this doesn't change the cPlayer if the player is already connected, you need to update all the + cPlayer instances manually. */ + void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName); + +protected: + + SQLite::Database m_DB; +} ; + + + + -- cgit v1.2.3 From fcfae0252503a845c98fe6e882dda69e44224094 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 5 Aug 2014 22:28:37 +0200 Subject: RankMgr: More interface. --- src/RankManager.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index cda6beee9..1eaeb97a1 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -47,12 +47,17 @@ public: void GetPlayerMsgVisuals( const AString & a_PlayerUUID, AString & a_MsgPrefix, - AString & a_MsgPostfix, + AString & a_MsgSuffix, AString & a_MsgNameColorCode ); /** Adds a new rank. No action if the rank already exists. */ - void AddRank(const AString & a_RankName); + void AddRank( + const AString & a_RankName, + const AString & a_MsgPrefix, + const AString & a_MsgSuffix, + const AString & a_MsgNameColorCode + ); /** Adds a new permission group. No action if such a group already exists. */ void AddPermissionGroup(const AString & a_GroupName); @@ -93,6 +98,13 @@ public: cPlayer instances manually. */ void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName); + /** Sets the message visuals of an existing rank. No action if the rank name is not found. */ + void SetRankVisuals( + const AString & a_RankName, + const AString & a_MsgPrefix, + const AString & a_MsgSuffix, + const AString & a_MsgNameColorCode + ); protected: SQLite::Database m_DB; -- cgit v1.2.3 From 670e94bfeb62a51ca64ffaa0e45086e1ca91057c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 8 Aug 2014 09:56:28 +0200 Subject: RankMgr: Renamed PermissionGroup to Group in API and PermGroup in DB. "Group" is SQL keyword and shouldn't be used as table name. --- src/RankManager.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/RankManager.h') 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. -- cgit v1.2.3 From 65b81b4ab7f580c98ca80b8e57a13de961f19131 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 8 Aug 2014 10:02:25 +0200 Subject: RankMgr: Implemented the basic API functions. --- src/RankManager.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 0b1db2fb8..0c35b555f 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -68,7 +68,7 @@ public: /** 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 AddGroupToRank(const AString & a_RankName, const AString & a_GroupName); + bool AddGroupToRank(const AString & a_GroupName, const AString & a_RankName); /** Adds the specified permission to the specified permission group. Fails if the permission group name is not found. @@ -113,6 +113,22 @@ public: const AString & a_MsgSuffix, const AString & a_MsgNameColorCode ); + + /** Returns true iff the specified rank exists in the DB. */ + bool RankExists(const AString & a_RankName); + + /** Returns true iff the specified group exists in the DB. */ + bool GroupExists(const AString & a_GroupName); + + /** Returns true iff the specified player has a rank assigned to them in the DB. */ + bool IsPlayerRankSet(const AString & a_PlayerUUID); + + /** Returns true iff the specified rank contains the specified group. */ + bool IsGroupInRank(const AString & a_GroupName, const AString & a_RankName); + + /** Returns true iff the specified group contains the specified permission. */ + bool IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName); + protected: SQLite::Database m_DB; -- cgit v1.2.3 From a5b35e09ce1e352d4c57e66750a72335fc60d4b2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 8 Aug 2014 16:38:38 +0200 Subject: RankMgr: Implemented GetXforY and GetAll APIs. --- src/RankManager.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 0c35b555f..9a1828275 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -28,13 +28,16 @@ public: /** 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. */ + /** Returns the names of groups that the specified rank has assigned to it. + Returns an empty vector if the rank doesn't exist. */ AStringVector GetRankGroups(const AString & a_RankName); - /** Returns the permissions that the specified group has assigned to it. */ + /** Returns the permissions that the specified group has assigned to it. + Returns an empty vector if the group doesn't exist. */ AStringVector GetGroupPermissions(const AString & a_GroupName); - /** Returns all permissions that the specified rank has assigned to it, through all its groups. */ + /** Returns all permissions that the specified rank has assigned to it, through all its groups. + Returns an empty vector if the rank doesn't exist. Any non-existent groups are ignored. */ AStringVector GetRankPermissions(const AString & a_RankName); /** Returns the names of all defined ranks. */ -- cgit v1.2.3 From 89333c5870efb438a38786fd67b82daff0482d9a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 8 Aug 2014 21:30:47 +0200 Subject: RankMgr: Finished API implementation. --- src/RankManager.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 9a1828275..e13febdac 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -49,8 +49,9 @@ public: /** Returns all the distinct permissions that are stored in the DB. */ AStringVector GetAllPermissions(void); - /** Returns the message visuals (prefix, postfix, color) for the specified player. */ - void GetPlayerMsgVisuals( + /** Returns the message visuals (prefix, postfix, color) for the specified player. + Returns true if the visuals were read from the DB, false if not (player not found etc). */ + bool GetPlayerMsgVisuals( const AString & a_PlayerUUID, AString & a_MsgPrefix, AString & a_MsgSuffix, @@ -79,7 +80,9 @@ public: 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. */ + All players assigned to that rank will be re-assigned to a_ReplacementRankName. + If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB, + which means they will receive the default rank the next time they are queried. */ void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName); /** Removes the specified group completely. @@ -88,7 +91,7 @@ public: /** 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); + void RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName); /** Removes the specified permission from the specified group. */ void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName); @@ -104,10 +107,11 @@ public: 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. + If the player already had rank assigned to them, it is overwritten with the new rank and name. Note that this doesn't change the cPlayer if the player is already connected, you need to update all the - cPlayer instances manually. */ - void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName); + cPlayer instances manually. + The PlayerName is provided for reference, so that GetRankPlayerNames() can work. */ + void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName); /** Sets the message visuals of an existing rank. No action if the rank name is not found. */ void SetRankVisuals( -- cgit v1.2.3 From 0001a7c9fc2359078968565a8ab464509362b776 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 9 Aug 2014 17:36:19 +0200 Subject: RankMgr: Added GetRankVisuals() function. --- src/RankManager.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/RankManager.h') 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); -- cgit v1.2.3 From e110f7226895b1629f72a52c7953d8f00a1f63c6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 13 Aug 2014 09:53:33 +0200 Subject: RankMgr: Initial migration code. --- src/RankManager.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 0a43bfe5d..ffe7638e1 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -14,11 +14,22 @@ +class cMojangAPI; + + + + + class cRankManager { public: + /** Creates the rank manager. Needs to be initialized before other use. */ cRankManager(void); + /** Initializes the rank manager. Performs migration and default-setting if no data is found in the DB. + The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */ + void Initialize(cMojangAPI & a_MojangAPI); + /** Returns the name of the rank that the specified player has assigned to them. */ AString GetPlayerRankName(const AString & a_PlayerUUID); @@ -79,6 +90,11 @@ public: Returns true if successful, false on error. */ bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName); + /** Adds the specified permissions to the specified permission group. + Fails if the permission group name is not found. + Returns true if successful, false on error. */ + bool AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName); + /** Removes the specified rank. All players assigned to that rank will be re-assigned to a_ReplacementRankName. If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB, @@ -147,7 +163,19 @@ public: protected: + /** The database storage for all the data. */ SQLite::Database m_DB; + + /** Set to true once the manager is initialized. */ + bool m_IsInitialized; + + + /** Returns true if all the DB tables are empty, indicating a fresh new install. */ + bool AreDBTablesEmpty(void); + + /** Returns true iff the specified DB table is empty. + If there's an error while querying, returns false. */ + bool IsDBTableEmpty(const AString & a_TableName); } ; -- cgit v1.2.3 From 5e415c5b9565564c41c4f2f4144c6863c106bc46 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 13 Aug 2014 12:33:31 +0200 Subject: RankMgr: Fixed multithreading issues. Only one thread is allowed to interact with a SQLite::Database object at a time. Additionally, improved performance of the migration by wrapping the entire thing in a transaction. --- src/RankManager.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index ffe7638e1..3ccbd2fd4 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -9,6 +9,7 @@ #pragma once #include "SQLiteCpp/Database.h" +#include "SQLiteCpp/Transaction.h" @@ -23,6 +24,29 @@ class cMojangAPI; class cRankManager { public: + /** Acquire this lock to perform mass changes. + Improves performance by wrapping everything into a transaction. + Makes sure that no other thread is accessing the DB. */ + class cMassChangeLock + { + public: + cMassChangeLock(cRankManager & a_RankManager) : + m_Lock(a_RankManager.m_CS), + m_Transaction(a_RankManager.m_DB) + { + } + + ~cMassChangeLock() + { + m_Transaction.commit(); + } + + protected: + cCSLock m_Lock; + SQLite::Transaction m_Transaction; + }; + + /** Creates the rank manager. Needs to be initialized before other use. */ cRankManager(void); @@ -80,6 +104,9 @@ public: /** Adds a new permission group. No action if such a group already exists. */ void AddGroup(const AString & a_GroupName); + /** Bulk-adds groups. Group names that already exist are silently skipped. */ + void AddGroups(const AStringVector & a_GroupNames); + /** 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. */ @@ -163,9 +190,12 @@ public: protected: - /** The database storage for all the data. */ + /** The database storage for all the data. Protected by m_CS. */ SQLite::Database m_DB; + /** The mutex protecting m_DB against multi-threaded access. */ + cCriticalSection m_CS; + /** Set to true once the manager is initialized. */ bool m_IsInitialized; -- cgit v1.2.3 From 326dd7e4c6baa6070d35a2a46ca20404c623c8e1 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 21 Aug 2014 16:55:39 +0200 Subject: RankMgr: Added cRankManager::RemovePlayerRank(). --- src/RankManager.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 3ccbd2fd4..532b4cd83 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -155,6 +155,12 @@ public: cPlayer instances manually. The PlayerName is provided for reference, so that GetRankPlayerNames() can work. */ void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName); + + /** Removes the player's rank assignment. The player is left without a rank. + Note that this doesn't change the cPlayer instances for the already connected players, you need to update + all the instances manually. + No action if the player has no rank assigned to them already. */ + void RemovePlayerRank(const AString & a_PlayerUUID); /** Sets the message visuals of an existing rank. No action if the rank name is not found. */ void SetRankVisuals( -- cgit v1.2.3 From 0c04bf962ed025789c1979c6d4fb122735b1a46b Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 21 Aug 2014 20:47:52 +0200 Subject: cMojangAPI updates cRankManager's playernames. --- src/RankManager.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 532b4cd83..24030ef22 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -49,6 +49,8 @@ public: /** Creates the rank manager. Needs to be initialized before other use. */ cRankManager(void); + + ~cRankManager(); /** Initializes the rank manager. Performs migration and default-setting if no data is found in the DB. The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */ @@ -194,6 +196,9 @@ public: /** Returns true iff the specified group contains the specified permission. */ bool IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName); + /** Called by cMojangAPI whenever the playername-uuid pairing is discovered. Updates the DB. */ + void NotifyNameUUID(const AString & a_PlayerName, const AString & a_UUID); + protected: /** The database storage for all the data. Protected by m_CS. */ @@ -204,6 +209,10 @@ protected: /** Set to true once the manager is initialized. */ bool m_IsInitialized; + + /** The MojangAPI instance that is used for translating playernames to UUIDs. + Set in Initialize(), may be NULL. */ + cMojangAPI * m_MojangAPI; /** Returns true if all the DB tables are empty, indicating a fresh new install. */ -- cgit v1.2.3 From 0daacd14d9ab678c08c45a1a1562d5ec160a3ff3 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 23 Aug 2014 03:44:04 +0200 Subject: RankMgr: Implemented default rank, added defaults. --- src/RankManager.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index 24030ef22..b93a1157d 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -127,7 +127,9 @@ public: /** Removes the specified rank. All players assigned to that rank will be re-assigned to a_ReplacementRankName. If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB, - which means they will receive the default rank the next time they are queried. */ + which means they will receive the default rank the next time they are queried. + If the rank being removed is the default rank, the default will be changed to the replacement + rank; the operation fails if there's no replacement. */ void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName); /** Removes the specified group completely. @@ -143,6 +145,7 @@ public: /** Renames the specified rank. No action if the rank name is not found. Fails if the new name is already used. + Updates the cached m_DefaultRank if the default rank is being renamed. Returns true on success, false on failure. */ bool RenameRank(const AString & a_OldName, const AString & a_NewName); @@ -198,13 +201,23 @@ public: /** Called by cMojangAPI whenever the playername-uuid pairing is discovered. Updates the DB. */ void NotifyNameUUID(const AString & a_PlayerName, const AString & a_UUID); - + + /** Sets the specified rank as the default rank. + Returns true on success, false on failure (rank not found). */ + bool SetDefaultRank(const AString & a_RankName); + + /** Returns the name of the default rank. */ + const AString & GetDefaultRank(void) const { return m_DefaultRank; } + protected: /** The database storage for all the data. Protected by m_CS. */ SQLite::Database m_DB; - /** The mutex protecting m_DB against multi-threaded access. */ + /** The name of the default rank. Kept as a cache so that queries for it don't need to go through the DB. */ + AString m_DefaultRank; + + /** The mutex protecting m_DB and m_DefaultRank against multi-threaded access. */ cCriticalSection m_CS; /** Set to true once the manager is initialized. */ @@ -221,6 +234,9 @@ protected: /** Returns true iff the specified DB table is empty. If there's an error while querying, returns false. */ bool IsDBTableEmpty(const AString & a_TableName); + + /** Creates a default set of ranks / groups / permissions. */ + void CreateDefaults(void); } ; -- cgit v1.2.3 From 8630b20c523033b359e4f9d7513cb6e4aafec1cb Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 24 Aug 2014 20:00:45 +0200 Subject: RankMgr: Default rank is applied to players without any rank. --- src/RankManager.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/RankManager.h') diff --git a/src/RankManager.h b/src/RankManager.h index b93a1157d..f364bba6a 100644 --- a/src/RankManager.h +++ b/src/RankManager.h @@ -56,13 +56,15 @@ public: The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */ void Initialize(cMojangAPI & a_MojangAPI); - /** Returns the name of the rank that the specified player has assigned to them. */ + /** Returns the name of the rank that the specified player has assigned to them. + If the player has no rank assigned, returns an empty string (NOT the default rank). */ AString GetPlayerRankName(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. */ + /** Returns the permissions that the specified player has assigned to them. + If the player has no rank assigned to them, returns the default rank's permissions. */ AStringVector GetPlayerPermissions(const AString & a_PlayerUUID); /** Returns the names of groups that the specified rank has assigned to it. -- cgit v1.2.3