DarkflameServer/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.cpp

49 lines
1.4 KiB
C++
Raw Normal View History

2024-06-05 07:39:36 +00:00
#include "CDDeletionRestrictionsTable.h"
#include "GeneralUtils.h"
#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()) {
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
entries.insert(std::make_pair(entry.id, entry));
2024-06-05 07:39:36 +00:00
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;
2024-06-05 07:39:36 +00:00
}