#include "CDDeletionRestrictionsTable.h" #include "GeneralUtils.h" #include "eDeletionRestrictionsCheckType.h" CDDeletionRestriction CDDeletionRestrictionsTable::Default = { .id = 0, .restricted = false, .ids = {}, .checkType = eDeletionRestrictionsCheckType::MAX }; void CDDeletionRestrictionsTable::LoadValuesFromDatabase() { uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM CurrencyTable"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); tableSize.nextRow(); } tableSize.finalize(); auto& entries = GetEntriesMutable(); auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions"); while (!tableData.eof()) { CDDeletionRestriction entry; 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(idstr).value_or(-1); if (id != -1) entry.ids.push_back(id); } } } entry.checkType = static_cast(tableData.getIntField("checkType", 6)); // MAX entries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } tableData.finalize(); } 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; }