Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cRankManager Class Reference

#include <RankManager.h>

Collaboration diagram for cRankManager:
Collaboration graph
[legend]

Classes

class  cMassChangeLock
 Acquire this lock to perform mass changes. More...
 

Public Member Functions

void AddGroup (const AString &a_GroupName)
 Adds a new permission group. More...
 
void AddGroups (const AStringVector &a_GroupNames)
 Bulk-adds groups. More...
 
bool AddGroupToRank (const AString &a_GroupName, const AString &a_RankName)
 Adds the specified permission group to the specified rank. More...
 
bool AddPermissionsToGroup (const AStringVector &a_Permissions, const AString &a_GroupName)
 Adds the specified permissions to the specified permission group. More...
 
bool AddPermissionToGroup (const AString &a_Permission, const AString &a_GroupName)
 Adds the specified permission to the specified permission group. More...
 
void AddRank (const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
 Adds a new rank. More...
 
bool AddRestrictionsToGroup (const AStringVector &a_Restrictions, const AString &a_GroupName)
 Adds the specified restrictions to the specified group. More...
 
bool AddRestrictionToGroup (const AString &a_Restriction, const AString &a_GroupName)
 Adds the specified restriction to the specified group. More...
 
void ClearPlayerRanks (void)
 Removes all player ranks from the database. More...
 
 cRankManager (void)
 Creates the rank manager. More...
 
AStringVector GetAllGroups (void)
 Returns the names of all permission groups. More...
 
AStringVector GetAllPermissions (void)
 Returns all the distinct permissions that are stored in the DB. More...
 
AStringVector GetAllPermissionsRestrictions (void)
 Returns all the distinct permissions and restrictions that are stored in the DB. More...
 
std::vector< cUUIDGetAllPlayerUUIDs (void)
 Returns the uuids of all defined players. More...
 
AStringVector GetAllRanks (void)
 Returns the names of all defined ranks. More...
 
AStringVector GetAllRestrictions (void)
 Returns all the distinct restrictions that are stored in the DB. More...
 
const AStringGetDefaultRank (void) const
 Returns the name of the default rank. More...
 
AStringVector GetGroupPermissions (const AString &a_GroupName)
 Returns the permissions that the specified group has assigned to it. More...
 
AStringVector GetGroupRestrictions (const AString &a_GroupName)
 Returns the restrictions that the specified group has assigned to it. More...
 
AStringVector GetPlayerGroups (const cUUID &a_PlayerUUID)
 Returns the names of Groups that the specified player has assigned to them. More...
 
bool GetPlayerMsgVisuals (const cUUID &a_PlayerUUID, AString &a_MsgPrefix, AString &a_MsgSuffix, AString &a_MsgNameColorCode)
 Returns the message visuals (prefix, postfix, color) for the specified player. More...
 
AString GetPlayerName (const cUUID &a_PlayerUUID)
 Returns the last name that the specified player has. More...
 
AStringVector GetPlayerPermissions (const cUUID &a_PlayerUUID)
 Returns the permissions that the specified player has assigned to them. More...
 
AString GetPlayerRankName (const cUUID &a_PlayerUUID)
 Returns the name of the rank that the specified player has assigned to them. More...
 
AStringVector GetPlayerRestrictions (const cUUID &a_PlayerUUID)
 Returns the restrictions that the specified player has assigned to them. More...
 
AStringVector GetRankGroups (const AString &a_RankName)
 Returns the names of groups that the specified rank has assigned to it. More...
 
AStringVector GetRankPermissions (const AString &a_RankName)
 Returns all permissions that the specified rank has assigned to it, through all its groups. More...
 
AStringVector GetRankRestrictions (const AString &a_RankName)
 Returns all restrictions that the specified rank has assigned to it, through all its groups. More...
 
bool GetRankVisuals (const AString &a_RankName, AString &a_MsgPrefix, AString &a_MsgSuffix, AString &a_MsgNameColorCode)
 Returns the message visuals of an existing rank. More...
 
bool GroupExists (const AString &a_GroupName)
 Returns true iff the specified group exists in the DB. More...
 
void Initialize (cMojangAPI &a_MojangAPI)
 Initializes the rank manager. More...
 
bool IsGroupInRank (const AString &a_GroupName, const AString &a_RankName)
 Returns true iff the specified rank contains the specified group. More...
 
bool IsPermissionInGroup (const AString &a_Permission, const AString &a_GroupName)
 Returns true iff the specified group contains the specified permission. More...
 
bool IsPlayerRankSet (const cUUID &a_PlayerUUID)
 Returns true iff the specified player has a rank assigned to them in the DB. More...
 
bool IsRestrictionInGroup (const AString &a_Restriction, const AString &a_GroupName)
 Returns true iff the specified group contains the specified restriction. More...
 
void NotifyNameUUID (const AString &a_PlayerName, const cUUID &a_UUID)
 Called by cMojangAPI whenever the playername-uuid pairing is discovered. More...
 
bool RankExists (const AString &a_RankName)
 Returns true iff the specified rank exists in the DB. More...
 
void RemoveGroup (const AString &a_GroupName)
 Removes the specified group completely. More...
 
void RemoveGroupFromRank (const AString &a_GroupName, const AString &a_RankName)
 Removes the specified group from the specified rank. More...
 
void RemovePermissionFromGroup (const AString &a_Permission, const AString &a_GroupName)
 Removes the specified permission from the specified group. More...
 
void RemovePlayerRank (const cUUID &a_PlayerUUID)
 Removes the player's rank assignment. More...
 
void RemoveRank (const AString &a_RankName, const AString &a_ReplacementRankName)
 Removes the specified rank. More...
 
void RemoveRestrictionFromGroup (const AString &a_Restriction, const AString &a_GroupName)
 Removes the specified restriction from the specified group. More...
 
bool RenameGroup (const AString &a_OldName, const AString &a_NewName)
 Renames the specified group. More...
 
bool RenameRank (const AString &a_OldName, const AString &a_NewName)
 Renames the specified rank. More...
 
bool SetDefaultRank (const AString &a_RankName)
 Sets the specified rank as the default rank. More...
 
void SetPlayerRank (const cUUID &a_PlayerUUID, const AString &a_PlayerName, const AString &a_RankName)
 Sets the specified player's rank. More...
 
void SetRankVisuals (const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
 Sets the message visuals of an existing rank. More...
 
bool UpdatePlayerName (const cUUID &a_PlayerUUID, const AString &a_NewPlayerName)
 Updates the playername that is saved with this uuid. More...
 
 ~cRankManager ()
 

Protected Member Functions

bool AreDBTablesEmpty (void)
 Returns true if all the DB tables are empty, indicating a fresh new install. More...
 
void CreateColumnIfNotExists (const char *a_TableName, const char *a_ColumnName, const char *a_ColumnType="")
 If the specified table doesn't contain the specified column, it is added to the table. More...
 
void CreateDefaults (void)
 Creates a default set of ranks / groups / permissions. More...
 
bool DoesColumnExist (const char *a_TableName, const char *a_ColumnName)
 Returns true if the specified column exists in the specified table. More...
 
bool IsDBTableEmpty (const AString &a_TableName)
 Returns true iff the specified DB table is empty. More...
 

Protected Attributes

cCriticalSection m_CS
 The mutex protecting m_DB and m_DefaultRank against multi-threaded access. More...
 
SQLite::Database m_DB
 The database storage for all the data. More...
 
AString m_DefaultRank
 The name of the default rank. More...
 
bool m_IsInitialized
 Set to true once the manager is initialized. More...
 
cMojangAPIm_MojangAPI
 The MojangAPI instance that is used for keeping player names and UUIDs in sync. More...
 

Detailed Description

Definition at line 24 of file RankManager.h.

Constructor & Destructor Documentation

◆ cRankManager()

cRankManager::cRankManager ( void  )

Creates the rank manager.

Needs to be initialized before other use.

Definition at line 18 of file RankManager.cpp.

◆ ~cRankManager()

cRankManager::~cRankManager ( )

Definition at line 29 of file RankManager.cpp.

Member Function Documentation

◆ AddGroup()

void cRankManager::AddGroup ( const AString a_GroupName)

Adds a new permission group.

No action if such a group already exists.

Definition at line 582 of file RankManager.cpp.

◆ AddGroups()

void cRankManager::AddGroups ( const AStringVector a_GroupNames)

Bulk-adds groups.

Group names that already exist are silently skipped.

Definition at line 622 of file RankManager.cpp.

◆ AddGroupToRank()

bool cRankManager::AddGroupToRank ( const AString a_GroupName,
const AString a_RankName 
)

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.

Definition at line 665 of file RankManager.cpp.

◆ AddPermissionsToGroup()

bool cRankManager::AddPermissionsToGroup ( const AStringVector a_Permissions,
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.

Definition at line 877 of file RankManager.cpp.

◆ AddPermissionToGroup()

bool cRankManager::AddPermissionToGroup ( const AString a_Permission,
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.

Definition at line 743 of file RankManager.cpp.

◆ AddRank()

void cRankManager::AddRank ( const AString a_RankName,
const AString a_MsgPrefix,
const AString a_MsgSuffix,
const AString a_MsgNameColorCode 
)

Adds a new rank.

No action if the rank already exists.

Definition at line 534 of file RankManager.cpp.

◆ AddRestrictionsToGroup()

bool cRankManager::AddRestrictionsToGroup ( const AStringVector a_Restrictions,
const AString a_GroupName 
)

Adds the specified restrictions to the specified group.

Fails if the group name is not found. Returns true if successful, false on error.

Definition at line 947 of file RankManager.cpp.

◆ AddRestrictionToGroup()

bool cRankManager::AddRestrictionToGroup ( const AString a_Restriction,
const AString a_GroupName 
)

Adds the specified restriction to the specified group.

Fails if the group name is not found. Returns true if successful, false on error.

Definition at line 810 of file RankManager.cpp.

◆ AreDBTablesEmpty()

bool cRankManager::AreDBTablesEmpty ( void  )
protected

Returns true if all the DB tables are empty, indicating a fresh new install.

Definition at line 1827 of file RankManager.cpp.

◆ ClearPlayerRanks()

void cRankManager::ClearPlayerRanks ( void  )

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.

Definition at line 1778 of file RankManager.cpp.

◆ CreateColumnIfNotExists()

void cRankManager::CreateColumnIfNotExists ( const char *  a_TableName,
const char *  a_ColumnName,
const char *  a_ColumnType = "" 
)
protected

If the specified table doesn't contain the specified column, it is added to the table.

The column type is used only when creating the column, it is not used when checking for existence.

Definition at line 1933 of file RankManager.cpp.

◆ CreateDefaults()

void cRankManager::CreateDefaults ( void  )
protected

Creates a default set of ranks / groups / permissions.

Definition at line 1861 of file RankManager.cpp.

◆ DoesColumnExist()

bool cRankManager::DoesColumnExist ( const char *  a_TableName,
const char *  a_ColumnName 
)
protected

Returns true if the specified column exists in the specified table.

Definition at line 1900 of file RankManager.cpp.

◆ GetAllGroups()

AStringVector cRankManager::GetAllGroups ( void  )

Returns the names of all permission groups.

Definition at line 421 of file RankManager.cpp.

◆ GetAllPermissions()

AStringVector cRankManager::GetAllPermissions ( void  )

Returns all the distinct permissions that are stored in the DB.

Definition at line 446 of file RankManager.cpp.

◆ GetAllPermissionsRestrictions()

AStringVector cRankManager::GetAllPermissionsRestrictions ( void  )

Returns all the distinct permissions and restrictions that are stored in the DB.

Definition at line 496 of file RankManager.cpp.

◆ GetAllPlayerUUIDs()

std::vector< cUUID > cRankManager::GetAllPlayerUUIDs ( void  )

Returns the uuids of all defined players.

The returned players are ordered by their name (NOT their UUIDs).

Definition at line 365 of file RankManager.cpp.

◆ GetAllRanks()

AStringVector cRankManager::GetAllRanks ( void  )

Returns the names of all defined ranks.

Definition at line 396 of file RankManager.cpp.

◆ GetAllRestrictions()

AStringVector cRankManager::GetAllRestrictions ( void  )

Returns all the distinct restrictions that are stored in the DB.

Definition at line 471 of file RankManager.cpp.

◆ GetDefaultRank()

const AString& cRankManager::GetDefaultRank ( void  ) const
inline

Returns the name of the default rank.

Definition at line 253 of file RankManager.h.

◆ GetGroupPermissions()

AStringVector cRankManager::GetGroupPermissions ( const AString a_GroupName)

Returns the permissions that the specified group has assigned to it.

Returns an empty vector if the group doesn't exist.

Definition at line 243 of file RankManager.cpp.

◆ GetGroupRestrictions()

AStringVector cRankManager::GetGroupRestrictions ( const AString a_GroupName)

Returns the restrictions that the specified group has assigned to it.

Returns an empty vector if the group doesn't exist.

Definition at line 273 of file RankManager.cpp.

◆ GetPlayerGroups()

AStringVector cRankManager::GetPlayerGroups ( const cUUID a_PlayerUUID)

Returns the names of Groups that the specified player has assigned to them.

Definition at line 150 of file RankManager.cpp.

◆ GetPlayerMsgVisuals()

bool cRankManager::GetPlayerMsgVisuals ( const cUUID a_PlayerUUID,
AString a_MsgPrefix,
AString a_MsgSuffix,
AString a_MsgNameColorCode 
)

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).

Definition at line 511 of file RankManager.cpp.

◆ GetPlayerName()

AString cRankManager::GetPlayerName ( const cUUID a_PlayerUUID)

Returns the last name that the specified player has.

An empty string is returned if the player isn't in the database.

Definition at line 123 of file RankManager.cpp.

◆ GetPlayerPermissions()

AStringVector cRankManager::GetPlayerPermissions ( const cUUID a_PlayerUUID)

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.

Definition at line 184 of file RankManager.cpp.

◆ GetPlayerRankName()

AString cRankManager::GetPlayerRankName ( const cUUID a_PlayerUUID)

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).

Definition at line 95 of file RankManager.cpp.

◆ GetPlayerRestrictions()

AStringVector cRankManager::GetPlayerRestrictions ( const cUUID a_PlayerUUID)

Returns the restrictions that the specified player has assigned to them.

If the player has no rank assigned to them, returns the default rank's restrictions.

Definition at line 198 of file RankManager.cpp.

◆ GetRankGroups()

AStringVector cRankManager::GetRankGroups ( const AString a_RankName)

Returns the names of groups that the specified rank has assigned to it.

Returns an empty vector if the rank doesn't exist.

Definition at line 212 of file RankManager.cpp.

◆ GetRankPermissions()

AStringVector cRankManager::GetRankPermissions ( const AString a_RankName)

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.

Definition at line 303 of file RankManager.cpp.

◆ GetRankRestrictions()

AStringVector cRankManager::GetRankRestrictions ( const AString a_RankName)

Returns all restrictions 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.

Definition at line 334 of file RankManager.cpp.

◆ GetRankVisuals()

bool cRankManager::GetRankVisuals ( const AString a_RankName,
AString a_MsgPrefix,
AString a_MsgSuffix,
AString a_MsgNameColorCode 
)

Returns the message visuals of an existing rank.

Returns true if successful, false on error (rank doesn't exist).

Definition at line 1496 of file RankManager.cpp.

◆ GroupExists()

bool cRankManager::GroupExists ( const AString a_GroupName)

Returns true iff the specified group exists in the DB.

Definition at line 1557 of file RankManager.cpp.

◆ Initialize()

void cRankManager::Initialize ( cMojangAPI a_MojangAPI)

Initializes the rank manager.

Performs migration and default-setting if no data is found in the DB. The a_MojangAPI param is used to keep player names in sync with UUIDs, since Mojang allows username changes.

Definition at line 41 of file RankManager.cpp.

◆ IsDBTableEmpty()

bool cRankManager::IsDBTableEmpty ( const AString a_TableName)
protected

Returns true iff the specified DB table is empty.

If there's an error while querying, returns false.

Definition at line 1843 of file RankManager.cpp.

◆ IsGroupInRank()

bool cRankManager::IsGroupInRank ( const AString a_GroupName,
const AString a_RankName 
)

Returns true iff the specified rank contains the specified group.

Definition at line 1611 of file RankManager.cpp.

◆ IsPermissionInGroup()

bool cRankManager::IsPermissionInGroup ( const AString a_Permission,
const AString a_GroupName 
)

Returns true iff the specified group contains the specified permission.

Definition at line 1643 of file RankManager.cpp.

◆ IsPlayerRankSet()

bool cRankManager::IsPlayerRankSet ( const cUUID a_PlayerUUID)

Returns true iff the specified player has a rank assigned to them in the DB.

Definition at line 1583 of file RankManager.cpp.

◆ IsRestrictionInGroup()

bool cRankManager::IsRestrictionInGroup ( const AString a_Restriction,
const AString a_GroupName 
)

Returns true iff the specified group contains the specified restriction.

Definition at line 1674 of file RankManager.cpp.

◆ NotifyNameUUID()

void cRankManager::NotifyNameUUID ( const AString a_PlayerName,
const cUUID a_UUID 
)

Called by cMojangAPI whenever the playername-uuid pairing is discovered.

Updates the DB.

Definition at line 1705 of file RankManager.cpp.

◆ RankExists()

bool cRankManager::RankExists ( const AString a_RankName)

Returns true iff the specified rank exists in the DB.

Definition at line 1531 of file RankManager.cpp.

◆ RemoveGroup()

void cRankManager::RemoveGroup ( const AString a_GroupName)

Removes the specified group completely.

The group will first be removed from all ranks using it, and then removed itself.

Definition at line 1103 of file RankManager.cpp.

◆ RemoveGroupFromRank()

void cRankManager::RemoveGroupFromRank ( const AString a_GroupName,
const AString a_RankName 
)

Removes the specified group from the specified rank.

The group will stay defined, even if no rank is using it.

Definition at line 1154 of file RankManager.cpp.

◆ RemovePermissionFromGroup()

void cRankManager::RemovePermissionFromGroup ( const AString a_Permission,
const AString a_GroupName 
)

Removes the specified permission from the specified group.

Definition at line 1206 of file RankManager.cpp.

◆ RemovePlayerRank()

void cRankManager::RemovePlayerRank ( const cUUID a_PlayerUUID)

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.

Definition at line 1439 of file RankManager.cpp.

◆ RemoveRank()

void cRankManager::RemoveRank ( const AString a_RankName,
const AString a_ReplacementRankName 
)

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. If the rank being removed is the default rank, the default will be changed to the replacement rank; the operation fails silently if there's no replacement.

Definition at line 1017 of file RankManager.cpp.

◆ RemoveRestrictionFromGroup()

void cRankManager::RemoveRestrictionFromGroup ( const AString a_Restriction,
const AString a_GroupName 
)

Removes the specified restriction from the specified group.

Definition at line 1246 of file RankManager.cpp.

◆ RenameGroup()

bool cRankManager::RenameGroup ( const AString a_OldName,
const AString a_NewName 
)

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.

Definition at line 1336 of file RankManager.cpp.

◆ RenameRank()

bool cRankManager::RenameRank ( const AString a_OldName,
const AString a_NewName 
)

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.

Definition at line 1286 of file RankManager.cpp.

◆ SetDefaultRank()

bool cRankManager::SetDefaultRank ( const AString a_RankName)

Sets the specified rank as the default rank.

Returns true on success, false on failure (rank not found).

Definition at line 1727 of file RankManager.cpp.

◆ SetPlayerRank()

void cRankManager::SetPlayerRank ( const cUUID a_PlayerUUID,
const AString a_PlayerName,
const AString a_RankName 
)

Sets the specified player's 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. The PlayerName is provided for reference, so that GetRankPlayerNames() can work.

Definition at line 1377 of file RankManager.cpp.

◆ SetRankVisuals()

void cRankManager::SetRankVisuals ( const AString a_RankName,
const AString a_MsgPrefix,
const AString a_MsgSuffix,
const AString a_MsgNameColorCode 
)

Sets the message visuals of an existing rank.

No action if the rank name is not found.

Definition at line 1464 of file RankManager.cpp.

◆ UpdatePlayerName()

bool cRankManager::UpdatePlayerName ( const cUUID a_PlayerUUID,
const AString a_NewPlayerName 
)

Updates the playername that is saved with this uuid.

Returns false if a error occurred

Definition at line 1798 of file RankManager.cpp.

Member Data Documentation

◆ m_CS

cCriticalSection cRankManager::m_CS
protected

The mutex protecting m_DB and m_DefaultRank against multi-threaded access.

Definition at line 271 of file RankManager.h.

◆ m_DB

SQLite::Database cRankManager::m_DB
protected

The database storage for all the data.

Protected by m_CS.

Definition at line 265 of file RankManager.h.

◆ m_DefaultRank

AString cRankManager::m_DefaultRank
protected

The name of the default rank.

Kept as a cache so that queries for it don't need to go through the DB.

Definition at line 268 of file RankManager.h.

◆ m_IsInitialized

bool cRankManager::m_IsInitialized
protected

Set to true once the manager is initialized.

Definition at line 274 of file RankManager.h.

◆ m_MojangAPI

cMojangAPI* cRankManager::m_MojangAPI
protected

The MojangAPI instance that is used for keeping player names and UUIDs in sync.

Set in Initialize(), may be nullptr.

Definition at line 278 of file RankManager.h.


The documentation for this class was generated from the following files: