Cuberite
A lightweight, fast and extensible game server for Minecraft
RankManager.cpp
Go to the documentation of this file.
1 
2 // RankManager.cpp
3 
4 // Implements the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players
5 
6 #include "Globals.h"
7 #include "RankManager.h"
8 #include "Protocol/MojangAPI.h"
9 #include "ClientHandle.h"
10 
11 
12 
13 
14 
16 // cRankManager:
17 
19  m_DB("Ranks.sqlite", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE),
20  m_IsInitialized(false),
21  m_MojangAPI(nullptr)
22 {
23 }
24 
25 
26 
27 
28 
30 {
31  if (m_MojangAPI != nullptr)
32  {
33  m_MojangAPI->SetRankManager(nullptr);
34  }
35 }
36 
37 
38 
39 
40 
42 {
43  ASSERT(!m_IsInitialized); // Calling Initialize for the second time?
44 
45  // Create the DB tables, if they don't exist:
46  m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgSuffix, MsgNameColorCode)");
47  m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
48  m_DB.exec("CREATE TABLE IF NOT EXISTS PermGroup (PermGroupID INTEGER PRIMARY KEY, Name)");
49  m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
50  m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (PermGroupID INTEGER, Permission)");
51  m_DB.exec("CREATE TABLE IF NOT EXISTS RestrictionItem (PermGroupID INTEGER, Permission)");
52  m_DB.exec("CREATE TABLE IF NOT EXISTS DefaultRank (RankID INTEGER)");
53 
54  m_IsInitialized = true;
55 
56  a_MojangAPI.SetRankManager(this);
57 
58  // If tables are empty, create default ranks
59  if (AreDBTablesEmpty())
60  {
61  LOGINFO("Creating default ranks...");
63  LOGINFO("Default ranks created.");
64  }
65 
66  // Load the default rank:
67  try
68  {
69  SQLite::Statement stmt(m_DB,
70  "SELECT Rank.Name FROM Rank "
71  "LEFT JOIN DefaultRank ON Rank.RankID = DefaultRank.RankID"
72  );
73  if (stmt.executeStep())
74  {
75  m_DefaultRank = stmt.getColumn(0).getText();
76  }
77  }
78  catch (const SQLite::Exception & ex)
79  {
80  LOGWARNING("%s: Cannot load default rank: %s", __FUNCTION__, ex.what());
81  return;
82  }
83 
84  // If the default rank cannot be loaded, use the first rank:
85  if (m_DefaultRank.empty())
86  {
88  }
89 }
90 
91 
92 
93 
94 
96 {
98  cCSLock Lock(m_CS);
99 
100  try
101  {
102  SQLite::Statement stmt(m_DB, "SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
103  stmt.bind(1, a_PlayerUUID.ToShortString());
104  // executeStep returns false on no data
105  if (!stmt.executeStep())
106  {
107  // No data returned from the DB
108  return AString();
109  }
110  return stmt.getColumn(0).getText();
111  }
112  catch (const SQLite::Exception & ex)
113  {
114  LOGWARNING("%s: Cannot get player rank name: %s", __FUNCTION__, ex.what());
115  }
116  return AString();
117 }
118 
119 
120 
121 
122 
124 {
126  cCSLock Lock(m_CS);
127 
128  try
129  {
130  // Prepare the DB statement:
131  SQLite::Statement stmt(m_DB, "SELECT PlayerName FROM PlayerRank WHERE PlayerUUID = ?");
132  stmt.bind(1, a_PlayerUUID.ToShortString());
133 
134  if (stmt.executeStep())
135  {
136  return stmt.getColumn(0).getText();
137  }
138  }
139  catch (SQLite::Exception & ex)
140  {
141  LOGWARNING("%s: Cannot get player name: %s", __FUNCTION__, ex.what());
142  }
143  return AString();
144 }
145 
146 
147 
148 
149 
151 {
153  cCSLock Lock(m_CS);
154 
155  AStringVector res;
156  try
157  {
158  // Prepare the DB statement:
159  SQLite::Statement stmt(m_DB,
160  "SELECT PermGroup.Name FROM PermGroup "
161  "LEFT JOIN RankPermGroup ON PermGroup.PermGroupID = RankPermGroup.PermGroupID "
162  "LEFT JOIN PlayerRank ON PlayerRank.RankID = RankPermGroup.RankID "
163  "WHERE PlayerRank.PlayerUUID = ?"
164  );
165  stmt.bind(1, a_PlayerUUID.ToShortString());
166 
167  // Execute and get results:
168  while (stmt.executeStep())
169  {
170  res.push_back(stmt.getColumn(0).getText());
171  }
172  }
173  catch (const SQLite::Exception & ex)
174  {
175  LOGWARNING("%s: Cannot get player groups: %s", __FUNCTION__, ex.what());
176  }
177  return res;
178 }
179 
180 
181 
182 
183 
185 {
186  AString Rank = GetPlayerRankName(a_PlayerUUID);
187  if (Rank.empty())
188  {
189  Rank = m_DefaultRank;
190  }
191  return GetRankPermissions(Rank);
192 }
193 
194 
195 
196 
197 
199 {
200  AString Rank = GetPlayerRankName(a_PlayerUUID);
201  if (Rank.empty())
202  {
203  Rank = m_DefaultRank;
204  }
205  return GetRankRestrictions(Rank);
206 }
207 
208 
209 
210 
211 
213 {
215  cCSLock Lock(m_CS);
216 
217  AStringVector res;
218  try
219  {
220  SQLite::Statement stmt(m_DB,
221  "SELECT PermGroup.Name FROM PermGroup "
222  "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID "
223  "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
224  "WHERE Rank.Name = ?"
225  );
226  stmt.bind(1, a_RankName);
227  while (stmt.executeStep())
228  {
229  res.push_back(stmt.getColumn(0).getText());
230  }
231  }
232  catch (const SQLite::Exception & ex)
233  {
234  LOGWARNING("%s: Failed to get rank groups from DB: %s", __FUNCTION__, ex.what());
235  }
236  return res;
237 }
238 
239 
240 
241 
242 
244 {
246  cCSLock Lock(m_CS);
247 
248  AStringVector res;
249  try
250  {
251  SQLite::Statement stmt(m_DB,
252  "SELECT PermissionItem.Permission FROM PermissionItem "
253  "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID "
254  "WHERE PermGroup.Name = ?"
255  );
256  stmt.bind(1, a_GroupName);
257  while (stmt.executeStep())
258  {
259  res.push_back(stmt.getColumn(0).getText());
260  }
261  }
262  catch (const SQLite::Exception & ex)
263  {
264  LOGWARNING("%s: Failed to get group permissions from DB: %s", __FUNCTION__, ex.what());
265  }
266  return res;
267 }
268 
269 
270 
271 
272 
274 {
276  cCSLock Lock(m_CS);
277 
278  AStringVector res;
279  try
280  {
281  SQLite::Statement stmt(m_DB,
282  "SELECT RestrictionItem.Permission FROM RestrictionItem "
283  "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RestrictionItem.PermGroupID "
284  "WHERE PermGroup.Name = ?"
285  );
286  stmt.bind(1, a_GroupName);
287  while (stmt.executeStep())
288  {
289  res.push_back(stmt.getColumn(0).getText());
290  }
291  }
292  catch (const SQLite::Exception & ex)
293  {
294  LOGWARNING("%s: Failed to get group restrictions from DB: %s", __FUNCTION__, ex.what());
295  }
296  return res;
297 }
298 
299 
300 
301 
302 
304 {
306  cCSLock Lock(m_CS);
307 
308  AStringVector res;
309  try
310  {
311  SQLite::Statement stmt(m_DB,
312  "SELECT PermissionItem.Permission FROM PermissionItem "
313  "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermissionItem.PermGroupID "
314  "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
315  "WHERE Rank.Name = ?"
316  );
317  stmt.bind(1, a_RankName);
318  while (stmt.executeStep())
319  {
320  res.push_back(stmt.getColumn(0).getText());
321  }
322  }
323  catch (const SQLite::Exception & ex)
324  {
325  LOGWARNING("%s: Failed to get rank permissions from DB: %s", __FUNCTION__, ex.what());
326  }
327  return res;
328 }
329 
330 
331 
332 
333 
335 {
337  cCSLock Lock(m_CS);
338 
339  AStringVector res;
340  try
341  {
342  SQLite::Statement stmt(m_DB,
343  "SELECT RestrictionItem.Permission FROM RestrictionItem "
344  "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = RestrictionItem.PermGroupID "
345  "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
346  "WHERE Rank.Name = ?"
347  );
348  stmt.bind(1, a_RankName);
349  while (stmt.executeStep())
350  {
351  res.push_back(stmt.getColumn(0).getText());
352  }
353  }
354  catch (const SQLite::Exception & ex)
355  {
356  LOGWARNING("%s: Failed to get rank restrictions from DB: %s", __FUNCTION__, ex.what());
357  }
358  return res;
359 }
360 
361 
362 
363 
364 
365 std::vector<cUUID> cRankManager::GetAllPlayerUUIDs(void)
366 {
368  cCSLock Lock(m_CS);
369 
370  cUUID tempUUID;
371  std::vector<cUUID> res;
372  try
373  {
374  SQLite::Statement stmt(m_DB, "SELECT PlayerUUID FROM PlayerRank ORDER BY PlayerName COLLATE NOCASE");
375  while (stmt.executeStep())
376  {
377  if (!tempUUID.FromString(stmt.getColumn(0).getText()))
378  {
379  // Invalid UUID, ignore
380  continue;
381  }
382  res.push_back(tempUUID);
383  }
384  }
385  catch (const SQLite::Exception & ex)
386  {
387  LOGWARNING("%s: Failed to get players from DB: %s", __FUNCTION__, ex.what());
388  }
389  return res;
390 }
391 
392 
393 
394 
395 
397 {
399  cCSLock Lock(m_CS);
400 
401  AStringVector res;
402  try
403  {
404  SQLite::Statement stmt(m_DB, "SELECT Name FROM Rank");
405  while (stmt.executeStep())
406  {
407  res.push_back(stmt.getColumn(0).getText());
408  }
409  }
410  catch (const SQLite::Exception & ex)
411  {
412  LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
413  }
414  return res;
415 }
416 
417 
418 
419 
420 
422 {
424  cCSLock Lock(m_CS);
425 
426  AStringVector res;
427  try
428  {
429  SQLite::Statement stmt(m_DB, "SELECT Name FROM PermGroup");
430  while (stmt.executeStep())
431  {
432  res.push_back(stmt.getColumn(0).getText());
433  }
434  }
435  catch (const SQLite::Exception & ex)
436  {
437  LOGWARNING("%s: Failed to get groups from DB: %s", __FUNCTION__, ex.what());
438  }
439  return res;
440 }
441 
442 
443 
444 
445 
447 {
449  cCSLock Lock(m_CS);
450 
451  AStringVector res;
452  try
453  {
454  SQLite::Statement stmt(m_DB, "SELECT DISTINCT(Permission) FROM PermissionItem");
455  while (stmt.executeStep())
456  {
457  res.push_back(stmt.getColumn(0).getText());
458  }
459  }
460  catch (const SQLite::Exception & ex)
461  {
462  LOGWARNING("%s: Failed to get permissions from DB: %s", __FUNCTION__, ex.what());
463  }
464  return res;
465 }
466 
467 
468 
469 
470 
472 {
474  cCSLock Lock(m_CS);
475 
476  AStringVector res;
477  try
478  {
479  SQLite::Statement stmt(m_DB, "SELECT DISTINCT(Permission) FROM RestrictionItem");
480  while (stmt.executeStep())
481  {
482  res.push_back(stmt.getColumn(0).getText());
483  }
484  }
485  catch (const SQLite::Exception & ex)
486  {
487  LOGWARNING("%s: Failed to get restrictions from DB: %s", __FUNCTION__, ex.what());
488  }
489  return res;
490 }
491 
492 
493 
494 
495 
497 {
498  AStringVector Permissions = GetAllPermissions();
499  AStringVector Restrictions = GetAllRestrictions();
500  for (auto & restriction: Restrictions)
501  {
502  Permissions.push_back(restriction);
503  }
504  return Permissions;
505 }
506 
507 
508 
509 
510 
512  const cUUID & a_PlayerUUID,
513  AString & a_MsgPrefix,
514  AString & a_MsgSuffix,
515  AString & a_MsgNameColorCode
516 )
517 {
518  AString Rank = GetPlayerRankName(a_PlayerUUID);
519  if (Rank.empty())
520  {
521  // Rank not found, return failure:
522  a_MsgPrefix.clear();
523  a_MsgSuffix.clear();
524  a_MsgNameColorCode.clear();
525  return false;
526  }
527  return GetRankVisuals(Rank, a_MsgPrefix, a_MsgSuffix, a_MsgNameColorCode);
528 }
529 
530 
531 
532 
533 
535  const AString & a_RankName,
536  const AString & a_MsgPrefix,
537  const AString & a_MsgSuffix,
538  const AString & a_MsgNameColorCode
539 )
540 {
542  cCSLock Lock(m_CS);
543 
544  try
545  {
546  // Check if such a rank name is already used:
547  {
548  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM Rank WHERE Name = ?");
549  stmt.bind(1, a_RankName);
550  if (stmt.executeStep())
551  {
552  if (stmt.getColumn(0).getInt() > 0)
553  {
554  // Rank already exists, do nothing:
555  return;
556  }
557  }
558  }
559 
560  // Insert a new rank:
561  SQLite::Statement stmt(m_DB, "INSERT INTO Rank (Name, MsgPrefix, MsgSuffix, MsgNameColorCode) VALUES (?, ?, ?, ?)");
562  stmt.bind(1, a_RankName);
563  stmt.bind(2, a_MsgPrefix);
564  stmt.bind(3, a_MsgSuffix);
565  stmt.bind(4, a_MsgNameColorCode);
566  if (stmt.exec() <= 0)
567  {
568  LOGWARNING("%s: Failed to add a new rank \"%s\".", __FUNCTION__, a_RankName.c_str());
569  return;
570  }
571  }
572  catch (const SQLite::Exception & ex)
573  {
574  LOGWARNING("%s: Failed to add a new rank \"%s\": %s", __FUNCTION__, a_RankName.c_str(), ex.what());
575  }
576 }
577 
578 
579 
580 
581 
582 void cRankManager::AddGroup(const AString & a_GroupName)
583 {
585  cCSLock Lock(m_CS);
586 
587  try
588  {
589  // Check if such a group name is already used:
590  {
591  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
592  stmt.bind(1, a_GroupName);
593  if (stmt.executeStep())
594  {
595  if (stmt.getColumn(0).getInt() > 0)
596  {
597  // Group already exists, do nothing:
598  return;
599  }
600  }
601  }
602 
603  // Insert a new group:
604  SQLite::Statement stmt(m_DB, "INSERT INTO PermGroup (Name) VALUES (?)");
605  stmt.bind(1, a_GroupName);
606  if (stmt.exec() <= 0)
607  {
608  LOGWARNING("%s: Failed to add a new group \"%s\".", __FUNCTION__, a_GroupName.c_str());
609  return;
610  }
611  }
612  catch (const SQLite::Exception & ex)
613  {
614  LOGWARNING("%s: Failed to add a new group \"%s\": %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
615  }
616 }
617 
618 
619 
620 
621 
622 void cRankManager::AddGroups(const AStringVector & a_GroupNames)
623 {
625  cCSLock Lock(m_CS);
626 
627  try
628  {
629  for (AStringVector::const_iterator itr = a_GroupNames.begin(), end = a_GroupNames.end(); itr != end; ++itr)
630  {
631  // Check if such the group name is already used:
632  {
633  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
634  stmt.bind(1, *itr);
635  if (stmt.executeStep())
636  {
637  if (stmt.getColumn(0).getInt() > 0)
638  {
639  // Group already exists, do nothing:
640  return;
641  }
642  }
643  }
644 
645  // Insert a new group:
646  SQLite::Statement stmt(m_DB, "INSERT INTO PermGroup (Name) VALUES (?)");
647  stmt.bind(1, *itr);
648  if (stmt.exec() <= 0)
649  {
650  LOGWARNING("%s: Failed to add a new group \"%s\".", __FUNCTION__, itr->c_str());
651  return;
652  }
653  } // for itr - a_GroupNames[]
654  }
655  catch (const SQLite::Exception & ex)
656  {
657  LOGWARNING("%s: Failed to add new groups: %s", __FUNCTION__, ex.what());
658  }
659 }
660 
661 
662 
663 
664 
665 bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a_RankName)
666 {
668  cCSLock Lock(m_CS);
669 
670  try
671  {
672  // Get the group's ID:
673  int GroupID;
674  {
675  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
676  stmt.bind(1, a_GroupName);
677  if (!stmt.executeStep())
678  {
679  LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
680  return false;
681  }
682  GroupID = stmt.getColumn(0);
683  }
684 
685  // Get the rank's ID:
686  int RankID;
687  {
688  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
689  stmt.bind(1, a_RankName);
690  if (!stmt.executeStep())
691  {
692  LOGWARNING("%s: No such rank (%s), aborting.", __FUNCTION__, a_RankName.c_str());
693  return false;
694  }
695  RankID = stmt.getColumn(0);
696  }
697 
698  // Check if the group is already there:
699  {
700  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM RankPermGroup WHERE RankID = ? AND PermGroupID = ?");
701  stmt.bind(1, RankID);
702  stmt.bind(2, GroupID);
703  if (!stmt.executeStep())
704  {
705  LOGWARNING("%s: Failed to check binding between rank %s and group %s, aborting.", __FUNCTION__, a_RankName.c_str(), a_GroupName.c_str());
706  return false;
707  }
708  if (stmt.getColumn(0).getInt() > 0)
709  {
710  LOGD("%s: Group %s already present in rank %s, skipping and returning success.",
711  __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str()
712  );
713  return true;
714  }
715  }
716 
717  // Add the group:
718  {
719  SQLite::Statement stmt(m_DB, "INSERT INTO RankPermGroup (RankID, PermGroupID) VALUES (?, ?)");
720  stmt.bind(1, RankID);
721  stmt.bind(2, GroupID);
722  if (stmt.exec() <= 0)
723  {
724  LOGWARNING("%s: Failed to add group %s to rank %s, aborting.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
725  return false;
726  }
727  }
728 
729  // Adding succeeded:
730  return true;
731  }
732  catch (const SQLite::Exception & ex)
733  {
734  LOGWARNING("%s: Failed to add group %s to rank %s: %s", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str(), ex.what());
735  }
736  return false;
737 }
738 
739 
740 
741 
742 
743 bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName)
744 {
746  cCSLock Lock(m_CS);
747 
748  try
749  {
750  // Get the group's ID:
751  int GroupID;
752  {
753  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
754  stmt.bind(1, a_GroupName);
755  if (!stmt.executeStep())
756  {
757  LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
758  return false;
759  }
760  GroupID = stmt.getColumn(0).getInt();
761  }
762 
763  // Check if the permission is already present:
764  {
765  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
766  stmt.bind(1, GroupID);
767  stmt.bind(2, a_Permission);
768  if (!stmt.executeStep())
769  {
770  LOGWARNING("%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
771  return false;
772  }
773  if (stmt.getColumn(0).getInt() > 0)
774  {
775  LOGD("%s: Permission %s is already present in group %s, skipping and returning success.",
776  __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str()
777  );
778  return true;
779  }
780  }
781 
782  // Add the permission:
783  {
784  SQLite::Statement stmt(m_DB, "INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
785  stmt.bind(1, a_Permission);
786  stmt.bind(2, GroupID);
787  if (stmt.exec() <= 0)
788  {
789  LOGWARNING("%s: Failed to add permission %s to group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
790  return false;
791  }
792  }
793 
794  // Adding succeeded:
795  return true;
796  }
797  catch (const SQLite::Exception & ex)
798  {
799  LOGWARNING("%s: Failed to add permission %s to group %s: %s",
800  __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
801  );
802  }
803  return false;
804 }
805 
806 
807 
808 
809 
810 bool cRankManager::AddRestrictionToGroup(const AString & a_Restriction, const AString & a_GroupName)
811 {
813  cCSLock Lock(m_CS);
814 
815  try
816  {
817  // Get the group's ID:
818  int GroupID;
819  {
820  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
821  stmt.bind(1, a_GroupName);
822  if (!stmt.executeStep())
823  {
824  LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
825  return false;
826  }
827  GroupID = stmt.getColumn(0).getInt();
828  }
829 
830  // Check if the restriction is already present:
831  {
832  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
833  stmt.bind(1, GroupID);
834  stmt.bind(2, a_Restriction);
835  if (!stmt.executeStep())
836  {
837  LOGWARNING("%s: Failed to check binding between restriction %s and group %s, aborting.", __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str());
838  return false;
839  }
840  if (stmt.getColumn(0).getInt() > 0)
841  {
842  LOGD("%s: Restriction %s is already present in group %s, skipping and returning success.",
843  __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str()
844  );
845  return true;
846  }
847  }
848 
849  // Add the restriction:
850  {
851  SQLite::Statement stmt(m_DB, "INSERT INTO RestrictionItem (Permission, PermGroupID) VALUES (?, ?)");
852  stmt.bind(1, a_Restriction);
853  stmt.bind(2, GroupID);
854  if (stmt.exec() <= 0)
855  {
856  LOGWARNING("%s: Failed to add restriction %s to group %s, aborting.", __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str());
857  return false;
858  }
859  }
860 
861  // Adding succeeded:
862  return true;
863  }
864  catch (const SQLite::Exception & ex)
865  {
866  LOGWARNING("%s: Failed to add restriction %s to group %s: %s",
867  __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str(), ex.what()
868  );
869  }
870  return false;
871 }
872 
873 
874 
875 
876 
877 bool cRankManager::AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName)
878 {
880  cCSLock Lock(m_CS);
881 
882  try
883  {
884  // Get the group's ID:
885  int GroupID;
886  {
887  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
888  stmt.bind(1, a_GroupName);
889  if (!stmt.executeStep())
890  {
891  LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
892  return false;
893  }
894  GroupID = stmt.getColumn(0).getInt();
895  }
896 
897  for (AStringVector::const_iterator itr = a_Permissions.begin(), end = a_Permissions.end(); itr != end; ++itr)
898  {
899  // Check if the permission is already present:
900  {
901  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
902  stmt.bind(1, GroupID);
903  stmt.bind(2, *itr);
904  if (!stmt.executeStep())
905  {
906  LOGWARNING("%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
907  return false;
908  }
909  if (stmt.getColumn(0).getInt() > 0)
910  {
911  LOGD("%s: Permission %s is already present in group %s, skipping and returning success.",
912  __FUNCTION__, itr->c_str(), a_GroupName.c_str()
913  );
914  continue;
915  }
916  }
917 
918  // Add the permission:
919  {
920  SQLite::Statement stmt(m_DB, "INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
921  stmt.bind(1, *itr);
922  stmt.bind(2, GroupID);
923  if (stmt.exec() <= 0)
924  {
925  LOGWARNING("%s: Failed to add permission %s to group %s, skipping.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
926  continue;
927  }
928  }
929  } // for itr - a_Permissions[]
930 
931  // Adding succeeded:
932  return true;
933  }
934  catch (const SQLite::Exception & ex)
935  {
936  LOGWARNING("%s: Failed to add permissions to group %s: %s",
937  __FUNCTION__, a_GroupName.c_str(), ex.what()
938  );
939  }
940  return false;
941 }
942 
943 
944 
945 
946 
947 bool cRankManager::AddRestrictionsToGroup(const AStringVector & a_Restrictions, const AString & a_GroupName)
948 {
950  cCSLock Lock(m_CS);
951 
952  try
953  {
954  // Get the group's ID:
955  int GroupID;
956  {
957  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
958  stmt.bind(1, a_GroupName);
959  if (!stmt.executeStep())
960  {
961  LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
962  return false;
963  }
964  GroupID = stmt.getColumn(0).getInt();
965  }
966 
967  for (auto itr = a_Restrictions.cbegin(), end = a_Restrictions.cend(); itr != end; ++itr)
968  {
969  // Check if the restriction is already present:
970  {
971  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
972  stmt.bind(1, GroupID);
973  stmt.bind(2, *itr);
974  if (!stmt.executeStep())
975  {
976  LOGWARNING("%s: Failed to check binding between restriction %s and group %s, aborting.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
977  return false;
978  }
979  if (stmt.getColumn(0).getInt() > 0)
980  {
981  LOGD("%s: Restriction %s is already present in group %s, skipping and returning success.",
982  __FUNCTION__, itr->c_str(), a_GroupName.c_str()
983  );
984  continue;
985  }
986  }
987 
988  // Add the permission:
989  {
990  SQLite::Statement stmt(m_DB, "INSERT INTO RestrictionItem (Permission, PermGroupID) VALUES (?, ?)");
991  stmt.bind(1, *itr);
992  stmt.bind(2, GroupID);
993  if (stmt.exec() <= 0)
994  {
995  LOGWARNING("%s: Failed to add restriction %s to group %s, skipping.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
996  continue;
997  }
998  }
999  } // for itr - a_Restrictions[]
1000 
1001  // Adding succeeded:
1002  return true;
1003  }
1004  catch (const SQLite::Exception & ex)
1005  {
1006  LOGWARNING("%s: Failed to add restrictions to group %s: %s",
1007  __FUNCTION__, a_GroupName.c_str(), ex.what()
1008  );
1009  }
1010  return false;
1011 }
1012 
1013 
1014 
1015 
1016 
1017 void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName)
1018 {
1020  cCSLock Lock(m_CS);
1021 
1022  // Check if the default rank is being removed with a proper replacement:
1023  if ((a_RankName == m_DefaultRank) && !RankExists(a_ReplacementRankName))
1024  {
1025  LOGWARNING("%s: Cannot remove rank %s, it is the default rank and the replacement rank doesn't exist.", __FUNCTION__, a_RankName.c_str());
1026  return;
1027  }
1028 
1029  AStringVector res;
1030  try
1031  {
1032  // Get the RankID for the rank being removed:
1033  int RemoveRankID;
1034  {
1035  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
1036  stmt.bind(1, a_RankName);
1037  if (!stmt.executeStep())
1038  {
1039  LOGINFO("%s: Rank %s was not found. Skipping.", __FUNCTION__, a_RankName.c_str());
1040  return;
1041  }
1042  RemoveRankID = stmt.getColumn(0).getInt();
1043  }
1044 
1045  // Get the RankID for the replacement rank:
1046  int ReplacementRankID = -1;
1047  {
1048  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
1049  stmt.bind(1, a_ReplacementRankName);
1050  if (stmt.executeStep())
1051  {
1052  ReplacementRankID = stmt.getColumn(0).getInt();
1053  }
1054  }
1055 
1056  // Remove the rank's bindings to groups:
1057  {
1058  SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE RankID = ?");
1059  stmt.bind(1, RemoveRankID);
1060  stmt.exec();
1061  }
1062 
1063  // Adjust players:
1064  if (ReplacementRankID == -1)
1065  {
1066  // No replacement, just delete all the players that have the rank:
1067  SQLite::Statement stmt(m_DB, "DELETE FROM PlayerRank WHERE RankID = ?");
1068  stmt.bind(1, RemoveRankID);
1069  stmt.exec();
1070  }
1071  else
1072  {
1073  // Replacement available, change all the player records:
1074  SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ? WHERE RankID = ?");
1075  stmt.bind(1, ReplacementRankID);
1076  stmt.bind(2, RemoveRankID);
1077  stmt.exec();
1078  }
1079 
1080  // Remove the rank from the DB:
1081  {
1082  SQLite::Statement stmt(m_DB, "DELETE FROM Rank WHERE RankID = ?");
1083  stmt.bind(1, RemoveRankID);
1084  stmt.exec();
1085  }
1086 
1087  // Update the default rank, if it was the one being removed:
1088  if (a_RankName == m_DefaultRank)
1089  {
1090  m_DefaultRank = a_RankName;
1091  }
1092  }
1093  catch (const SQLite::Exception & ex)
1094  {
1095  LOGWARNING("%s: Failed to remove rank from DB: %s", __FUNCTION__, ex.what());
1096  }
1097 }
1098 
1099 
1100 
1101 
1102 
1103 void cRankManager::RemoveGroup(const AString & a_GroupName)
1104 {
1106  cCSLock Lock(m_CS);
1107 
1108  try
1109  {
1110  // Get the ID of the group:
1111  int GroupID;
1112  {
1113  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1114  stmt.bind(1, a_GroupName);
1115  if (!stmt.executeStep())
1116  {
1117  LOGINFO("%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1118  return;
1119  }
1120  GroupID = stmt.getColumn(0).getInt();
1121  }
1122 
1123  // Remove all permissions from the group:
1124  {
1125  SQLite::Statement stmt(m_DB, "DELETE FROM PermissionItem WHERE PermGroupID = ?");
1126  stmt.bind(1, GroupID);
1127  stmt.exec();
1128  }
1129 
1130  // Remove the group from all ranks that contain it:
1131  {
1132  SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ?");
1133  stmt.bind(1, GroupID);
1134  stmt.exec();
1135  }
1136 
1137  // Remove the group itself:
1138  {
1139  SQLite::Statement stmt(m_DB, "DELETE FROM PermGroup WHERE PermGroupID = ?");
1140  stmt.bind(1, GroupID);
1141  stmt.exec();
1142  }
1143  }
1144  catch (const SQLite::Exception & ex)
1145  {
1146  LOGWARNING("%s: Failed to remove group %s from DB: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
1147  }
1148 }
1149 
1150 
1151 
1152 
1153 
1154 void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName)
1155 {
1157  cCSLock Lock(m_CS);
1158 
1159  try
1160  {
1161  // Get the IDs of the group and the rank:
1162  int GroupID, RankID;
1163  {
1164  SQLite::Statement stmt(m_DB,
1165  "SELECT PermGroup.PermGroupID, Rank.RankID FROM PermGroup "
1166  "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID "
1167  "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
1168  "WHERE PermGroup.Name = ? AND Rank.Name = ?"
1169  );
1170  stmt.bind(1, a_GroupName);
1171  stmt.bind(2, a_RankName);
1172  if (!stmt.executeStep())
1173  {
1174  LOGINFO("%s: Group %s was not found in rank %s, skipping.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
1175  return;
1176  }
1177  GroupID = stmt.getColumn(0).getInt();
1178  RankID = stmt.getColumn(1).getInt();
1179  }
1180 
1181  // Remove the group from all ranks that contain it:
1182  {
1183  SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ?");
1184  stmt.bind(1, GroupID);
1185  stmt.exec();
1186  }
1187 
1188  // Remove the group-to-rank binding:
1189  {
1190  SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ? AND RankID = ?");
1191  stmt.bind(1, GroupID);
1192  stmt.bind(1, RankID);
1193  stmt.exec();
1194  }
1195  }
1196  catch (const SQLite::Exception & ex)
1197  {
1198  LOGWARNING("%s: Failed to remove group %s from rank %s in the DB: %s", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str(), ex.what());
1199  }
1200 }
1201 
1202 
1203 
1204 
1205 
1206 void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName)
1207 {
1209  cCSLock Lock(m_CS);
1210 
1211  try
1212  {
1213  // Get the ID of the group:
1214  int GroupID;
1215  {
1216  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1217  stmt.bind(1, a_GroupName);
1218  if (!stmt.executeStep())
1219  {
1220  LOGINFO("%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1221  return;
1222  }
1223  GroupID = stmt.getColumn(0).getInt();
1224  }
1225 
1226  // Remove the permission from the group:
1227  {
1228  SQLite::Statement stmt(m_DB, "DELETE FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
1229  stmt.bind(1, GroupID);
1230  stmt.bind(2, a_Permission);
1231  stmt.exec();
1232  }
1233  }
1234  catch (const SQLite::Exception & ex)
1235  {
1236  LOGWARNING("%s: Failed to remove permission %s from group %s in DB: %s",
1237  __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
1238  );
1239  }
1240 }
1241 
1242 
1243 
1244 
1245 
1246 void cRankManager::RemoveRestrictionFromGroup(const AString & a_Restriction, const AString & a_GroupName)
1247 {
1249  cCSLock Lock(m_CS);
1250 
1251  try
1252  {
1253  // Get the ID of the group:
1254  int GroupID;
1255  {
1256  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1257  stmt.bind(1, a_GroupName);
1258  if (!stmt.executeStep())
1259  {
1260  LOGINFO("%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1261  return;
1262  }
1263  GroupID = stmt.getColumn(0).getInt();
1264  }
1265 
1266  // Remove the permission from the group:
1267  {
1268  SQLite::Statement stmt(m_DB, "DELETE FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
1269  stmt.bind(1, GroupID);
1270  stmt.bind(2, a_Restriction);
1271  stmt.exec();
1272  }
1273  }
1274  catch (const SQLite::Exception & ex)
1275  {
1276  LOGWARNING("%s: Failed to remove restriction %s from group %s in DB: %s",
1277  __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str(), ex.what()
1278  );
1279  }
1280 }
1281 
1282 
1283 
1284 
1285 
1286 bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewName)
1287 {
1289  cCSLock Lock(m_CS);
1290 
1291  try
1292  {
1293  // Check that NewName doesn't exist:
1294  {
1295  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
1296  stmt.bind(1, a_NewName);
1297  if (stmt.executeStep())
1298  {
1299  LOGINFO("%s: Rank %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
1300  return false;
1301  }
1302  }
1303 
1304  // Rename:
1305  {
1306  SQLite::Statement stmt(m_DB, "UPDATE Rank SET Name = ? WHERE Name = ?");
1307  stmt.bind(1, a_NewName);
1308  stmt.bind(2, a_OldName);
1309  if (stmt.exec() <= 0)
1310  {
1311  LOGINFO("%s: There is no rank %s, cannot rename to %s.", __FUNCTION__, a_OldName.c_str(), a_NewName.c_str());
1312  return false;
1313  }
1314  }
1315 
1316  // Update the default rank, if it was the one being renamed:
1317  if (a_OldName == m_DefaultRank)
1318  {
1319  m_DefaultRank = a_NewName;
1320  }
1321 
1322  return true;
1323  }
1324  catch (const SQLite::Exception & ex)
1325  {
1326  LOGWARNING("%s: Failed to rename rank %s to %s in DB: %s",
1327  __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
1328  }
1329  return false;
1330 }
1331 
1332 
1333 
1334 
1335 
1336 bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewName)
1337 {
1339  cCSLock Lock(m_CS);
1340 
1341  try
1342  {
1343  // Check that NewName doesn't exist:
1344  {
1345  SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1346  stmt.bind(1, a_NewName);
1347  if (stmt.executeStep())
1348  {
1349  LOGD("%s: Group %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
1350  return false;
1351  }
1352  }
1353 
1354  // Rename:
1355  bool res;
1356  {
1357  SQLite::Statement stmt(m_DB, "UPDATE PermGroup SET Name = ? WHERE Name = ?");
1358  stmt.bind(1, a_NewName);
1359  stmt.bind(2, a_OldName);
1360  res = (stmt.exec() > 0);
1361  }
1362 
1363  return res;
1364  }
1365  catch (const SQLite::Exception & ex)
1366  {
1367  LOGWARNING("%s: Failed to rename group %s to %s in DB: %s",
1368  __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
1369  }
1370  return false;
1371 }
1372 
1373 
1374 
1375 
1376 
1377 void cRankManager::SetPlayerRank(const cUUID & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName)
1378 {
1380  cCSLock Lock(m_CS);
1381 
1382  AString StrUUID = a_PlayerUUID.ToShortString();
1383 
1384  try
1385  {
1386  // Get the rank ID:
1387  int RankID;
1388  {
1389  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
1390  stmt.bind(1, a_RankName);
1391  if (!stmt.executeStep())
1392  {
1393  LOGWARNING("%s: There is no rank %s, aborting.", __FUNCTION__, a_RankName.c_str());
1394  return;
1395  }
1396  RankID = stmt.getColumn(0).getInt();
1397  }
1398 
1399  // Update the player's rank, if already in DB:
1400  {
1401  SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ?, PlayerName = ? WHERE PlayerUUID = ?");
1402  stmt.bind(1, RankID);
1403  stmt.bind(2, a_PlayerName);
1404  stmt.bind(3, StrUUID);
1405  if (stmt.exec() > 0)
1406  {
1407  // Successfully updated the player's rank
1408  return;
1409  }
1410  }
1411 
1412  // The player is not yet in the DB, add them:
1413  SQLite::Statement stmt(m_DB, "INSERT INTO PlayerRank (RankID, PlayerUUID, PlayerName) VALUES (?, ?, ?)");
1414  stmt.bind(1, RankID);
1415  stmt.bind(2, StrUUID);
1416  stmt.bind(3, a_PlayerName);
1417  if (stmt.exec() > 0)
1418  {
1419  // Successfully added the player
1420  return;
1421  }
1422 
1423  LOGWARNING("%s: Failed to set player UUID %s to rank %s.",
1424  __FUNCTION__, StrUUID.c_str(), a_RankName.c_str()
1425  );
1426  }
1427  catch (const SQLite::Exception & ex)
1428  {
1429  LOGWARNING("%s: Failed to set player UUID %s to rank %s: %s",
1430  __FUNCTION__, StrUUID.c_str(), a_RankName.c_str(), ex.what()
1431  );
1432  }
1433 }
1434 
1435 
1436 
1437 
1438 
1439 void cRankManager::RemovePlayerRank(const cUUID & a_PlayerUUID)
1440 {
1442  cCSLock Lock(m_CS);
1443 
1444  AString StrUUID = a_PlayerUUID.ToShortString();
1445 
1446  try
1447  {
1448  SQLite::Statement stmt(m_DB, "DELETE FROM PlayerRank WHERE PlayerUUID = ?");
1449  stmt.bind(1, StrUUID);
1450  stmt.exec();
1451  }
1452  catch (const SQLite::Exception & ex)
1453  {
1454  LOGWARNING("%s: Failed to remove rank from player UUID %s: %s",
1455  __FUNCTION__, StrUUID.c_str(), ex.what()
1456  );
1457  }
1458 }
1459 
1460 
1461 
1462 
1463 
1465  const AString & a_RankName,
1466  const AString & a_MsgPrefix,
1467  const AString & a_MsgSuffix,
1468  const AString & a_MsgNameColorCode
1469 )
1470 {
1472  cCSLock Lock(m_CS);
1473 
1474  try
1475  {
1476  SQLite::Statement stmt(m_DB, "UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?");
1477  stmt.bind(1, a_MsgPrefix);
1478  stmt.bind(2, a_MsgSuffix);
1479  stmt.bind(3, a_MsgNameColorCode);
1480  stmt.bind(4, a_RankName);
1481  if (stmt.exec() < 1)
1482  {
1483  LOGINFO("%s: Rank %s not found, visuals not set.", __FUNCTION__, a_RankName.c_str());
1484  }
1485  }
1486  catch (const SQLite::Exception & ex)
1487  {
1488  LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
1489  }
1490 }
1491 
1492 
1493 
1494 
1495 
1497  const AString & a_RankName,
1498  AString & a_MsgPrefix,
1499  AString & a_MsgSuffix,
1500  AString & a_MsgNameColorCode
1501 )
1502 {
1504  cCSLock Lock(m_CS);
1505 
1506  try
1507  {
1508  SQLite::Statement stmt(m_DB, "SELECT MsgPrefix, MsgSuffix, MsgNameColorCode FROM Rank WHERE Name = ?");
1509  stmt.bind(1, a_RankName);
1510  if (!stmt.executeStep())
1511  {
1512  // Rank not found
1513  return false;
1514  }
1515  a_MsgPrefix = stmt.getColumn(0).getText();
1516  a_MsgSuffix = stmt.getColumn(1).getText();
1517  a_MsgNameColorCode = stmt.getColumn(2).getText();
1518  return true;
1519  }
1520  catch (const SQLite::Exception & ex)
1521  {
1522  LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
1523  }
1524  return false;
1525 }
1526 
1527 
1528 
1529 
1530 
1531 bool cRankManager::RankExists(const AString & a_RankName)
1532 {
1534  cCSLock Lock(m_CS);
1535 
1536  try
1537  {
1538  SQLite::Statement stmt(m_DB, "SELECT * FROM Rank WHERE Name = ?");
1539  stmt.bind(1, a_RankName);
1540  if (stmt.executeStep())
1541  {
1542  // The rank was found
1543  return true;
1544  }
1545  }
1546  catch (const SQLite::Exception & ex)
1547  {
1548  LOGWARNING("%s: Failed to query DB for rank %s: %s", __FUNCTION__, a_RankName.c_str(), ex.what());
1549  }
1550  return false;
1551 }
1552 
1553 
1554 
1555 
1556 
1557 bool cRankManager::GroupExists(const AString & a_GroupName)
1558 {
1560  cCSLock Lock(m_CS);
1561 
1562  try
1563  {
1564  SQLite::Statement stmt(m_DB, "SELECT * FROM PermGroup WHERE Name = ?");
1565  stmt.bind(1, a_GroupName);
1566  if (stmt.executeStep())
1567  {
1568  // The group was found
1569  return true;
1570  }
1571  }
1572  catch (const SQLite::Exception & ex)
1573  {
1574  LOGWARNING("%s: Failed to query DB for group %s: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
1575  }
1576  return false;
1577 }
1578 
1579 
1580 
1581 
1582 
1583 bool cRankManager::IsPlayerRankSet(const cUUID & a_PlayerUUID)
1584 {
1586  cCSLock Lock(m_CS);
1587 
1588  AString StrUUID = a_PlayerUUID.ToShortString();
1589 
1590  try
1591  {
1592  SQLite::Statement stmt(m_DB, "SELECT * FROM PlayerRank WHERE PlayerUUID = ?");
1593  stmt.bind(1, StrUUID);
1594  if (stmt.executeStep())
1595  {
1596  // The player UUID was found, they have a rank
1597  return true;
1598  }
1599  }
1600  catch (const SQLite::Exception & ex)
1601  {
1602  LOGWARNING("%s: Failed to query DB for player UUID %s: %s", __FUNCTION__, StrUUID.c_str(), ex.what());
1603  }
1604  return false;
1605 }
1606 
1607 
1608 
1609 
1610 
1611 bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_RankName)
1612 {
1614  cCSLock Lock(m_CS);
1615 
1616  try
1617  {
1618  SQLite::Statement stmt(m_DB,
1619  "SELECT * FROM Rank "
1620  "LEFT JOIN RankPermGroup ON Rank.RankID = RankPermGroup.RankID "
1621  "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RankPermGroup.PermGroupID "
1622  "WHERE Rank.Name = ? AND PermGroup.Name = ?"
1623  );
1624  stmt.bind(1, a_RankName);
1625  stmt.bind(2, a_GroupName);
1626  if (stmt.executeStep())
1627  {
1628  // The group is in the rank
1629  return true;
1630  }
1631  }
1632  catch (const SQLite::Exception & ex)
1633  {
1634  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
1635  }
1636  return false;
1637 }
1638 
1639 
1640 
1641 
1642 
1643 bool cRankManager::IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName)
1644 {
1646  cCSLock Lock(m_CS);
1647 
1648  try
1649  {
1650  SQLite::Statement stmt(m_DB,
1651  "SELECT * FROM PermissionItem "
1652  "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID "
1653  "WHERE PermissionItem.Permission = ? AND PermGroup.Name = ?"
1654  );
1655  stmt.bind(1, a_Permission);
1656  stmt.bind(2, a_GroupName);
1657  if (stmt.executeStep())
1658  {
1659  // The permission is in the group
1660  return true;
1661  }
1662  }
1663  catch (const SQLite::Exception & ex)
1664  {
1665  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
1666  }
1667  return false;
1668 }
1669 
1670 
1671 
1672 
1673 
1674 bool cRankManager::IsRestrictionInGroup(const AString & a_Restriction, const AString & a_GroupName)
1675 {
1677  cCSLock Lock(m_CS);
1678 
1679  try
1680  {
1681  SQLite::Statement stmt(m_DB,
1682  "SELECT * FROM RestrictionItem "
1683  "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RestrictionItem.PermGroupID "
1684  "WHERE RestrictionItem.Permission = ? AND PermGroup.Name = ?"
1685  );
1686  stmt.bind(1, a_Restriction);
1687  stmt.bind(2, a_GroupName);
1688  if (stmt.executeStep())
1689  {
1690  // The restriction is in the group
1691  return true;
1692  }
1693  }
1694  catch (const SQLite::Exception & ex)
1695  {
1696  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
1697  }
1698  return false;
1699 }
1700 
1701 
1702 
1703 
1704 
1705 void cRankManager::NotifyNameUUID(const AString & a_PlayerName, const cUUID & a_UUID)
1706 {
1708  cCSLock Lock(m_CS);
1709 
1710  try
1711  {
1712  SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET PlayerName = ? WHERE PlayerUUID = ?");
1713  stmt.bind(1, a_PlayerName);
1714  stmt.bind(2, a_UUID.ToShortString());
1715  stmt.exec();
1716  }
1717  catch (const SQLite::Exception & ex)
1718  {
1719  LOGWARNING("%s: Failed to update DB: %s", __FUNCTION__, ex.what());
1720  }
1721 }
1722 
1723 
1724 
1725 
1726 
1727 bool cRankManager::SetDefaultRank(const AString & a_RankName)
1728 {
1730  cCSLock Lock(m_CS);
1731 
1732  try
1733  {
1734  // Find the rank's ID:
1735  int RankID = 0;
1736  {
1737  SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
1738  stmt.bind(1, a_RankName);
1739  if (!stmt.executeStep())
1740  {
1741  LOGINFO("%s: Cannot set rank %s as the default, it does not exist.", __FUNCTION__, a_RankName.c_str());
1742  return false;
1743  }
1744  }
1745 
1746  // Set the rank as the default:
1747  {
1748  SQLite::Statement stmt(m_DB, "UPDATE DefaultRank SET RankID = ?");
1749  stmt.bind(1, RankID);
1750  if (stmt.exec() < 1)
1751  {
1752  // Failed to update, there might be none in the DB, try inserting:
1753  SQLite::Statement stmt2(m_DB, "INSERT INTO DefaultRank (RankID) VALUES (?)");
1754  stmt2.bind(1, RankID);
1755  if (stmt2.exec() < 1)
1756  {
1757  LOGINFO("%s: Cannot update the default rank in the DB to %s.", __FUNCTION__, a_RankName.c_str());
1758  return false;
1759  }
1760  }
1761  }
1762 
1763  // Set the internal cache:
1764  m_DefaultRank = a_RankName;
1765  return true;
1766  }
1767  catch (const SQLite::Exception & ex)
1768  {
1769  LOGWARNING("%s: Failed to update DB: %s", __FUNCTION__, ex.what());
1770  return false;
1771  }
1772 }
1773 
1774 
1775 
1776 
1777 
1779 {
1781  cCSLock Lock(m_CS);
1782 
1783  try
1784  {
1785  SQLite::Statement stmt(m_DB, "DELETE FROM PlayerRank");
1786  stmt.exec();
1787  }
1788  catch (SQLite::Exception & ex)
1789  {
1790  LOGWARNING("%s: Failed to remove / clear all players: %s", __FUNCTION__, ex.what());
1791  }
1792 }
1793 
1794 
1795 
1796 
1797 
1798 bool cRankManager::UpdatePlayerName(const cUUID & a_PlayerUUID, const AString & a_NewPlayerName)
1799 {
1801  cCSLock Lock(m_CS);
1802 
1803  AString StrUUID = a_PlayerUUID.ToShortString();
1804 
1805  try
1806  {
1807  SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET PlayerName = ? WHERE PlayerUUID = ?");
1808  stmt.bind(1, a_NewPlayerName);
1809  stmt.bind(2, StrUUID);
1810  if (stmt.exec() > 0)
1811  {
1812  // The player name was changed, returns true
1813  return true;
1814  }
1815  }
1816  catch (const SQLite::Exception & ex)
1817  {
1818  LOGWARNING("%s: Failed to update player name from UUID %s: %s", __FUNCTION__, StrUUID.c_str(), ex.what());
1819  }
1820  return false;
1821 }
1822 
1823 
1824 
1825 
1826 
1828 {
1829  return (
1830  IsDBTableEmpty("Rank") &&
1831  IsDBTableEmpty("PlayerRank") &&
1832  IsDBTableEmpty("PermGroup") &&
1833  IsDBTableEmpty("RankPermGroup") &&
1834  IsDBTableEmpty("PermissionItem") &&
1835  IsDBTableEmpty("DefaultRank")
1836  );
1837 }
1838 
1839 
1840 
1841 
1842 
1843 bool cRankManager::IsDBTableEmpty(const AString & a_TableName)
1844 {
1845  try
1846  {
1847  SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM " + a_TableName);
1848  return (stmt.executeStep() && (stmt.getColumn(0).getInt() == 0));
1849  }
1850  catch (const SQLite::Exception & ex)
1851  {
1852  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
1853  }
1854  return false;
1855 }
1856 
1857 
1858 
1859 
1860 
1862 {
1863  // Wrap everything in a big transaction to speed things up:
1864  cMassChangeLock Lock(*this);
1865 
1866  // Create ranks:
1867  AddRank("Default", "", "", "");
1868  AddRank("VIP", "", "", "");
1869  AddRank("Operator", "", "", "");
1870  AddRank("Admin", "", "", "");
1871 
1872  // Create groups:
1873  AddGroup("Default");
1874  AddGroup("Kick");
1875  AddGroup("Teleport");
1876  AddGroup("Everything");
1877 
1878  // Add groups to ranks:
1879  AddGroupToRank("Default", "Default");
1880  AddGroupToRank("Teleport", "VIP");
1881  AddGroupToRank("Teleport", "Operator");
1882  AddGroupToRank("Kick", "Operator");
1883  AddGroupToRank("Everything", "Admin");
1884 
1885  // Add permissions to groups:
1886  AddPermissionToGroup("core.help", "Default");
1887  AddPermissionToGroup("core.build", "Default");
1888  AddPermissionToGroup("core.teleport", "Teleport");
1889  AddPermissionToGroup("core.kick", "Kick");
1890  AddPermissionToGroup("*", "Everything");
1891 
1892  // Set the default rank:
1893  SetDefaultRank("Default");
1894 }
1895 
1896 
1897 
1898 
1899 
1900 bool cRankManager::DoesColumnExist(const char * a_TableName, const char * a_ColumnName)
1901 {
1902  try
1903  {
1904  SQLite::Statement stmt(m_DB, Printf("PRAGMA table_info(%s)", a_TableName));
1905  while (stmt.executeStep()) // Iterate over all table's columns
1906  {
1907  int NumColumns = stmt.getColumnCount();
1908  for (int i = 0; i < NumColumns; i++) // Iterate over all reply's columns (table column's metadata)
1909  {
1910  auto column = stmt.getColumn(i);
1911  if (strcmp(column.getName(), "name") == 0)
1912  {
1913  if (NoCaseCompare(column.getText(), a_ColumnName) == 0)
1914  {
1915  // Colun found
1916  return true;
1917  }
1918  }
1919  } // for i - stmt.getColumns()
1920  } // while (stmt.executeStep())
1921  }
1922  catch (const SQLite::Exception & ex)
1923  {
1924  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
1925  }
1926  return false;
1927 }
1928 
1929 
1930 
1931 
1932 
1933 void cRankManager::CreateColumnIfNotExists(const char * a_TableName, const char * a_ColumnName, const char * a_ColumnType)
1934 {
1935  // If the column already exists, bail out:
1936  if (DoesColumnExist(a_TableName, a_ColumnName))
1937  {
1938  return;
1939  }
1940 
1941  // Add the column:
1942  try
1943  {
1944  m_DB.exec(Printf("ALTER TABLE %s ADD COLUMN %s %s", a_TableName, a_ColumnName, a_ColumnType));
1945  }
1946  catch (const SQLite::Exception & exc)
1947  {
1948  LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, exc.what());
1949  }
1950 }
1951 
1952 
1953 
1954 
cMojangAPI
Definition: MojangAPI.h:33
cRankManager::AddPermissionToGroup
bool AddPermissionToGroup(const AString &a_Permission, const AString &a_GroupName)
Adds the specified permission to the specified permission group.
Definition: RankManager.cpp:743
cRankManager::GetPlayerName
AString GetPlayerName(const cUUID &a_PlayerUUID)
Returns the last name that the specified player has.
Definition: RankManager.cpp:123
cUUID
Definition: UUID.h:10
cRankManager::AddGroups
void AddGroups(const AStringVector &a_GroupNames)
Bulk-adds groups.
Definition: RankManager.cpp:622
cRankManager::AddRank
void AddRank(const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
Adds a new rank.
Definition: RankManager.cpp:534
cRankManager::GetAllRestrictions
AStringVector GetAllRestrictions(void)
Returns all the distinct restrictions that are stored in the DB.
Definition: RankManager.cpp:471
cRankManager::m_DefaultRank
AString m_DefaultRank
The name of the default rank.
Definition: RankManager.h:268
cRankManager::AddGroupToRank
bool AddGroupToRank(const AString &a_GroupName, const AString &a_RankName)
Adds the specified permission group to the specified rank.
Definition: RankManager.cpp:665
cRankManager::cMassChangeLock
Acquire this lock to perform mass changes.
Definition: RankManager.h:30
cRankManager::DoesColumnExist
bool DoesColumnExist(const char *a_TableName, const char *a_ColumnName)
Returns true if the specified column exists in the specified table.
Definition: RankManager.cpp:1900
cRankManager::GetAllGroups
AStringVector GetAllGroups(void)
Returns the names of all permission groups.
Definition: RankManager.cpp:421
cRankManager::RenameGroup
bool RenameGroup(const AString &a_OldName, const AString &a_NewName)
Renames the specified group.
Definition: RankManager.cpp:1336
cRankManager::~cRankManager
~cRankManager()
Definition: RankManager.cpp:29
LOGINFO
void LOGINFO(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:61
cRankManager::GetRankGroups
AStringVector GetRankGroups(const AString &a_RankName)
Returns the names of groups that the specified rank has assigned to it.
Definition: RankManager.cpp:212
cRankManager::SetRankVisuals
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.
Definition: RankManager.cpp:1464
MojangAPI.h
cRankManager::RankExists
bool RankExists(const AString &a_RankName)
Returns true iff the specified rank exists in the DB.
Definition: RankManager.cpp:1531
Globals.h
cRankManager::CreateDefaults
void CreateDefaults(void)
Creates a default set of ranks / groups / permissions.
Definition: RankManager.cpp:1861
NoCaseCompare
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
Definition: StringUtils.cpp:304
cRankManager::m_IsInitialized
bool m_IsInitialized
Set to true once the manager is initialized.
Definition: RankManager.h:274
cRankManager::ClearPlayerRanks
void ClearPlayerRanks(void)
Removes all player ranks from the database.
Definition: RankManager.cpp:1778
cRankManager::AddGroup
void AddGroup(const AString &a_GroupName)
Adds a new permission group.
Definition: RankManager.cpp:582
cRankManager::RemoveRestrictionFromGroup
void RemoveRestrictionFromGroup(const AString &a_Restriction, const AString &a_GroupName)
Removes the specified restriction from the specified group.
Definition: RankManager.cpp:1246
ASSERT
#define ASSERT(x)
Definition: Globals.h:273
cRankManager::GetAllPermissions
AStringVector GetAllPermissions(void)
Returns all the distinct permissions that are stored in the DB.
Definition: RankManager.cpp:446
LOGD
#define LOGD
Definition: LoggerSimple.h:83
cRankManager::NotifyNameUUID
void NotifyNameUUID(const AString &a_PlayerName, const cUUID &a_UUID)
Called by cMojangAPI whenever the playername-uuid pairing is discovered.
Definition: RankManager.cpp:1705
cRankManager::m_DB
SQLite::Database m_DB
The database storage for all the data.
Definition: RankManager.h:265
cRankManager::GetPlayerMsgVisuals
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.
Definition: RankManager.cpp:511
cRankManager::GetRankVisuals
bool GetRankVisuals(const AString &a_RankName, AString &a_MsgPrefix, AString &a_MsgSuffix, AString &a_MsgNameColorCode)
Returns the message visuals of an existing rank.
Definition: RankManager.cpp:1496
cRankManager::RemoveGroupFromRank
void RemoveGroupFromRank(const AString &a_GroupName, const AString &a_RankName)
Removes the specified group from the specified rank.
Definition: RankManager.cpp:1154
cRankManager::SetDefaultRank
bool SetDefaultRank(const AString &a_RankName)
Sets the specified rank as the default rank.
Definition: RankManager.cpp:1727
cRankManager::GetRankRestrictions
AStringVector GetRankRestrictions(const AString &a_RankName)
Returns all restrictions that the specified rank has assigned to it, through all its groups.
Definition: RankManager.cpp:334
cRankManager::GetPlayerGroups
AStringVector GetPlayerGroups(const cUUID &a_PlayerUUID)
Returns the names of Groups that the specified player has assigned to them.
Definition: RankManager.cpp:150
cRankManager::RenameRank
bool RenameRank(const AString &a_OldName, const AString &a_NewName)
Renames the specified rank.
Definition: RankManager.cpp:1286
cRankManager::CreateColumnIfNotExists
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.
Definition: RankManager.cpp:1933
cRankManager::GetAllPlayerUUIDs
std::vector< cUUID > GetAllPlayerUUIDs(void)
Returns the uuids of all defined players.
Definition: RankManager.cpp:365
cRankManager::IsPlayerRankSet
bool IsPlayerRankSet(const cUUID &a_PlayerUUID)
Returns true iff the specified player has a rank assigned to them in the DB.
Definition: RankManager.cpp:1583
cRankManager::Initialize
void Initialize(cMojangAPI &a_MojangAPI)
Initializes the rank manager.
Definition: RankManager.cpp:41
cRankManager::UpdatePlayerName
bool UpdatePlayerName(const cUUID &a_PlayerUUID, const AString &a_NewPlayerName)
Updates the playername that is saved with this uuid.
Definition: RankManager.cpp:1798
cRankManager::IsPermissionInGroup
bool IsPermissionInGroup(const AString &a_Permission, const AString &a_GroupName)
Returns true iff the specified group contains the specified permission.
Definition: RankManager.cpp:1643
cRankManager::GetRankPermissions
AStringVector GetRankPermissions(const AString &a_RankName)
Returns all permissions that the specified rank has assigned to it, through all its groups.
Definition: RankManager.cpp:303
cRankManager::RemovePermissionFromGroup
void RemovePermissionFromGroup(const AString &a_Permission, const AString &a_GroupName)
Removes the specified permission from the specified group.
Definition: RankManager.cpp:1206
cRankManager::AreDBTablesEmpty
bool AreDBTablesEmpty(void)
Returns true if all the DB tables are empty, indicating a fresh new install.
Definition: RankManager.cpp:1827
cCSLock
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
Definition: CriticalSection.h:52
cRankManager::SetPlayerRank
void SetPlayerRank(const cUUID &a_PlayerUUID, const AString &a_PlayerName, const AString &a_RankName)
Sets the specified player's rank.
Definition: RankManager.cpp:1377
cRankManager::GetPlayerPermissions
AStringVector GetPlayerPermissions(const cUUID &a_PlayerUUID)
Returns the permissions that the specified player has assigned to them.
Definition: RankManager.cpp:184
cRankManager::AddPermissionsToGroup
bool AddPermissionsToGroup(const AStringVector &a_Permissions, const AString &a_GroupName)
Adds the specified permissions to the specified permission group.
Definition: RankManager.cpp:877
cRankManager::AddRestrictionsToGroup
bool AddRestrictionsToGroup(const AStringVector &a_Restrictions, const AString &a_GroupName)
Adds the specified restrictions to the specified group.
Definition: RankManager.cpp:947
LOGWARNING
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
ClientHandle.h
Printf
AString & Printf(AString &a_Dst, const char *a_Format, const Args &... a_Args)
Definition: StringUtils.h:26
cRankManager::GetPlayerRankName
AString GetPlayerRankName(const cUUID &a_PlayerUUID)
Returns the name of the rank that the specified player has assigned to them.
Definition: RankManager.cpp:95
cMojangAPI::SetRankManager
void SetRankManager(cRankManager *a_RankManager)
Sets the m_RankMgr that is used for name-uuid notifications.
Definition: MojangAPI.h:84
cRankManager::IsGroupInRank
bool IsGroupInRank(const AString &a_GroupName, const AString &a_RankName)
Returns true iff the specified rank contains the specified group.
Definition: RankManager.cpp:1611
cRankManager::GetAllPermissionsRestrictions
AStringVector GetAllPermissionsRestrictions(void)
Returns all the distinct permissions and restrictions that are stored in the DB.
Definition: RankManager.cpp:496
cRankManager::IsRestrictionInGroup
bool IsRestrictionInGroup(const AString &a_Restriction, const AString &a_GroupName)
Returns true iff the specified group contains the specified restriction.
Definition: RankManager.cpp:1674
cRankManager::RemoveGroup
void RemoveGroup(const AString &a_GroupName)
Removes the specified group completely.
Definition: RankManager.cpp:1103
cRankManager::GetAllRanks
AStringVector GetAllRanks(void)
Returns the names of all defined ranks.
Definition: RankManager.cpp:396
cUUID::ToShortString
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
Definition: UUID.cpp:133
cRankManager::GetGroupPermissions
AStringVector GetGroupPermissions(const AString &a_GroupName)
Returns the permissions that the specified group has assigned to it.
Definition: RankManager.cpp:243
RankManager.h
cRankManager::m_MojangAPI
cMojangAPI * m_MojangAPI
The MojangAPI instance that is used for keeping player names and UUIDs in sync.
Definition: RankManager.h:278
cRankManager::GroupExists
bool GroupExists(const AString &a_GroupName)
Returns true iff the specified group exists in the DB.
Definition: RankManager.cpp:1557
cRankManager::AddRestrictionToGroup
bool AddRestrictionToGroup(const AString &a_Restriction, const AString &a_GroupName)
Adds the specified restriction to the specified group.
Definition: RankManager.cpp:810
cRankManager::GetGroupRestrictions
AStringVector GetGroupRestrictions(const AString &a_GroupName)
Returns the restrictions that the specified group has assigned to it.
Definition: RankManager.cpp:273
AString
std::string AString
Definition: StringUtils.h:11
cRankManager::IsDBTableEmpty
bool IsDBTableEmpty(const AString &a_TableName)
Returns true iff the specified DB table is empty.
Definition: RankManager.cpp:1843
cUUID::FromString
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
Definition: UUID.cpp:102
cRankManager::cRankManager
cRankManager(void)
Creates the rank manager.
Definition: RankManager.cpp:18
cRankManager::m_CS
cCriticalSection m_CS
The mutex protecting m_DB and m_DefaultRank against multi-threaded access.
Definition: RankManager.h:271
cRankManager::RemovePlayerRank
void RemovePlayerRank(const cUUID &a_PlayerUUID)
Removes the player's rank assignment.
Definition: RankManager.cpp:1439
cRankManager::RemoveRank
void RemoveRank(const AString &a_RankName, const AString &a_ReplacementRankName)
Removes the specified rank.
Definition: RankManager.cpp:1017
AStringVector
std::vector< AString > AStringVector
Definition: StringUtils.h:12
cRankManager::GetPlayerRestrictions
AStringVector GetPlayerRestrictions(const cUUID &a_PlayerUUID)
Returns the restrictions that the specified player has assigned to them.
Definition: RankManager.cpp:198