#!/usr/bin/env python3 """Compile the active item-level material policy and verify its grant/storage rules.""" import pathlib import subprocess import tempfile root = pathlib.Path(__file__).resolve().parents[2] source = r''' #include typedef uint8_t BYTE; typedef uint16_t WORD; #include "src/server/common/length.h" #include "src/server/common/item_length.h" #include "src/server/game/src/port_material_stack_policy.h" #include int main() { using namespace PortMaterialStackPolicy; for (auto t : {ITEM_USE, ITEM_AUTOUSE, ITEM_MATERIAL, ITEM_METIN, ITEM_RESOURCE, ITEM_BLEND, ITEM_EXTRACT}) assert(Limit(t, true, false) == 2000); assert(Limit(ITEM_USE, false, false) == 200); assert(Limit(ITEM_USE, true, true) == 200); assert(Limit(ITEM_QUEST, true, false) == 200); assert(Limit(ITEM_TREASURE_BOX, true, false) == 200); assert(Limit(ITEM_WEAPON, false, false) == 200); assert(GrantLimit(ITEM_WEAPON, false, false) == 1); assert(GrantLimit(ITEM_USE, true, true) == 1); setenv("PORT_MATERIAL_STACK_QA_LOGIN", "alice,bob", 1); assert(QAAllowed("alice") && QAAllowed("bob") && !QAAllowed("ali") && !QAAllowed("eve")); unsetenv("PORT_MATERIAL_STACK_QA_LOGIN"); assert(QAAllowed("eve")); setenv("PORT_MATERIAL_STACK_LEGACY_MODE", "1", 1); assert(LegacyGrowthMode()); assert(Limit(ITEM_USE, true, false) == 2000); // Reading old wide rows remains safe. unsetenv("PORT_MATERIAL_STACK_LEGACY_MODE"); assert(!LegacyGrowthMode()); RefineIngredients().insert(999001); assert(Limit(ITEM_QUEST, true, false, 999001) == 2000); assert(Limit(ITEM_QUEST, true, false, 999002) == 200); } '''.replace('#include ', '#include \n#include ') with tempfile.TemporaryDirectory() as td: path = pathlib.Path(td) / 'policy.cpp' path.write_text(source) exe = pathlib.Path(td) / 'policy' subprocess.run(['c++', '-std=c++11', '-I', str(root), str(path), '-o', str(exe)], check=True) subprocess.run([str(exe)], check=True) print('PASS: material stack policy')