Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <RankManager.h>
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< cUUID > | GetAllPlayerUUIDs (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 AString & | GetDefaultRank (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... | |
cMojangAPI * | m_MojangAPI |
The MojangAPI instance that is used for translating playernames to UUIDs. More... | |
Definition at line 24 of file RankManager.h.
cRankManager::cRankManager | ( | void | ) |
Creates the rank manager.
Needs to be initialized before other use.
Definition at line 384 of file RankManager.cpp.
cRankManager::~cRankManager | ( | ) |
Definition at line 395 of file RankManager.cpp.
void cRankManager::AddGroup | ( | const AString & | a_GroupName | ) |
Adds a new permission group.
No action if such a group already exists.
Definition at line 959 of file RankManager.cpp.
void cRankManager::AddGroups | ( | const AStringVector & | a_GroupNames | ) |
Bulk-adds groups.
Group names that already exist are silently skipped.
Definition at line 999 of file RankManager.cpp.
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 1042 of file RankManager.cpp.
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 1254 of file RankManager.cpp.
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 1120 of file RankManager.cpp.
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 911 of file RankManager.cpp.
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 1324 of file RankManager.cpp.
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 1187 of file RankManager.cpp.
|
protected |
Returns true if all the DB tables are empty, indicating a fresh new install.
Definition at line 2204 of file RankManager.cpp.
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 2155 of file RankManager.cpp.
|
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 2310 of file RankManager.cpp.
|
protected |
Creates a default set of ranks / groups / permissions.
Definition at line 2238 of file RankManager.cpp.
|
protected |
Returns true if the specified column exists in the specified table.
Definition at line 2277 of file RankManager.cpp.
AStringVector cRankManager::GetAllGroups | ( | void | ) |
Returns the names of all permission groups.
Definition at line 798 of file RankManager.cpp.
AStringVector cRankManager::GetAllPermissions | ( | void | ) |
Returns all the distinct permissions that are stored in the DB.
Definition at line 823 of file RankManager.cpp.
AStringVector cRankManager::GetAllPermissionsRestrictions | ( | void | ) |
Returns all the distinct permissions and restrictions that are stored in the DB.
Definition at line 873 of file RankManager.cpp.
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 742 of file RankManager.cpp.
AStringVector cRankManager::GetAllRanks | ( | void | ) |
Returns the names of all defined ranks.
Definition at line 773 of file RankManager.cpp.
AStringVector cRankManager::GetAllRestrictions | ( | void | ) |
Returns all the distinct restrictions that are stored in the DB.
Definition at line 848 of file RankManager.cpp.
|
inline |
Returns the name of the default rank.
Definition at line 253 of file RankManager.h.
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 620 of file RankManager.cpp.
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 650 of file RankManager.cpp.
AStringVector cRankManager::GetPlayerGroups | ( | const cUUID & | a_PlayerUUID | ) |
Returns the names of Groups that the specified player has assigned to them.
Definition at line 527 of file RankManager.cpp.
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 888 of file RankManager.cpp.
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 500 of file RankManager.cpp.
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 561 of file RankManager.cpp.
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 472 of file RankManager.cpp.
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 575 of file RankManager.cpp.
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 589 of file RankManager.cpp.
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 680 of file RankManager.cpp.
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 711 of file RankManager.cpp.
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 1873 of file RankManager.cpp.
bool cRankManager::GroupExists | ( | const AString & | a_GroupName | ) |
Returns true iff the specified group exists in the DB.
Definition at line 1934 of file RankManager.cpp.
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 when migrating from old ini files, to look up player UUIDs.
Definition at line 407 of file RankManager.cpp.
|
protected |
Returns true iff the specified DB table is empty.
If there's an error while querying, returns false.
Definition at line 2220 of file RankManager.cpp.
Returns true iff the specified rank contains the specified group.
Definition at line 1988 of file RankManager.cpp.
bool cRankManager::IsPermissionInGroup | ( | const AString & | a_Permission, |
const AString & | a_GroupName | ||
) |
Returns true iff the specified group contains the specified permission.
Definition at line 2020 of file RankManager.cpp.
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 1960 of file RankManager.cpp.
bool cRankManager::IsRestrictionInGroup | ( | const AString & | a_Restriction, |
const AString & | a_GroupName | ||
) |
Returns true iff the specified group contains the specified restriction.
Definition at line 2051 of file RankManager.cpp.
Called by cMojangAPI whenever the playername-uuid pairing is discovered.
Updates the DB.
Definition at line 2082 of file RankManager.cpp.
bool cRankManager::RankExists | ( | const AString & | a_RankName | ) |
Returns true iff the specified rank exists in the DB.
Definition at line 1908 of file RankManager.cpp.
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 1480 of file RankManager.cpp.
Removes the specified group from the specified rank.
The group will stay defined, even if no rank is using it.
Definition at line 1531 of file RankManager.cpp.
void cRankManager::RemovePermissionFromGroup | ( | const AString & | a_Permission, |
const AString & | a_GroupName | ||
) |
Removes the specified permission from the specified group.
Definition at line 1583 of file RankManager.cpp.
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 1816 of file RankManager.cpp.
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 1394 of file RankManager.cpp.
void cRankManager::RemoveRestrictionFromGroup | ( | const AString & | a_Restriction, |
const AString & | a_GroupName | ||
) |
Removes the specified restriction from the specified group.
Definition at line 1623 of file RankManager.cpp.
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 1713 of file RankManager.cpp.
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 1663 of file RankManager.cpp.
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 2104 of file RankManager.cpp.
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 1754 of file RankManager.cpp.
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 1841 of file RankManager.cpp.
Updates the playername that is saved with this uuid.
Returns false if a error occurred
Definition at line 2175 of file RankManager.cpp.
|
protected |
The mutex protecting m_DB and m_DefaultRank against multi-threaded access.
Definition at line 271 of file RankManager.h.
|
protected |
The database storage for all the data.
Protected by m_CS.
Definition at line 265 of file RankManager.h.
|
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.
|
protected |
Set to true once the manager is initialized.
Definition at line 274 of file RankManager.h.
|
protected |
The MojangAPI instance that is used for translating playernames to UUIDs.
Set in Initialize(), may be nullptr.
Definition at line 278 of file RankManager.h.