bool Commands::loadFromXml() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/XML/commands.xml"); if (!result) { std::cout << "[Error - Commands::loadFromXml] Failed to load data/XML/commands.xml: " << result.description() << std::endl; return false; } loaded = true; for (pugi::xml_node commandNode = doc.child("commands").first_child(); commandNode; commandNode = commandNode.next_sibling()) { pugi::xml_attribute cmdAttribute = commandNode.attribute("cmd"); if (!cmdAttribute) { std::cout << "[Warning - Commands::loadFromXml] Missing cmd" << std::endl; continue; } auto it = commandMap.find(cmdAttribute.as_string()); if (it == commandMap.end()) { std::cout << "[Warning - Commands::loadFromXml] Unknown command " << cmdAttribute.as_string() << std::endl; continue; } Command* command = it->second; pugi::xml_attribute groupAttribute = commandNode.attribute("group"); if (groupAttribute) { if (!command->loadedGroupId) { command->groupId = pugi::cast<uint32_t>(groupAttribute.value()); command->loadedGroupId = true; } else { std::cout << "[Notice - Commands::loadFromXml] Duplicate command: " << it->first << std::endl; } } pugi::xml_attribute acctypeAttribute = commandNode.attribute("acctype"); if (acctypeAttribute) { if (!command->loadedAccountType) { command->accountType = (AccountType_t)pugi::cast<uint32_t>(acctypeAttribute.value()); command->loadedAccountType = true; } else { std::cout << "[Notice - Commands::loadFromXml] Duplicate command: " << it->first << std::endl; } } pugi::xml_attribute logAttribute = commandNode.attribute("log"); if (logAttribute) { if (!command->loadedLogging) { command->logged = booleanString(logAttribute.as_string()); command->loadedLogging = true; } else { std::cout << "[Notice - Commands::loadFromXml] Duplicate log tag for: " << it->first << std::endl; } } } for (const auto& it : commandMap) { Command* command = it.second; if (!command->loadedGroupId) { std::cout << "[Warning - Commands::loadFromXml] Missing group id for command " << it.first << std::endl; } if (!command->loadedAccountType) { std::cout << "[Warning - Commands::loadFromXml] Missing acctype level for command " << it.first << std::endl; } if (!command->loadedLogging) { std::cout << "[Warning - Commands::loadFromXml] Missing log command " << it.first << std::endl; } g_game.addCommandTag(it.first[0]); } return loaded; }