Cuberite
A lightweight, fast and extensible game server for Minecraft
RankManager.h
Go to the documentation of this file.
1 
2 // RankManager.h
3 
4 // Declares the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players
5 
6 
7 
8 
9 #pragma once
10 
11 #include "SQLiteCpp/Database.h"
12 #include "SQLiteCpp/Transaction.h"
13 
14 
15 
16 
17 class cUUID;
18 class cMojangAPI;
19 
20 
21 
22 
23 
25 {
26 public:
31  {
32  public:
33  cMassChangeLock(cRankManager & a_RankManager) :
34  m_Lock(a_RankManager.m_CS),
35  m_Transaction(a_RankManager.m_DB)
36  {
37  }
38 
40  {
41  m_Transaction.commit();
42  }
43 
44  protected:
46  SQLite::Transaction m_Transaction;
47  };
48 
49 
51  cRankManager(void);
52 
53  ~cRankManager();
54 
57  void Initialize(cMojangAPI & a_MojangAPI);
58 
61  AString GetPlayerRankName(const cUUID & a_PlayerUUID);
62 
65  AString GetPlayerName(const cUUID & a_PlayerUUID);
66 
68  AStringVector GetPlayerGroups(const cUUID & a_PlayerUUID);
69 
72  AStringVector GetPlayerPermissions(const cUUID & a_PlayerUUID);
73 
76  AStringVector GetPlayerRestrictions(const cUUID & a_PlayerUUID);
77 
80  AStringVector GetRankGroups(const AString & a_RankName);
81 
84  AStringVector GetGroupPermissions(const AString & a_GroupName);
85 
88  AStringVector GetGroupRestrictions(const AString & a_GroupName);
89 
92  AStringVector GetRankPermissions(const AString & a_RankName);
93 
96  AStringVector GetRankRestrictions(const AString & a_RankName);
97 
99  std::vector<cUUID> GetAllPlayerUUIDs(void);
100 
103 
106 
109 
112 
115 
118  bool GetPlayerMsgVisuals(
119  const cUUID & a_PlayerUUID,
120  AString & a_MsgPrefix,
121  AString & a_MsgSuffix,
122  AString & a_MsgNameColorCode
123  );
124 
126  void AddRank(
127  const AString & a_RankName,
128  const AString & a_MsgPrefix,
129  const AString & a_MsgSuffix,
130  const AString & a_MsgNameColorCode
131  );
132 
134  void AddGroup(const AString & a_GroupName);
135 
137  void AddGroups(const AStringVector & a_GroupNames);
138 
142  bool AddGroupToRank(const AString & a_GroupName, const AString & a_RankName);
143 
147  bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
148 
152  bool AddRestrictionToGroup(const AString & a_Restriction, const AString & a_GroupName);
153 
157  bool AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName);
158 
162  bool AddRestrictionsToGroup(const AStringVector & a_Restrictions, const AString & a_GroupName);
163 
170  void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
171 
174  void RemoveGroup(const AString & a_GroupName);
175 
178  void RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName);
179 
181  void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName);
182 
184  void RemoveRestrictionFromGroup(const AString & a_Restriction, const AString & a_GroupName);
185 
190  bool RenameRank(const AString & a_OldName, const AString & a_NewName);
191 
195  bool RenameGroup(const AString & a_OldName, const AString & a_NewName);
196 
202  void SetPlayerRank(const cUUID & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName);
203 
208  void RemovePlayerRank(const cUUID & a_PlayerUUID);
209 
211  void SetRankVisuals(
212  const AString & a_RankName,
213  const AString & a_MsgPrefix,
214  const AString & a_MsgSuffix,
215  const AString & a_MsgNameColorCode
216  );
217 
220  bool GetRankVisuals(
221  const AString & a_RankName,
222  AString & a_MsgPrefix,
223  AString & a_MsgSuffix,
224  AString & a_MsgNameColorCode
225  );
226 
228  bool RankExists(const AString & a_RankName);
229 
231  bool GroupExists(const AString & a_GroupName);
232 
234  bool IsPlayerRankSet(const cUUID & a_PlayerUUID);
235 
237  bool IsGroupInRank(const AString & a_GroupName, const AString & a_RankName);
238 
240  bool IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName);
241 
243  bool IsRestrictionInGroup(const AString & a_Restriction, const AString & a_GroupName);
244 
246  void NotifyNameUUID(const AString & a_PlayerName, const cUUID & a_UUID);
247 
250  bool SetDefaultRank(const AString & a_RankName);
251 
253  const AString & GetDefaultRank(void) const { return m_DefaultRank; }
254 
257  void ClearPlayerRanks(void);
258 
260  bool UpdatePlayerName(const cUUID & a_PlayerUUID, const AString & a_NewPlayerName);
261 
262 protected:
263 
265  SQLite::Database m_DB;
266 
269 
272 
275 
277  bool AreDBTablesEmpty(void);
278 
281  bool IsDBTableEmpty(const AString & a_TableName);
282 
284  void CreateDefaults(void);
285 
287  bool DoesColumnExist(const char * a_TableName, const char * a_ColumnName);
288 
291  void CreateColumnIfNotExists(const char * a_TableName, const char * a_ColumnName, const char * a_ColumnType = "");
292 } ;
293 
294 
295 
296 
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
AStringVector GetGroupPermissions(const AString &a_GroupName)
Returns the permissions that the specified group has assigned to it.
void AddGroups(const AStringVector &a_GroupNames)
Bulk-adds groups.
void AddGroup(const AString &a_GroupName)
Adds a new permission group.
AStringVector GetGroupRestrictions(const AString &a_GroupName)
Returns the restrictions that the specified group has assigned to it.
bool IsPermissionInGroup(const AString &a_Permission, const AString &a_GroupName)
Returns true iff the specified group contains the specified permission.
AStringVector GetAllPermissionsRestrictions(void)
Returns all the distinct permissions and restrictions that are stored in the DB.
void RemoveRestrictionFromGroup(const AString &a_Restriction, const AString &a_GroupName)
Removes the specified restriction from the specified group.
bool GroupExists(const AString &a_GroupName)
Returns true iff the specified group exists in the DB.
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.
bool AddGroupToRank(const AString &a_GroupName, const AString &a_RankName)
Adds the specified permission group to the specified rank.
cRankManager(void)
Creates the rank manager.
Definition: RankManager.cpp:18
bool DoesColumnExist(const char *a_TableName, const char *a_ColumnName)
Returns true if the specified column exists in the specified table.
bool RenameGroup(const AString &a_OldName, const AString &a_NewName)
Renames the specified group.
bool SetDefaultRank(const AString &a_RankName)
Sets the specified rank as the default rank.
AString m_DefaultRank
The name of the default rank.
Definition: RankManager.h:268
void RemovePlayerRank(const cUUID &a_PlayerUUID)
Removes the player's rank assignment.
bool AddPermissionToGroup(const AString &a_Permission, const AString &a_GroupName)
Adds the specified permission to the specified permission group.
bool m_IsInitialized
Set to true once the manager is initialized.
Definition: RankManager.h:274
AStringVector GetPlayerPermissions(const cUUID &a_PlayerUUID)
Returns the permissions that the specified player has assigned to them.
AStringVector GetAllGroups(void)
Returns the names of all permission groups.
void AddRank(const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
Adds a new rank.
bool GetRankVisuals(const AString &a_RankName, AString &a_MsgPrefix, AString &a_MsgSuffix, AString &a_MsgNameColorCode)
Returns the message visuals of an existing rank.
const AString & GetDefaultRank(void) const
Returns the name of the default rank.
Definition: RankManager.h:253
bool IsDBTableEmpty(const AString &a_TableName)
Returns true iff the specified DB table is empty.
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.
bool RankExists(const AString &a_RankName)
Returns true iff the specified rank exists in the DB.
AStringVector GetRankPermissions(const AString &a_RankName)
Returns all permissions that the specified rank has assigned to it, through all its groups.
cCriticalSection m_CS
The mutex protecting m_DB and m_DefaultRank against multi-threaded access.
Definition: RankManager.h:271
AString GetPlayerName(const cUUID &a_PlayerUUID)
Returns the last name that the specified player has.
bool IsPlayerRankSet(const cUUID &a_PlayerUUID)
Returns true iff the specified player has a rank assigned to them in the DB.
void RemovePermissionFromGroup(const AString &a_Permission, const AString &a_GroupName)
Removes the specified permission from the specified group.
void Initialize(cMojangAPI &a_MojangAPI)
Initializes the rank manager.
Definition: RankManager.cpp:36
AStringVector GetPlayerGroups(const cUUID &a_PlayerUUID)
Returns the names of Groups that the specified player has assigned to them.
AStringVector GetAllRanks(void)
Returns the names of all defined ranks.
bool AreDBTablesEmpty(void)
Returns true if all the DB tables are empty, indicating a fresh new install.
bool AddRestrictionToGroup(const AString &a_Restriction, const AString &a_GroupName)
Adds the specified restriction to the specified group.
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.
AString GetPlayerRankName(const cUUID &a_PlayerUUID)
Returns the name of the rank that the specified player has assigned to them.
Definition: RankManager.cpp:90
void RemoveGroupFromRank(const AString &a_GroupName, const AString &a_RankName)
Removes the specified group from the specified rank.
void NotifyNameUUID(const AString &a_PlayerName, const cUUID &a_UUID)
Called by cMojangAPI whenever the playername-uuid pairing is discovered.
AStringVector GetRankGroups(const AString &a_RankName)
Returns the names of groups that the specified rank has assigned to it.
void RemoveGroup(const AString &a_GroupName)
Removes the specified group completely.
void SetPlayerRank(const cUUID &a_PlayerUUID, const AString &a_PlayerName, const AString &a_RankName)
Sets the specified player's rank.
bool UpdatePlayerName(const cUUID &a_PlayerUUID, const AString &a_NewPlayerName)
Updates the playername that is saved with this uuid.
AStringVector GetAllRestrictions(void)
Returns all the distinct restrictions that are stored in the DB.
void CreateDefaults(void)
Creates a default set of ranks / groups / permissions.
AStringVector GetRankRestrictions(const AString &a_RankName)
Returns all restrictions that the specified rank has assigned to it, through all its groups.
void RemoveRank(const AString &a_RankName, const AString &a_ReplacementRankName)
Removes the specified rank.
SQLite::Database m_DB
The database storage for all the data.
Definition: RankManager.h:265
std::vector< cUUID > GetAllPlayerUUIDs(void)
Returns the uuids of all defined players.
AStringVector GetPlayerRestrictions(const cUUID &a_PlayerUUID)
Returns the restrictions that the specified player has assigned to them.
bool RenameRank(const AString &a_OldName, const AString &a_NewName)
Renames the specified rank.
bool AddPermissionsToGroup(const AStringVector &a_Permissions, const AString &a_GroupName)
Adds the specified permissions to the specified permission group.
AStringVector GetAllPermissions(void)
Returns all the distinct permissions that are stored in the DB.
void ClearPlayerRanks(void)
Removes all player ranks from the database.
bool IsGroupInRank(const AString &a_GroupName, const AString &a_RankName)
Returns true iff the specified rank contains the specified group.
bool IsRestrictionInGroup(const AString &a_Restriction, const AString &a_GroupName)
Returns true iff the specified group contains the specified restriction.
bool AddRestrictionsToGroup(const AStringVector &a_Restrictions, const AString &a_GroupName)
Adds the specified restrictions to the specified group.
Acquire this lock to perform mass changes.
Definition: RankManager.h:31
cMassChangeLock(cRankManager &a_RankManager)
Definition: RankManager.h:33
SQLite::Transaction m_Transaction
Definition: RankManager.h:46
Definition: UUID.h:11