extend user block fields check
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "data/StructLayout.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace data;
|
||||
|
||||
static debug::Logger logger("content-loader");
|
||||
|
||||
@@ -117,6 +118,30 @@ void ContentLoader::fixPackIndices() {
|
||||
}
|
||||
}
|
||||
|
||||
static void perform_user_block_fields(
|
||||
const std::string& blockName, StructLayout& layout
|
||||
) {
|
||||
if (layout.size() > MAX_USER_BLOCK_FIELDS_SIZE) {
|
||||
throw std::runtime_error(
|
||||
util::quote(blockName) +
|
||||
" fields total size exceeds limit (" +
|
||||
std::to_string(layout.size()) + "/" +
|
||||
std::to_string(MAX_USER_BLOCK_FIELDS_SIZE) + ")");
|
||||
}
|
||||
for (const auto& field : layout) {
|
||||
if (field.name.at(0) == '.') {
|
||||
throw std::runtime_error(
|
||||
util::quote(blockName) + " field " + field.name +
|
||||
": user field may not start with '.'");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Field> fields;
|
||||
fields.insert(fields.end(), layout.begin(), layout.end());
|
||||
// add built-in fields here
|
||||
layout = StructLayout::create(fields);
|
||||
}
|
||||
|
||||
void ContentLoader::loadBlock(
|
||||
Block& def, const std::string& name, const fs::path& file
|
||||
) {
|
||||
@@ -253,15 +278,10 @@ void ContentLoader::loadBlock(
|
||||
root.at("tick-interval").get(def.tickInterval);
|
||||
|
||||
if (root.has("fields")) {
|
||||
def.dataStruct = std::make_unique<data::StructLayout>();
|
||||
def.dataStruct = std::make_unique<StructLayout>();
|
||||
def.dataStruct->deserialize(root["fields"]);
|
||||
if (def.dataStruct->size() > MAX_BLOCK_FIELDS_SIZE) {
|
||||
throw std::runtime_error(
|
||||
util::quote(def.name) +
|
||||
" fields total size exceeds limit (" +
|
||||
std::to_string(def.dataStruct->size()) + "/" +
|
||||
std::to_string(MAX_BLOCK_FIELDS_SIZE) + ")");
|
||||
}
|
||||
|
||||
perform_user_block_fields(def.name, *def.dataStruct);
|
||||
}
|
||||
|
||||
if (def.tickInterval == 0) {
|
||||
|
||||
Reference in New Issue
Block a user