2024-06-05 07:39:36 +00:00
|
|
|
#include "CDDeletionRestrictionsTable.h"
|
|
|
|
#include "GeneralUtils.h"
|
2024-06-07 02:11:43 +00:00
|
|
|
#include "eDeletionRestrictionsCheckType.h"
|
|
|
|
|
|
|
|
CDDeletionRestriction CDDeletionRestrictionsTable::Default = {
|
|
|
|
.id = 0,
|
|
|
|
.restricted = false,
|
|
|
|
.ids = {},
|
|
|
|
.checkType = eDeletionRestrictionsCheckType::MAX
|
|
|
|
};
|
2024-06-05 07:39:36 +00:00
|
|
|
|
|
|
|
void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
|
|
|
|
|
|
|
|
|
|
|
|
auto& entries = GetEntriesMutable();
|
|
|
|
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions");
|
|
|
|
while (!tableData.eof()) {
|
2024-06-07 02:11:43 +00:00
|
|
|
CDDeletionRestriction entry;
|
2024-06-05 07:39:36 +00:00
|
|
|
entry.id = tableData.getIntField("id", -1);
|
|
|
|
if (entry.id == -1) continue;
|
|
|
|
entry.restricted = tableData.getIntField("restricted", -1);
|
|
|
|
const std::string raw_ids = tableData.getStringField("ids", "");
|
|
|
|
if (!raw_ids.empty()) {
|
|
|
|
for (const auto& idstr : GeneralUtils::SplitString(raw_ids, ',')) {
|
|
|
|
if (!idstr.empty()) {
|
|
|
|
const auto id = GeneralUtils::TryParse<int32_t>(idstr).value_or(-1);
|
|
|
|
if (id != -1) entry.ids.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-06 13:50:00 +00:00
|
|
|
entry.checkType = static_cast<eDeletionRestrictionsCheckType>(tableData.getIntField("checkType", 6)); // MAX
|
2024-06-05 07:39:36 +00:00
|
|
|
|
2024-06-07 02:11:43 +00:00
|
|
|
entries.insert(std::make_pair(entry.id, entry));
|
2024-06-05 07:39:36 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
tableData.finalize();
|
|
|
|
}
|
|
|
|
|
2024-06-07 02:11:43 +00:00
|
|
|
const CDDeletionRestriction& CDDeletionRestrictionsTable::GetByID(uint32_t id) {
|
|
|
|
auto& entries = GetEntries();
|
|
|
|
const auto& it = entries.find(id);
|
|
|
|
if (it != entries.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
return Default;
|
2024-06-05 07:39:36 +00:00
|
|
|
}
|