feat(missions): keep and save the mission journal type states

The client sends SetMissionTypeState (851) for the journal's mission
types and subtypes (Missions.defined_type / defined_subtype) at load and
after mission updates: 650 live packets, every one with the optional
state left at NEW, the subtype written before the type. DLU
dropped it and never wrote the states, so the client lost them on every
load.

- SetMissionTypeState message struct and handler: the state is stored on
  the player's MissionComponent (byte-sized as the client keeps it,
  LWOMissionComponent::msgSetMissionTypeState 0x00c90d00).
- Saved as live wrote it (226 live charxmls): after <cur>,
  <ts><type v="Build"><st sub="" val="1"/></type>...</ts>, <ts/> when
  empty. Read back per <type>; old saves without <ts> load with none.
  The client's reader (0x00d171c0) reads v from <ts> rather than from
  each <type>, so it files every state under one type; the server keeps
  the types apart.
- Mission::SetMissionTypeState (on accept) records NEW for the mission's
  type instead of doing nothing.

Check in game: accept missions of a few kinds (a location mission, a
battle achievement), open the passport/journal, then log out and back in
and change zones: the journal tabs keep their "new" markers as before,
nothing errors, and the character still loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 03:02:47 -05:00
parent cba2a36dc4
commit 70df41ae8d
10 changed files with 232 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ set(DCOMPONENTS_TESTS
"PetComponentTests.cpp"
"SimplePhysicsComponentTests.cpp"
"SavingTests.cpp"
"CharacterSaveFieldsTests.cpp"
"ReplicaComponentOrderTests.cpp"
)

View File

@@ -0,0 +1,74 @@
// Charxml fields the client reads on load that DLU now saves. The formats are the ones live wrote (2011/2012 live
// captures of the charxml the world server sent) and the client reads (legouniverse.exe 1.10.64).
#include "GameDependencies.h"
#include "CDClientDatabase.h"
#include "Entity.h"
#include "GameMessages.h"
#include "MissionComponent.h"
#include "eMissionLockState.h"
#include "tinyxml2.h"
#include <string>
#include <gtest/gtest.h>
namespace {
std::string Print(const tinyxml2::XMLDocument& doc) {
tinyxml2::XMLPrinter printer(nullptr, true);
doc.Print(&printer);
return printer.CStr();
}
void Parse(tinyxml2::XMLDocument& doc, const std::string& xml) {
ASSERT_EQ(doc.Parse(xml.c_str()), tinyxml2::XML_SUCCESS);
}
}
class CharacterSaveFieldsTests : public GameDependenciesTest {
protected:
void SetUp() override {
SetUpDependencies();
CDClientDatabase::Connect(":memory:"); // MissionComponent counts the achievements
CDClientDatabase::ExecuteDML("CREATE TABLE Missions (id INTEGER, isMission INTEGER);");
}
void TearDown() override { TearDownDependencies(); }
};
// <mis><ts>: the states of the mission journal tabs, written after <cur> the way live wrote them.
TEST_F(CharacterSaveFieldsTests, MissionTypeStatesRoundTrip) {
tinyxml2::XMLDocument doc;
Parse(doc, R"(<obj v="1"><mis><done/><cur/><ts><type v="Build"><st sub="" val="1"/></type><type v="Location"><st sub="Avant Gardens" val="1"/><st sub="Nimbus Station" val="2"/></type></ts></mis></obj>)");
Entity player(20, info);
auto* const missions = player.AddComponent<MissionComponent>(-1);
missions->LoadFromXml(doc);
const auto& states = missions->GetMissionTypeStates();
ASSERT_EQ(states.size(), 2);
EXPECT_EQ(states.at("Build").at(""), eMissionLockState::NEW);
EXPECT_EQ(states.at("Location").at("Avant Gardens"), eMissionLockState::NEW);
EXPECT_EQ(states.at("Location").at("Nimbus Station"), eMissionLockState::UNLOCKED);
missions->SetMissionTypeState("Battle", "General", eMissionLockState::NEW);
missions->UpdateXml(doc);
EXPECT_EQ(Print(doc), R"(<obj v="1"><mis><done/><cur/><ts><type v="Battle"><st sub="General" val="1"/></type><type v="Build"><st sub="" val="1"/></type><type v="Location"><st sub="Avant Gardens" val="1"/><st sub="Nimbus Station" val="2"/></type></ts></mis></obj>)");
Entity reloaded(21, info);
auto* const reloadedMissions = reloaded.AddComponent<MissionComponent>(-1);
reloadedMissions->LoadFromXml(doc);
EXPECT_EQ(reloadedMissions->GetMissionTypeStates(), states);
}
// Saves from before <ts> was written load with no states and gain an empty <ts>.
TEST_F(CharacterSaveFieldsTests, MissionTypeStatesMissingInOldSave) {
tinyxml2::XMLDocument doc;
Parse(doc, R"(<obj v="1"><mis><done/><cur/></mis></obj>)");
Entity player(22, info);
auto* const missions = player.AddComponent<MissionComponent>(-1);
missions->LoadFromXml(doc);
EXPECT_TRUE(missions->GetMissionTypeStates().empty());
missions->UpdateXml(doc);
EXPECT_EQ(Print(doc), R"(<obj v="1"><mis><done/><cur/><ts/></mis></obj>)");
}