summaryrefslogtreecommitdiffstats
path: root/src/RankManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/RankManager.cpp')
-rw-r--r--src/RankManager.cpp210
1 files changed, 2 insertions, 208 deletions
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index e64a47eb6..96c4baa56 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -12,215 +12,9 @@
-/*
-// This code is for internal testing while developing the cRankManager class
-static class cRankMgrTest
-{
-public:
- cRankMgrTest(void) :
- m_Mgr()
- {
- // Initialize logging:
- new cMCLogger();
- AString UUID = "b1caf24202a841a78055a079c460eee7"; // UUID for "xoft"
- LOG("Testing UUID %s", UUID.c_str());
-
- // Test the initial state of the ranks:
- LOG("Initial test:");
- ReportPlayer(UUID);
-
- // Add a rank, a few groups and permissions and set the player to use them:
- LOG("Adding data...");
- m_Mgr.AddRank("TestRank1", "[test]", "[/test]", "7");
- m_Mgr.AddRank("TestRank2", "[t2]", "[/t2]", "8");
- m_Mgr.AddGroup("TestGroup1");
- m_Mgr.AddGroup("TestGroup2");
- m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank2");
- m_Mgr.AddPermissionToGroup("testpermission1.1", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission1.2", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission1.3", "TestGroup1");
- m_Mgr.AddPermissionToGroup("common", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission2.1", "TestGroup2");
- m_Mgr.AddPermissionToGroup("common", "TestGroup2");
- m_Mgr.SetPlayerRank(UUID, "xoft", "TestRank1");
-
- // Test the added data:
- LOG("Testing the added data:");
- LOG("IsGroupInRank(TestGroup1, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup1", "TestRank1") ? "true" : "false");
- LOG("IsGroupInRank(TestGroup3, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup3", "TestRank1") ? "true" : "false");
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup1) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup1") ? "true" : "false"); // Existing permission, in group
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup2") ? "true" : "false"); // Existing permission, not in group
- LOG("IsPermissionInGroup(testpermission1.9, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.9", "TestGroup2") ? "true" : "false"); // Non-existing permission
- LOG("IsPlayerRankSet(%s) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID) ? "true" : "false");
- LOG("IsPlayerRankSet(%s1) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID + "1") ? "true" : "false");
- LOG("GroupExists(TestGroup1) = %s", m_Mgr.GroupExists("TestGroup1") ? "true" : "false");
- LOG("GroupExists(TestGroup3) = %s", m_Mgr.GroupExists("TestGroup3") ? "true" : "false");
- LOG("RankExists(TestRank1) = %s", m_Mgr.RankExists("TestRank1") ? "true" : "false");
- LOG("RankExists(NonexistentRank) = %s", m_Mgr.RankExists("NonexistentRank") ? "true" : "false");
- ReportRankGroups("TestRank1");
- ReportRankGroups("NonexistentRank");
- ReportGroupPermissions("TestGroup1");
- ReportGroupPermissions("NonexistentGroup");
-
- // Report the contents of the DB:
- ReportAll();
-
- // Test the assignments above:
- LOG("After-assignment test:");
- ReportPlayer(UUID);
-
- // Test removing a permission from a group:
- LOG("Removing permission testpermission1.3 from group TestGroup1.");
- m_Mgr.RemovePermissionFromGroup("testpermission1.3", "TestGroup1");
- ReportGroupPermissions("TestGroup1");
- LOG("Removing permission common from group TestGroup1.");
- m_Mgr.RemovePermissionFromGroup("common", "TestGroup1");
- ReportGroupPermissions("TestGroup1"); // Check that it's not present
- ReportGroupPermissions("TestGroup2"); // Check that it's still present here
-
- // Test removing a group from rank:
- LOG("Removing group TestGroup2 from rank TestRank1.");
- m_Mgr.RemoveGroupFromRank("TestGroup2", "TestRank1");
- ReportRankGroups("TestRank1");
- LOG("Removing group TestGroup3 from rank TestRank1.");
- m_Mgr.RemoveGroupFromRank("TestGroup3", "TestRank1");
- ReportRankGroups("TestRank1");
-
- // Test re-adding the groups:
- LOG("Re-adding groups to TestRank1.");
- m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
- ReportRankGroups("TestRank1");
-
- // Test removing a group altogether:
- LOG("Removing group TestGroup2");
- m_Mgr.RemoveGroup("TestGroup2");
- ReportAll();
-
- // Test removing a rank:
- LOG("Removing rank TestRank2, replacing with rank TestRank1.");
- m_Mgr.RemoveRank("TestRank2", "TestRank1");
- ReportAll();
- LOG("Removing rank Test altogether.");
- m_Mgr.RemoveRank("Test", "");
- ReportAll();
-
- // Test renaming a rank:
- LOG("Renaming rank TestRank1 to Test");
- m_Mgr.RenameRank("TestRank1", "Test");
- ReportRankGroups("TestRank1");
- ReportRankGroups("Test");
- LOG("Player after renaming:");
- ReportPlayer(UUID);
-
- // Test renaming a group:
- LOG("Renaming group TestGroup1 to Test");
- m_Mgr.RenameGroup("TestGroup1", "Test");
- ReportGroupPermissions("TestGroup1");
- ReportGroupPermissions("Test");
- LOG("Player after renaming:");
- ReportPlayer(UUID);
- m_Mgr.RenameGroup("Test", "TestGroup1");
-
- // Test removing the rank in favor of another one:
- m_Mgr.RemoveRank("Test", "TestRank2");
- LOG("After-removal test:");
- ReportPlayer(UUID);
-
- LOG("Done.");
- }
-
-
- void ReportAll(void)
- {
- // Report all ranks:
- AStringVector Ranks = m_Mgr.GetAllRanks();
- LOG("All ranks (%u):", (unsigned)Ranks.size());
- for (AStringVector::const_iterator itr = Ranks.begin(), end = Ranks.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
-
- // Report all groups:
- AStringVector Groups = m_Mgr.GetAllGroups();
- LOG("All groups (%u):", (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
-
- // Report all permissions:
- AStringVector Permissions = m_Mgr.GetAllPermissions();
- LOG("All permissions (%u):", (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-
- void ReportPlayer(const AString & a_PlayerUUID)
- {
- // Get the player's UUID and rank:
- LOG(" Rank: '%s'", m_Mgr.GetPlayerRankName(a_PlayerUUID).c_str());
-
- // List all the permission groups for the player:
- AStringVector Groups = m_Mgr.GetPlayerGroups(a_PlayerUUID);
- LOG(" Groups (%u):", (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'" , itr->c_str());
- } // for itr - Groups[]
-
- // List all the permissions for the player:
- AStringVector Permissions = m_Mgr.GetPlayerPermissions(a_PlayerUUID);
- LOG(" Permissions (%u):", (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- } // for itr - Groups[]
- }
-
-
- void ReportRankGroups(const AString & a_RankName)
- {
- AStringVector Groups = m_Mgr.GetRankGroups(a_RankName);
- LOG("Groups in rank %s: %u", a_RankName.c_str(), (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- AStringVector Permissions = m_Mgr.GetRankPermissions(a_RankName);
- LOG("Permissions in rank %s: %u", a_RankName.c_str(), (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-
- void ReportGroupPermissions(const AString & a_GroupName)
- {
- AStringVector Permissions = m_Mgr.GetGroupPermissions(a_GroupName);
- LOG("Permissions in group %s: %u", a_GroupName.c_str(), (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-protected:
- cRankManager m_Mgr;
-} g_RankMgrTest;
-//*/
-
-
-
-
-
////////////////////////////////////////////////////////////////////////////////
+// cRankManagerIniMigrator:
+
/** Migrates from groups.ini and users.ini into the rankmanager DB */
class cRankManagerIniMigrator
{