fix: character xml load and save no longer crash on bad data

Loading a character whose xml has a malformed flag threw out of
std::stoul, and a character whose xml failed to parse (or has no obj
tag) dereferenced null on load and again on every save.

- Flags are parsed with TryParse and a malformed one is logged and
  skipped instead of aborting the load.
- The quick parse checks for the obj and items tags before using them.
- Saving refuses to run when the document has no obj tag, logging that
  the character was not saved, instead of crashing and taking every
  other player's unsaved progress with it.
- The remaining obj-child lookups go through a helper that returns null
  when the root is missing.

Component LoadFromXml/UpdateXml still assume a valid document; refusing
to load a player with invalid xml belongs in the world server's load
path, which is being converted separately.

Refs #1332

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 18:42:13 -05:00
parent 66fa18eef0
commit 112b0e723c
2 changed files with 45 additions and 18 deletions

View File

@@ -488,6 +488,14 @@ private:
*/
LWOOBJID m_ObjectID{ LWOOBJID_EMPTY };
/**
* Gets a child of the root obj tag of the character xml, or nullptr if either is missing.
*/
tinyxml2::XMLElement* GetXmlObjChild(const char* name) {
auto* const obj = m_Doc.FirstChildElement("obj");
return obj ? obj->FirstChildElement(name) : nullptr;
}
/**
* The user that owns this character.
*/