36 LOGD(
"Reading groups...");
41 LOGD(
"Cleaning groups inheritance...");
43 LOGD(
"Creating groups...");
46 LOGD(
"Reading users...");
51 LOGD(
"Cleaning user groups...");
53 LOGD(
"Resolving user UUIDs...");
56 LOGD(
"Setting ranks...");
59 LOGD(
"Creating defaults...");
80 m_Inherits(a_Inherits),
81 m_Permissions(a_Permissions)
149 for (
int i = 0; i < NumGroups; i++)
153 if (m_Groups.find(lcGroupName) != m_Groups.end())
155 LOGINFO(
"groups.ini contains a duplicate definition of group %s, ignoring the latter.", GroupName.c_str());
158 m_Groups[lcGroupName] =
sGroup(
160 Groups.
GetValue(GroupName,
"Color",
""),
173 for (sGroupMap::iterator itrG = m_Groups.begin(), endG = m_Groups.end(); itrG != endG; ++itrG)
176 for (AStringVector::iterator itrI = Inherits.begin(); itrI != Inherits.end();)
179 if (m_Groups.find(lcInherits) != m_Groups.end())
186 LOGWARNING(
"RankMigrator: Group \"%s\" inherits from a non-existent group \"%s\", this inheritance will be ignored.",
187 itrG->second.m_Name.c_str(), itrI->c_str()
189 AStringVector::iterator itrI2 = itrI;
191 Inherits.erase(itrI);
211 for (
int i = 0; i < NumUsers; i++)
215 if (m_Users.find(lcUserName) != m_Users.end())
217 LOGINFO(
"users.ini contains a duplicate definition of user %s, ignoring the latter.", UserName.c_str());
220 m_Users[lcUserName] =
sUser(
233 for (sUserMap::iterator itrU = m_Users.begin(), endU = m_Users.end(); itrU != endU; ++itrU)
236 for (AStringVector::iterator itrG = Groups.begin(); itrG != Groups.end();)
239 if (m_Groups.find(lcGroup) != m_Groups.end())
246 LOGWARNING(
"RankMigrator: User \"%s\" is assigned a non-existent group \"%s\", this assignment will be ignored.",
247 itrU->second.m_Name.c_str(), itrG->c_str()
249 AStringVector::iterator itrG2 = itrG;
264 for (sGroupMap::const_iterator itr = m_Groups.begin(), end = m_Groups.end(); itr != end; ++itr)
266 m_RankManager.
AddGroup(itr->second.m_Name);
278 for (sUserMap::const_iterator itr = m_Users.begin(), end = m_Users.end(); itr != end; ++itr)
280 PlayerNames.push_back(itr->second.m_Name);
285 for (
auto & User : m_Users)
290 LOGWARNING(
"RankMigrator: Cannot resolve player %s to online UUID, player will be left unranked in online mode", User.second.m_Name.c_str());
292 User.second.m_UUID = UUID;
302 for (AStringVector::const_iterator itr = a_Groups.begin(), end = a_Groups.end(); itr != end; ++itr)
324 for (sUserMap::const_iterator itr = m_Users.begin(), end = m_Users.end(); itr != end; ++itr)
330 LOGWARNING(
"RankMigrator: Player %s has no groups assigned to them, skipping the player.", itr->second.m_Name.c_str());
336 for (AStringVector::const_iterator itrG = Groups.begin(), endG = Groups.end(); itrG != endG; ++itrG)
339 if (!RankName.empty())
341 RankName.push_back(
',');
343 RankName.append(GroupName);
354 m_RankManager.
SetPlayerRank(itr->second.m_UUID, itr->second.m_Name, RankName);
355 m_RankManager.
SetPlayerRank(itr->second.m_OfflineUUID, itr->second.m_Name, RankName);
367 m_RankManager.
AddRank(
"Default",
"",
"",
"");
385 m_DB(
"Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE),
386 m_IsInitialized(false),
412 m_DB.exec(
"CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgSuffix, MsgNameColorCode)");
413 m_DB.exec(
"CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
414 m_DB.exec(
"CREATE TABLE IF NOT EXISTS PermGroup (PermGroupID INTEGER PRIMARY KEY, Name)");
415 m_DB.exec(
"CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
416 m_DB.exec(
"CREATE TABLE IF NOT EXISTS PermissionItem (PermGroupID INTEGER, Permission)");
417 m_DB.exec(
"CREATE TABLE IF NOT EXISTS RestrictionItem (PermGroupID INTEGER, Permission)");
418 m_DB.exec(
"CREATE TABLE IF NOT EXISTS DefaultRank (RankID INTEGER)");
427 LOGINFO(
"There are no ranks, migrating old-style INI files to new DB ranks...");
428 LOGINFO(
"(This might take a while)");
438 LOGINFO(
"Rank migration failed, creating default ranks...");
440 LOGINFO(
"Default ranks created.");
446 SQLite::Statement stmt(
m_DB,
447 "SELECT Rank.Name FROM Rank " 448 "LEFT JOIN DefaultRank ON Rank.RankID = DefaultRank.RankID" 450 if (stmt.executeStep())
455 catch (
const SQLite::Exception & ex)
457 LOGWARNING(
"%s: Cannot load default rank: %s", __FUNCTION__, ex.what());
479 SQLite::Statement stmt(
m_DB,
"SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
482 if (!stmt.executeStep())
487 return stmt.getColumn(0).getText();
489 catch (
const SQLite::Exception & ex)
491 LOGWARNING(
"%s: Cannot get player rank name: %s", __FUNCTION__, ex.what());
508 SQLite::Statement stmt(
m_DB,
"SELECT PlayerName FROM PlayerRank WHERE PlayerUUID = ?");
511 if (stmt.executeStep())
513 return stmt.getColumn(0).getText();
516 catch (SQLite::Exception & ex)
518 LOGWARNING(
"%s: Cannot get player name: %s", __FUNCTION__, ex.what());
536 SQLite::Statement stmt(
m_DB,
537 "SELECT PermGroup.Name FROM PermGroup " 538 "LEFT JOIN RankPermGroup ON PermGroup.PermGroupID = RankPermGroup.PermGroupID " 539 "LEFT JOIN PlayerRank ON PlayerRank.RankID = RankPermGroup.RankID " 540 "WHERE PlayerRank.PlayerUUID = ?" 545 while (stmt.executeStep())
547 res.push_back(stmt.getColumn(0).getText());
550 catch (
const SQLite::Exception & ex)
552 LOGWARNING(
"%s: Cannot get player groups: %s", __FUNCTION__, ex.what());
597 SQLite::Statement stmt(
m_DB,
598 "SELECT PermGroup.Name FROM PermGroup " 599 "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID " 600 "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID " 601 "WHERE Rank.Name = ?" 603 stmt.bind(1, a_RankName);
604 while (stmt.executeStep())
606 res.push_back(stmt.getColumn(0).getText());
609 catch (
const SQLite::Exception & ex)
611 LOGWARNING(
"%s: Failed to get rank groups from DB: %s", __FUNCTION__, ex.what());
628 SQLite::Statement stmt(
m_DB,
629 "SELECT PermissionItem.Permission FROM PermissionItem " 630 "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID " 631 "WHERE PermGroup.Name = ?" 633 stmt.bind(1, a_GroupName);
634 while (stmt.executeStep())
636 res.push_back(stmt.getColumn(0).getText());
639 catch (
const SQLite::Exception & ex)
641 LOGWARNING(
"%s: Failed to get group permissions from DB: %s", __FUNCTION__, ex.what());
658 SQLite::Statement stmt(
m_DB,
659 "SELECT RestrictionItem.Permission FROM RestrictionItem " 660 "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RestrictionItem.PermGroupID " 661 "WHERE PermGroup.Name = ?" 663 stmt.bind(1, a_GroupName);
664 while (stmt.executeStep())
666 res.push_back(stmt.getColumn(0).getText());
669 catch (
const SQLite::Exception & ex)
671 LOGWARNING(
"%s: Failed to get group restrictions from DB: %s", __FUNCTION__, ex.what());
688 SQLite::Statement stmt(
m_DB,
689 "SELECT PermissionItem.Permission FROM PermissionItem " 690 "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermissionItem.PermGroupID " 691 "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID " 692 "WHERE Rank.Name = ?" 694 stmt.bind(1, a_RankName);
695 while (stmt.executeStep())
697 res.push_back(stmt.getColumn(0).getText());
700 catch (
const SQLite::Exception & ex)
702 LOGWARNING(
"%s: Failed to get rank permissions from DB: %s", __FUNCTION__, ex.what());
719 SQLite::Statement stmt(
m_DB,
720 "SELECT RestrictionItem.Permission FROM RestrictionItem " 721 "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = RestrictionItem.PermGroupID " 722 "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID " 723 "WHERE Rank.Name = ?" 725 stmt.bind(1, a_RankName);
726 while (stmt.executeStep())
728 res.push_back(stmt.getColumn(0).getText());
731 catch (
const SQLite::Exception & ex)
733 LOGWARNING(
"%s: Failed to get rank restrictions from DB: %s", __FUNCTION__, ex.what());
748 std::vector<cUUID> res;
751 SQLite::Statement stmt(
m_DB,
"SELECT PlayerUUID FROM PlayerRank ORDER BY PlayerName COLLATE NOCASE");
752 while (stmt.executeStep())
754 if (!tempUUID.
FromString(stmt.getColumn(0).getText()))
759 res.push_back(tempUUID);
762 catch (
const SQLite::Exception & ex)
764 LOGWARNING(
"%s: Failed to get players from DB: %s", __FUNCTION__, ex.what());
781 SQLite::Statement stmt(
m_DB,
"SELECT Name FROM Rank");
782 while (stmt.executeStep())
784 res.push_back(stmt.getColumn(0).getText());
787 catch (
const SQLite::Exception & ex)
789 LOGWARNING(
"%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
806 SQLite::Statement stmt(
m_DB,
"SELECT Name FROM PermGroup");
807 while (stmt.executeStep())
809 res.push_back(stmt.getColumn(0).getText());
812 catch (
const SQLite::Exception & ex)
814 LOGWARNING(
"%s: Failed to get groups from DB: %s", __FUNCTION__, ex.what());
831 SQLite::Statement stmt(
m_DB,
"SELECT DISTINCT(Permission) FROM PermissionItem");
832 while (stmt.executeStep())
834 res.push_back(stmt.getColumn(0).getText());
837 catch (
const SQLite::Exception & ex)
839 LOGWARNING(
"%s: Failed to get permissions from DB: %s", __FUNCTION__, ex.what());
856 SQLite::Statement stmt(
m_DB,
"SELECT DISTINCT(Permission) FROM RestrictionItem");
857 while (stmt.executeStep())
859 res.push_back(stmt.getColumn(0).getText());
862 catch (
const SQLite::Exception & ex)
864 LOGWARNING(
"%s: Failed to get restrictions from DB: %s", __FUNCTION__, ex.what());
877 for (
auto & restriction: Restrictions)
879 Permissions.push_back(restriction);
889 const cUUID & a_PlayerUUID,
901 a_MsgNameColorCode.clear();
904 return GetRankVisuals(Rank, a_MsgPrefix, a_MsgSuffix, a_MsgNameColorCode);
915 const AString & a_MsgNameColorCode
925 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM Rank WHERE Name = ?");
926 stmt.bind(1, a_RankName);
927 if (stmt.executeStep())
929 if (stmt.getColumn(0).getInt() > 0)
938 SQLite::Statement stmt(
m_DB,
"INSERT INTO Rank (Name, MsgPrefix, MsgSuffix, MsgNameColorCode) VALUES (?, ?, ?, ?)");
939 stmt.bind(1, a_RankName);
940 stmt.bind(2, a_MsgPrefix);
941 stmt.bind(3, a_MsgSuffix);
942 stmt.bind(4, a_MsgNameColorCode);
943 if (stmt.exec() <= 0)
945 LOGWARNING(
"%s: Failed to add a new rank \"%s\".", __FUNCTION__, a_RankName.c_str());
949 catch (
const SQLite::Exception & ex)
951 LOGWARNING(
"%s: Failed to add a new rank \"%s\": %s", __FUNCTION__, a_RankName.c_str(), ex.what());
968 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
969 stmt.bind(1, a_GroupName);
970 if (stmt.executeStep())
972 if (stmt.getColumn(0).getInt() > 0)
981 SQLite::Statement stmt(
m_DB,
"INSERT INTO PermGroup (Name) VALUES (?)");
982 stmt.bind(1, a_GroupName);
983 if (stmt.exec() <= 0)
985 LOGWARNING(
"%s: Failed to add a new group \"%s\".", __FUNCTION__, a_GroupName.c_str());
989 catch (
const SQLite::Exception & ex)
991 LOGWARNING(
"%s: Failed to add a new group \"%s\": %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
1006 for (AStringVector::const_iterator itr = a_GroupNames.begin(), end = a_GroupNames.end(); itr != end; ++itr)
1010 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
1012 if (stmt.executeStep())
1014 if (stmt.getColumn(0).getInt() > 0)
1023 SQLite::Statement stmt(
m_DB,
"INSERT INTO PermGroup (Name) VALUES (?)");
1025 if (stmt.exec() <= 0)
1027 LOGWARNING(
"%s: Failed to add a new group \"%s\".", __FUNCTION__, itr->c_str());
1032 catch (
const SQLite::Exception & ex)
1034 LOGWARNING(
"%s: Failed to add new groups: %s", __FUNCTION__, ex.what());
1052 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1053 stmt.bind(1, a_GroupName);
1054 if (!stmt.executeStep())
1056 LOGWARNING(
"%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
1059 GroupID = stmt.getColumn(0);
1065 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
1066 stmt.bind(1, a_RankName);
1067 if (!stmt.executeStep())
1069 LOGWARNING(
"%s: No such rank (%s), aborting.", __FUNCTION__, a_RankName.c_str());
1072 RankID = stmt.getColumn(0);
1077 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM RankPermGroup WHERE RankID = ? AND PermGroupID = ?");
1078 stmt.bind(1, RankID);
1079 stmt.bind(2, GroupID);
1080 if (!stmt.executeStep())
1082 LOGWARNING(
"%s: Failed to check binding between rank %s and group %s, aborting.", __FUNCTION__, a_RankName.c_str(), a_GroupName.c_str());
1085 if (stmt.getColumn(0).getInt() > 0)
1087 LOGD(
"%s: Group %s already present in rank %s, skipping and returning success.",
1088 __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str()
1096 SQLite::Statement stmt(
m_DB,
"INSERT INTO RankPermGroup (RankID, PermGroupID) VALUES (?, ?)");
1097 stmt.bind(1, RankID);
1098 stmt.bind(2, GroupID);
1099 if (stmt.exec() <= 0)
1101 LOGWARNING(
"%s: Failed to add group %s to rank %s, aborting.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
1109 catch (
const SQLite::Exception & ex)
1111 LOGWARNING(
"%s: Failed to add group %s to rank %s: %s", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str(), ex.what());
1130 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1131 stmt.bind(1, a_GroupName);
1132 if (!stmt.executeStep())
1134 LOGWARNING(
"%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
1137 GroupID = stmt.getColumn(0).getInt();
1142 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
1143 stmt.bind(1, GroupID);
1144 stmt.bind(2, a_Permission);
1145 if (!stmt.executeStep())
1147 LOGWARNING(
"%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
1150 if (stmt.getColumn(0).getInt() > 0)
1152 LOGD(
"%s: Permission %s is already present in group %s, skipping and returning success.",
1153 __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str()
1161 SQLite::Statement stmt(
m_DB,
"INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
1162 stmt.bind(1, a_Permission);
1163 stmt.bind(2, GroupID);
1164 if (stmt.exec() <= 0)
1166 LOGWARNING(
"%s: Failed to add permission %s to group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
1174 catch (
const SQLite::Exception & ex)
1176 LOGWARNING(
"%s: Failed to add permission %s to group %s: %s",
1177 __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
1197 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1198 stmt.bind(1, a_GroupName);
1199 if (!stmt.executeStep())
1201 LOGWARNING(
"%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
1204 GroupID = stmt.getColumn(0).getInt();
1209 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
1210 stmt.bind(1, GroupID);
1211 stmt.bind(2, a_Restriction);
1212 if (!stmt.executeStep())
1214 LOGWARNING(
"%s: Failed to check binding between restriction %s and group %s, aborting.", __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str());
1217 if (stmt.getColumn(0).getInt() > 0)
1219 LOGD(
"%s: Restriction %s is already present in group %s, skipping and returning success.",
1220 __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str()
1228 SQLite::Statement stmt(
m_DB,
"INSERT INTO RestrictionItem (Permission, PermGroupID) VALUES (?, ?)");
1229 stmt.bind(1, a_Restriction);
1230 stmt.bind(2, GroupID);
1231 if (stmt.exec() <= 0)
1233 LOGWARNING(
"%s: Failed to add restriction %s to group %s, aborting.", __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str());
1241 catch (
const SQLite::Exception & ex)
1243 LOGWARNING(
"%s: Failed to add restriction %s to group %s: %s",
1244 __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str(), ex.what()
1264 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1265 stmt.bind(1, a_GroupName);
1266 if (!stmt.executeStep())
1268 LOGWARNING(
"%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
1271 GroupID = stmt.getColumn(0).getInt();
1274 for (AStringVector::const_iterator itr = a_Permissions.begin(), end = a_Permissions.end(); itr != end; ++itr)
1278 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
1279 stmt.bind(1, GroupID);
1281 if (!stmt.executeStep())
1283 LOGWARNING(
"%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
1286 if (stmt.getColumn(0).getInt() > 0)
1288 LOGD(
"%s: Permission %s is already present in group %s, skipping and returning success.",
1289 __FUNCTION__, itr->c_str(), a_GroupName.c_str()
1297 SQLite::Statement stmt(
m_DB,
"INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
1299 stmt.bind(2, GroupID);
1300 if (stmt.exec() <= 0)
1302 LOGWARNING(
"%s: Failed to add permission %s to group %s, skipping.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
1311 catch (
const SQLite::Exception & ex)
1313 LOGWARNING(
"%s: Failed to add permissions to group %s: %s",
1314 __FUNCTION__, a_GroupName.c_str(), ex.what()
1334 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1335 stmt.bind(1, a_GroupName);
1336 if (!stmt.executeStep())
1338 LOGWARNING(
"%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
1341 GroupID = stmt.getColumn(0).getInt();
1344 for (
auto itr = a_Restrictions.cbegin(), end = a_Restrictions.cend(); itr != end; ++itr)
1348 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
1349 stmt.bind(1, GroupID);
1351 if (!stmt.executeStep())
1353 LOGWARNING(
"%s: Failed to check binding between restriction %s and group %s, aborting.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
1356 if (stmt.getColumn(0).getInt() > 0)
1358 LOGD(
"%s: Restriction %s is already present in group %s, skipping and returning success.",
1359 __FUNCTION__, itr->c_str(), a_GroupName.c_str()
1367 SQLite::Statement stmt(
m_DB,
"INSERT INTO RestrictionItem (Permission, PermGroupID) VALUES (?, ?)");
1369 stmt.bind(2, GroupID);
1370 if (stmt.exec() <= 0)
1372 LOGWARNING(
"%s: Failed to add restriction %s to group %s, skipping.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
1381 catch (
const SQLite::Exception & ex)
1383 LOGWARNING(
"%s: Failed to add restrictions to group %s: %s",
1384 __FUNCTION__, a_GroupName.c_str(), ex.what()
1402 LOGWARNING(
"%s: Cannot remove rank %s, it is the default rank and the replacement rank doesn't exist.", __FUNCTION__, a_RankName.c_str());
1412 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
1413 stmt.bind(1, a_RankName);
1414 if (!stmt.executeStep())
1416 LOGINFO(
"%s: Rank %s was not found. Skipping.", __FUNCTION__, a_RankName.c_str());
1419 RemoveRankID = stmt.getColumn(0).getInt();
1423 int ReplacementRankID = -1;
1425 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
1426 stmt.bind(1, a_ReplacementRankName);
1427 if (stmt.executeStep())
1429 ReplacementRankID = stmt.getColumn(0).getInt();
1435 SQLite::Statement stmt(
m_DB,
"DELETE FROM RankPermGroup WHERE RankID = ?");
1436 stmt.bind(1, RemoveRankID);
1441 if (ReplacementRankID == -1)
1444 SQLite::Statement stmt(
m_DB,
"DELETE FROM PlayerRank WHERE RankID = ?");
1445 stmt.bind(1, RemoveRankID);
1451 SQLite::Statement stmt(
m_DB,
"UPDATE PlayerRank SET RankID = ? WHERE RankID = ?");
1452 stmt.bind(1, ReplacementRankID);
1453 stmt.bind(2, RemoveRankID);
1459 SQLite::Statement stmt(
m_DB,
"DELETE FROM Rank WHERE RankID = ?");
1460 stmt.bind(1, RemoveRankID);
1470 catch (
const SQLite::Exception & ex)
1472 LOGWARNING(
"%s: Failed to remove rank from DB: %s", __FUNCTION__, ex.what());
1490 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1491 stmt.bind(1, a_GroupName);
1492 if (!stmt.executeStep())
1494 LOGINFO(
"%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1497 GroupID = stmt.getColumn(0).getInt();
1502 SQLite::Statement stmt(
m_DB,
"DELETE FROM PermissionItem WHERE PermGroupID = ?");
1503 stmt.bind(1, GroupID);
1509 SQLite::Statement stmt(
m_DB,
"DELETE FROM RankPermGroup WHERE PermGroupID = ?");
1510 stmt.bind(1, GroupID);
1516 SQLite::Statement stmt(
m_DB,
"DELETE FROM PermGroup WHERE PermGroupID = ?");
1517 stmt.bind(1, GroupID);
1521 catch (
const SQLite::Exception & ex)
1523 LOGWARNING(
"%s: Failed to remove group %s from DB: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
1539 int GroupID, RankID;
1541 SQLite::Statement stmt(
m_DB,
1542 "SELECT PermGroup.PermGroupID, Rank.RankID FROM PermGroup " 1543 "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID " 1544 "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID " 1545 "WHERE PermGroup.Name = ? AND Rank.Name = ?" 1547 stmt.bind(1, a_GroupName);
1548 stmt.bind(2, a_RankName);
1549 if (!stmt.executeStep())
1551 LOGINFO(
"%s: Group %s was not found in rank %s, skipping.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
1554 GroupID = stmt.getColumn(0).getInt();
1555 RankID = stmt.getColumn(1).getInt();
1560 SQLite::Statement stmt(
m_DB,
"DELETE FROM RankPermGroup WHERE PermGroupID = ?");
1561 stmt.bind(1, GroupID);
1567 SQLite::Statement stmt(
m_DB,
"DELETE FROM RankPermGroup WHERE PermGroupID = ? AND RankID = ?");
1568 stmt.bind(1, GroupID);
1569 stmt.bind(1, RankID);
1573 catch (
const SQLite::Exception & ex)
1575 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());
1593 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1594 stmt.bind(1, a_GroupName);
1595 if (!stmt.executeStep())
1597 LOGINFO(
"%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1600 GroupID = stmt.getColumn(0).getInt();
1605 SQLite::Statement stmt(
m_DB,
"DELETE FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
1606 stmt.bind(1, GroupID);
1607 stmt.bind(2, a_Permission);
1611 catch (
const SQLite::Exception & ex)
1613 LOGWARNING(
"%s: Failed to remove permission %s from group %s in DB: %s",
1614 __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
1633 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1634 stmt.bind(1, a_GroupName);
1635 if (!stmt.executeStep())
1637 LOGINFO(
"%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
1640 GroupID = stmt.getColumn(0).getInt();
1645 SQLite::Statement stmt(
m_DB,
"DELETE FROM RestrictionItem WHERE PermGroupID = ? AND Permission = ?");
1646 stmt.bind(1, GroupID);
1647 stmt.bind(2, a_Restriction);
1651 catch (
const SQLite::Exception & ex)
1653 LOGWARNING(
"%s: Failed to remove restriction %s from group %s in DB: %s",
1654 __FUNCTION__, a_Restriction.c_str(), a_GroupName.c_str(), ex.what()
1672 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
1673 stmt.bind(1, a_NewName);
1674 if (stmt.executeStep())
1676 LOGINFO(
"%s: Rank %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
1683 SQLite::Statement stmt(
m_DB,
"UPDATE Rank SET Name = ? WHERE Name = ?");
1684 stmt.bind(1, a_NewName);
1685 stmt.bind(2, a_OldName);
1686 if (stmt.exec() <= 0)
1688 LOGINFO(
"%s: There is no rank %s, cannot rename to %s.", __FUNCTION__, a_OldName.c_str(), a_NewName.c_str());
1701 catch (
const SQLite::Exception & ex)
1703 LOGWARNING(
"%s: Failed to rename rank %s to %s in DB: %s",
1704 __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
1722 SQLite::Statement stmt(
m_DB,
"SELECT PermGroupID FROM PermGroup WHERE Name = ?");
1723 stmt.bind(1, a_NewName);
1724 if (stmt.executeStep())
1726 LOGD(
"%s: Group %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
1734 SQLite::Statement stmt(
m_DB,
"UPDATE PermGroup SET Name = ? WHERE Name = ?");
1735 stmt.bind(1, a_NewName);
1736 stmt.bind(2, a_OldName);
1737 res = (stmt.exec() > 0);
1742 catch (
const SQLite::Exception & ex)
1744 LOGWARNING(
"%s: Failed to rename group %s to %s in DB: %s",
1745 __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
1766 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
1767 stmt.bind(1, a_RankName);
1768 if (!stmt.executeStep())
1770 LOGWARNING(
"%s: There is no rank %s, aborting.", __FUNCTION__, a_RankName.c_str());
1773 RankID = stmt.getColumn(0).getInt();
1778 SQLite::Statement stmt(
m_DB,
"UPDATE PlayerRank SET RankID = ?, PlayerName = ? WHERE PlayerUUID = ?");
1779 stmt.bind(1, RankID);
1780 stmt.bind(2, a_PlayerName);
1781 stmt.bind(3, StrUUID);
1782 if (stmt.exec() > 0)
1790 SQLite::Statement stmt(
m_DB,
"INSERT INTO PlayerRank (RankID, PlayerUUID, PlayerName) VALUES (?, ?, ?)");
1791 stmt.bind(1, RankID);
1792 stmt.bind(2, StrUUID);
1793 stmt.bind(3, a_PlayerName);
1794 if (stmt.exec() > 0)
1800 LOGWARNING(
"%s: Failed to set player UUID %s to rank %s.",
1801 __FUNCTION__, StrUUID.c_str(), a_RankName.c_str()
1804 catch (
const SQLite::Exception & ex)
1806 LOGWARNING(
"%s: Failed to set player UUID %s to rank %s: %s",
1807 __FUNCTION__, StrUUID.c_str(), a_RankName.c_str(), ex.what()
1825 SQLite::Statement stmt(
m_DB,
"DELETE FROM PlayerRank WHERE PlayerUUID = ?");
1826 stmt.bind(1, StrUUID);
1829 catch (
const SQLite::Exception & ex)
1831 LOGWARNING(
"%s: Failed to remove rank from player UUID %s: %s",
1832 __FUNCTION__, StrUUID.c_str(), ex.what()
1845 const AString & a_MsgNameColorCode
1853 SQLite::Statement stmt(
m_DB,
"UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?");
1854 stmt.bind(1, a_MsgPrefix);
1855 stmt.bind(2, a_MsgSuffix);
1856 stmt.bind(3, a_MsgNameColorCode);
1857 stmt.bind(4, a_RankName);
1858 if (stmt.exec() < 1)
1860 LOGINFO(
"%s: Rank %s not found, visuals not set.", __FUNCTION__, a_RankName.c_str());
1863 catch (
const SQLite::Exception & ex)
1865 LOGWARNING(
"%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
1885 SQLite::Statement stmt(
m_DB,
"SELECT MsgPrefix, MsgSuffix, MsgNameColorCode FROM Rank WHERE Name = ?");
1886 stmt.bind(1, a_RankName);
1887 if (!stmt.executeStep())
1892 a_MsgPrefix = stmt.getColumn(0).getText();
1893 a_MsgSuffix = stmt.getColumn(1).getText();
1894 a_MsgNameColorCode = stmt.getColumn(2).getText();
1897 catch (
const SQLite::Exception & ex)
1899 LOGWARNING(
"%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
1915 SQLite::Statement stmt(
m_DB,
"SELECT * FROM Rank WHERE Name = ?");
1916 stmt.bind(1, a_RankName);
1917 if (stmt.executeStep())
1923 catch (
const SQLite::Exception & ex)
1925 LOGWARNING(
"%s: Failed to query DB for rank %s: %s", __FUNCTION__, a_RankName.c_str(), ex.what());
1941 SQLite::Statement stmt(
m_DB,
"SELECT * FROM PermGroup WHERE Name = ?");
1942 stmt.bind(1, a_GroupName);
1943 if (stmt.executeStep())
1949 catch (
const SQLite::Exception & ex)
1951 LOGWARNING(
"%s: Failed to query DB for group %s: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
1969 SQLite::Statement stmt(
m_DB,
"SELECT * FROM PlayerRank WHERE PlayerUUID = ?");
1970 stmt.bind(1, StrUUID);
1971 if (stmt.executeStep())
1977 catch (
const SQLite::Exception & ex)
1979 LOGWARNING(
"%s: Failed to query DB for player UUID %s: %s", __FUNCTION__, StrUUID.c_str(), ex.what());
1995 SQLite::Statement stmt(
m_DB,
1996 "SELECT * FROM Rank " 1997 "LEFT JOIN RankPermGroup ON Rank.RankID = RankPermGroup.RankID " 1998 "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RankPermGroup.PermGroupID " 1999 "WHERE Rank.Name = ? AND PermGroup.Name = ?" 2001 stmt.bind(1, a_RankName);
2002 stmt.bind(2, a_GroupName);
2003 if (stmt.executeStep())
2009 catch (
const SQLite::Exception & ex)
2011 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, ex.what());
2027 SQLite::Statement stmt(
m_DB,
2028 "SELECT * FROM PermissionItem " 2029 "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID " 2030 "WHERE PermissionItem.Permission = ? AND PermGroup.Name = ?" 2032 stmt.bind(1, a_Permission);
2033 stmt.bind(2, a_GroupName);
2034 if (stmt.executeStep())
2040 catch (
const SQLite::Exception & ex)
2042 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, ex.what());
2058 SQLite::Statement stmt(
m_DB,
2059 "SELECT * FROM RestrictionItem " 2060 "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RestrictionItem.PermGroupID " 2061 "WHERE RestrictionItem.Permission = ? AND PermGroup.Name = ?" 2063 stmt.bind(1, a_Restriction);
2064 stmt.bind(2, a_GroupName);
2065 if (stmt.executeStep())
2071 catch (
const SQLite::Exception & ex)
2073 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, ex.what());
2089 SQLite::Statement stmt(
m_DB,
"UPDATE PlayerRank SET PlayerName = ? WHERE PlayerUUID = ?");
2090 stmt.bind(1, a_PlayerName);
2094 catch (
const SQLite::Exception & ex)
2096 LOGWARNING(
"%s: Failed to update DB: %s", __FUNCTION__, ex.what());
2114 SQLite::Statement stmt(
m_DB,
"SELECT RankID FROM Rank WHERE Name = ?");
2115 stmt.bind(1, a_RankName);
2116 if (!stmt.executeStep())
2118 LOGINFO(
"%s: Cannot set rank %s as the default, it does not exist.", __FUNCTION__, a_RankName.c_str());
2125 SQLite::Statement stmt(
m_DB,
"UPDATE DefaultRank SET RankID = ?");
2126 stmt.bind(1, RankID);
2127 if (stmt.exec() < 1)
2130 SQLite::Statement stmt2(
m_DB,
"INSERT INTO DefaultRank (RankID) VALUES (?)");
2131 stmt2.bind(1, RankID);
2132 if (stmt2.exec() < 1)
2134 LOGINFO(
"%s: Cannot update the default rank in the DB to %s.", __FUNCTION__, a_RankName.c_str());
2144 catch (
const SQLite::Exception & ex)
2146 LOGWARNING(
"%s: Failed to update DB: %s", __FUNCTION__, ex.what());
2162 SQLite::Statement stmt(
m_DB,
"DELETE FROM PlayerRank");
2165 catch (SQLite::Exception & ex)
2167 LOGWARNING(
"%s: Failed to remove / clear all players: %s", __FUNCTION__, ex.what());
2184 SQLite::Statement stmt(
m_DB,
"UPDATE PlayerRank SET PlayerName = ? WHERE PlayerUUID = ?");
2185 stmt.bind(1, a_NewPlayerName);
2186 stmt.bind(2, StrUUID);
2187 if (stmt.exec() > 0)
2193 catch (
const SQLite::Exception & ex)
2195 LOGWARNING(
"%s: Failed to update player name from UUID %s: %s", __FUNCTION__, StrUUID.c_str(), ex.what());
2224 SQLite::Statement stmt(
m_DB,
"SELECT COUNT(*) FROM " + a_TableName);
2225 return (stmt.executeStep() && (stmt.getColumn(0).getInt() == 0));
2227 catch (
const SQLite::Exception & ex)
2229 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, ex.what());
2244 AddRank(
"Default",
"",
"",
"");
2246 AddRank(
"Operator",
"",
"",
"");
2281 SQLite::Statement stmt(
m_DB,
Printf(
"PRAGMA table_info(%s)", a_TableName));
2282 while (stmt.executeStep())
2284 int NumColumns = stmt.getColumnCount();
2285 for (
int i = 0; i < NumColumns; i++)
2287 auto column = stmt.getColumn(i);
2288 if (strcmp(column.getName(),
"name") == 0)
2299 catch (
const SQLite::Exception & ex)
2301 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, ex.what());
2321 m_DB.exec(
Printf(
"ALTER TABLE %s ADD COLUMN %s %s", a_TableName, a_ColumnName, a_ColumnType));
2323 catch (
const SQLite::Exception & exc)
2325 LOGWARNING(
"%s: Failed to query DB: %s", __FUNCTION__, exc.what());
cRankManager(void)
Creates the rank manager.
void Initialize(cMojangAPI &a_MojangAPI)
Initializes the rank manager.
void ClearPlayerRanks(void)
Removes all player ranks from the database.
bool AreDBTablesEmpty(void)
Returns true if all the DB tables are empty, indicating a fresh new install.
sUserMap m_Users
List of all players read from the ini file.
void RemoveRestrictionFromGroup(const AString &a_Restriction, const AString &a_GroupName)
Removes the specified restriction from the specified group.
std::vector< cUUID > GetUUIDsFromPlayerNames(const AStringVector &a_PlayerName, bool a_UseOnlyCached=false)
Converts the player names into UUIDs.
AStringVector GetPlayerGroups(const cUUID &a_PlayerUUID)
Returns the names of Groups that the specified player has assigned to them.
void CreateDefaults(void)
Creates a default set of ranks / groups / permissions.
void ResolveUserUUIDs(void)
Resolves the UUID of each user in m_Users.
bool IsGroupInRank(const AString &a_GroupName, const AString &a_RankName)
Returns true iff the specified rank contains the specified group.
std::map< AString, sGroup > sGroupMap
bool ReadGroups(void)
Reads the groups from the "groups.ini" file into m_Groups.
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
void CreateGroups(void)
Creates groups based on m_Groups.
AStringVector GetAllRanks(void)
Returns the names of all defined ranks.
int GetNumKeys(void) const
Returns number of keys currently in the ini.
AStringVector GetRankPermissions(const AString &a_RankName)
Returns all permissions that the specified rank has assigned to it, through all its groups...
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
void CleanUserGroups(void)
Removes non-existent groups from each user's definition.
bool m_IsInitialized
Set to true once the manager is initialized.
bool AddRestrictionsToGroup(const AStringVector &a_Restrictions, const AString &a_GroupName)
Adds the specified restrictions to the specified group.
AString GetPlayerRankName(const cUUID &a_PlayerUUID)
Returns the name of the rank that the specified player has assigned to them.
bool AddGroupToRank(const AString &a_GroupName, const AString &a_RankName)
Adds the specified permission group to the specified rank.
AStringVector GetPlayerPermissions(const cUUID &a_PlayerUUID)
Returns the permissions that the specified player has assigned to them.
void CreateDefaults(void)
Creates the Default rank that contains the Default group, if it exists.
bool IsPermissionInGroup(const AString &a_Permission, const AString &a_GroupName)
Returns true iff the specified group contains the specified permission.
AStringVector GetPlayerRestrictions(const cUUID &a_PlayerUUID)
Returns the restrictions that the specified player has assigned to them.
void CleanGroupInheritance(void)
Removes non-existent groups from all the groups' inheritance.
bool AddRestrictionToGroup(const AString &a_Restriction, const AString &a_GroupName)
Adds the specified restriction to the specified group.
bool GetRankVisuals(const AString &a_RankName, AString &a_MsgPrefix, AString &a_MsgSuffix, AString &a_MsgNameColorCode)
Returns the message visuals of an existing rank.
AStringVector m_Permissions
AStringVector GetAllGroups(void)
Returns the names of all permission groups.
void NotifyNameUUID(const AString &a_PlayerName, const cUUID &a_UUID)
Called by cMojangAPI whenever the playername-uuid pairing is discovered.
bool RankExists(const AString &a_RankName)
Returns true iff the specified rank exists in the DB.
void AddGroup(const AString &a_GroupName)
Adds a new permission group.
void RemovePermissionFromGroup(const AString &a_Permission, const AString &a_GroupName)
Removes the specified permission from the specified group.
AStringVector GetRankRestrictions(const AString &a_RankName)
Returns all restrictions that the specified rank has assigned to it, through all its groups...
bool RenameRank(const AString &a_OldName, const AString &a_NewName)
Renames the specified rank.
bool DoesColumnExist(const char *a_TableName, const char *a_ColumnName)
Returns true if the specified column exists in the specified table.
void AddRank(const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
Adds a new rank.
SQLite::Database m_DB
The database storage for all the data.
AString GetPlayerName(const cUUID &a_PlayerUUID)
Returns the last name that the specified player has.
void RemoveRank(const AString &a_RankName, const AString &a_ReplacementRankName)
Removes the specified rank.
bool ReadFile(const AString &a_FileName, bool a_AllowExampleRedirect=true)
Reads the contents of the specified ini file If the file doesn't exist and a_AllowExampleRedirect is ...
AStringVector GetGroupPermissions(const AString &a_GroupName)
Returns the permissions that the specified group has assigned to it.
void SetRankManager(cRankManager *a_RankManager)
Sets the m_RankMgr that is used for name-uuid notifications.
std::vector< AString > AStringVector
Migrates from groups.ini and users.ini into the rankmanager DB.
std::map< AString, AString > cStringMap
sGroup(const AString &a_Name, const AString &a_Color, const AStringVector &a_Inherits, const AStringVector &a_Permissions)
AStringVector GetAllPermissions(void)
Returns all the distinct permissions that are stored in the DB.
bool RenameGroup(const AString &a_OldName, const AString &a_NewName)
Renames the specified group.
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.
void SetRanks(void)
Creates a rank for each player, based on the master groups they are assigned.
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
AStringVector StringSplitAndTrim(const AString &str, const AString &delim)
Split the string at any of the listed delimiters and trim each value.
bool IsPlayerRankSet(const cUUID &a_PlayerUUID)
Returns true iff the specified player has a rank assigned to them in the DB.
cMojangAPI * m_MojangAPI
The MojangAPI instance that is used for translating playernames to UUIDs.
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
AStringVector GetAllRestrictions(void)
Returns all the distinct restrictions that are stored in the DB.
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
void RemovePlayerRank(const cUUID &a_PlayerUUID)
Removes the player's rank assignment.
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
bool UpdatePlayerName(const cUUID &a_PlayerUUID, const AString &a_NewPlayerName)
Updates the playername that is saved with this uuid.
bool IsRestrictionInGroup(const AString &a_Restriction, const AString &a_GroupName)
Returns true iff the specified group contains the specified restriction.
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.
Container for a group read from an INI file.
sUser(const AString &a_Name, const AStringVector &a_Groups)
Container for a single user read from an INI file.
AString GetKeyName(const int keyID) const
bool IsDBTableEmpty(const AString &a_TableName)
Returns true iff the specified DB table is empty.
bool AddPermissionToGroup(const AString &a_Permission, const AString &a_GroupName)
Adds the specified permission to the specified permission group.
bool AddPermissionsToGroup(const AStringVector &a_Permissions, const AString &a_GroupName)
Adds the specified permissions to the specified permission group.
bool Migrate(void)
Performs the complete migration from INI files to DB.
cUUID GetUUIDFromPlayerName(const AString &a_PlayerName, bool a_UseOnlyCached=false)
Converts a player name into a UUID.
sGroupMap m_Groups
List of all groups read from the ini file.
bool GroupExists(const AString &a_GroupName)
Returns true iff the specified group exists in the DB.
cCriticalSection m_CS
The mutex protecting m_DB and m_DefaultRank against multi-threaded access.
cUUID m_UUID
Assigned by ResolveUserUUIDs(), contains the online (Mojang) UUID of the player.
void GenerateOfflineUUID(void)
Generates an UUID based on the username stored for this client, and stores it in the m_UUID member...
cMojangAPI & m_MojangAPI
The player name to UUID resolver.
std::vector< cUUID > GetAllPlayerUUIDs(void)
Returns the uuids of all defined players.
AString m_DefaultRank
The name of the default rank.
cUUID m_OfflineUUID
Assigned by ResolveUserUUIDs(), contains the offline (generated) UUID of the player.
AStringVector GetGroupRestrictions(const AString &a_GroupName)
Returns the restrictions that the specified group has assigned to it.
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
cRankManager & m_RankManager
The parent Rank manager where we will create the groups, ranks and players.
AStringVector GetRankGroups(const AString &a_RankName)
Returns the names of groups that the specified rank has assigned to it.
cStringMap m_GroupsToRanks
Maps lists of groups to rank names.
Acquire this lock to perform mass changes.
void AddGroups(const AStringVector &a_GroupNames)
Bulk-adds groups.
cRankManagerIniMigrator(cRankManager &a_RankManager, cMojangAPI &a_MojangAPI)
void RemoveGroupFromRank(const AString &a_GroupName, const AString &a_RankName)
Removes the specified group from the specified rank.
void RemoveGroup(const AString &a_GroupName)
Removes the specified group completely.
bool SetDefaultRank(const AString &a_RankName)
Sets the specified rank as the default rank.
AStringVector GetAllPermissionsRestrictions(void)
Returns all the distinct permissions and restrictions that are stored in the DB.
AString GetValue(const AString &keyname, const AString &valuename, const AString &defValue="") const override
Get the value at the specified key and value, returns defValue on failure.
AString StrToLower(const AString &s)
Returns a lower-cased copy of the string.
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
bool ReadUsers(void)
Reads the users from the "users.ini" file into m_Users.
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.
void SetPlayerRank(const cUUID &a_PlayerUUID, const AString &a_PlayerName, const AString &a_RankName)
Sets the specified player's rank.
std::map< AString, sUser > sUserMap
void AddGroupsToRank(const AStringVector &a_Groups, const AString &a_RankName)
Adds the specified groups to the specified ranks.