mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-18 02:32:50 +00:00
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:
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionLockState.h"
|
||||
#include "Logger.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDMissionTasksTable.h"
|
||||
@@ -493,6 +494,21 @@ void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
m_Missions.insert_or_assign(missionId, mission);
|
||||
}
|
||||
}
|
||||
|
||||
// Live wrote <ts><type v="Build"><st sub="" val="1"/></type>...</ts>. The client's loader
|
||||
// (LWOMissionComponent::LoadFromSaveData 0x00d171c0) reads v from <ts> instead of from each <type>, so it files
|
||||
// every state under one type; the server reads each <type> as it was written.
|
||||
m_MissionTypeStates.clear();
|
||||
const auto* const ts = mis->FirstChildElement("ts");
|
||||
if (ts) {
|
||||
for (const auto* type = ts->FirstChildElement("type"); type; type = type->NextSiblingElement("type")) {
|
||||
const char* const typeName = type->Attribute("v");
|
||||
for (const auto* st = type->FirstChildElement("st"); st; st = st->NextSiblingElement("st")) {
|
||||
const char* const subtype = st->Attribute("sub");
|
||||
SetMissionTypeState(typeName ? typeName : "", subtype ? subtype : "", static_cast<eMissionLockState>(st->IntAttribute("val")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -543,11 +559,31 @@ void MissionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
mis->InsertFirstChild(done);
|
||||
mis->InsertEndChild(cur);
|
||||
|
||||
// Live wrote <ts> after <cur>, even when it was empty
|
||||
auto* const ts = doc.NewElement("ts");
|
||||
for (const auto& [type, subtypes] : m_MissionTypeStates) {
|
||||
auto* const typeElement = doc.NewElement("type");
|
||||
typeElement->SetAttribute("v", type.c_str());
|
||||
for (const auto& [subtype, state] : subtypes) {
|
||||
auto* const st = doc.NewElement("st");
|
||||
st->SetAttribute("sub", subtype.c_str());
|
||||
st->SetAttribute("val", static_cast<int32_t>(state));
|
||||
typeElement->LinkEndChild(st);
|
||||
}
|
||||
ts->LinkEndChild(typeElement);
|
||||
}
|
||||
mis->InsertEndChild(ts);
|
||||
|
||||
if (shouldInsertMis) {
|
||||
obj->LinkEndChild(mis);
|
||||
}
|
||||
}
|
||||
|
||||
void MissionComponent::SetMissionTypeState(const std::string& type, const std::string& subtype, const eMissionLockState state) {
|
||||
// The client keeps the state as a byte (LWOMissionComponent::msgSetMissionTypeState 0x00c90d00)
|
||||
m_MissionTypeStates[type][subtype] = static_cast<eMissionLockState>(static_cast<int8_t>(state));
|
||||
}
|
||||
|
||||
void MissionComponent::AddCollectible(int32_t collectibleID) {
|
||||
// Check if this collectible is already in the list
|
||||
if (HasCollectible(collectibleID)) {
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#ifndef MISSIONCOMPONENT_H
|
||||
#define MISSIONCOMPONENT_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "dCommonVars.h"
|
||||
@@ -171,6 +173,12 @@ public:
|
||||
void ResetMission(const int32_t missionId);
|
||||
|
||||
void FixRacingMetaMissions();
|
||||
|
||||
// The journal state of a mission type and subtype (Missions.defined_type / defined_subtype), as the client sets it
|
||||
// with SetMissionTypeState. Saved in the charxml: <mis><ts><type v="type"><st sub="subtype" val="state"/></type></ts>
|
||||
using MissionTypeStates = std::map<std::string, std::map<std::string, eMissionLockState>>;
|
||||
void SetMissionTypeState(const std::string& type, const std::string& subtype, eMissionLockState state);
|
||||
const MissionTypeStates& GetMissionTypeStates() const { return m_MissionTypeStates; }
|
||||
private:
|
||||
bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo);
|
||||
bool OnGetMissionState(GameMessages::GetMissionState& getMissionState);
|
||||
@@ -185,6 +193,8 @@ private:
|
||||
*/
|
||||
std::vector<int32_t> m_Collectibles;
|
||||
|
||||
MissionTypeStates m_MissionTypeStates;
|
||||
|
||||
|
||||
/**
|
||||
* For the given parameters, finds the mission IDs of the achievements that may be unlcoked
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace {
|
||||
{ REQUEST_LINKED_MISSION, []() { return std::make_unique<RequestLinkedMission>(); } },
|
||||
{ SET_FLAG, []() { return std::make_unique<SetFlag>(); } },
|
||||
{ HAS_BEEN_COLLECTED, []() { return std::make_unique<HasBeenCollected>(); } },
|
||||
{ SET_MISSION_TYPE_STATE, []() { return std::make_unique<SetMissionTypeState>(); } },
|
||||
|
||||
// Effects, emotes, cinematics, UI
|
||||
{ PLAY_EMOTE, []() { return std::make_unique<PlayEmote>(); } },
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Character.h"
|
||||
#include "CppScripts.h"
|
||||
#include "dConfig.h"
|
||||
#include "eMissionLockState.h"
|
||||
#include "eMissionState.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include "ePlayerFlag.h"
|
||||
@@ -247,6 +248,26 @@ namespace GameMessages {
|
||||
}
|
||||
}
|
||||
|
||||
SetMissionTypeState::SetMissionTypeState() : NetGameMsg(MessageType::Game::SET_MISSION_TYPE_STATE), state{ eMissionLockState::NEW } {}
|
||||
|
||||
void SetMissionTypeState::Serialize(RakNet::BitStream& bitStream) const {
|
||||
BitStreamUtils::WriteOptional(bitStream, state, eMissionLockState::NEW);
|
||||
BitStreamUtils::WriteLengthPrefixed(bitStream, subtype);
|
||||
BitStreamUtils::WriteLengthPrefixed(bitStream, type);
|
||||
}
|
||||
|
||||
bool SetMissionTypeState::Deserialize(RakNet::BitStream& bitStream) {
|
||||
VALIDATE_READ(BitStreamUtils::ReadOptional(bitStream, state, eMissionLockState::NEW));
|
||||
VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed(bitStream, subtype));
|
||||
VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed(bitStream, type));
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetMissionTypeState::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* const missionComponent = entity.GetComponent<MissionComponent>();
|
||||
if (missionComponent) missionComponent->SetMissionTypeState(type, subtype, state);
|
||||
}
|
||||
|
||||
void NotifyLevelRewards::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(level);
|
||||
bitStream.Write(sendingRewards);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
enum class eMissionState : int;
|
||||
enum class eMissionLockState : int;
|
||||
|
||||
// Game messages for missions, player flags, collectibles and level rewards.
|
||||
// Field names follow the client (legouniverse.exe 1.10.64); fields are listed in wire order.
|
||||
@@ -134,6 +135,20 @@ namespace GameMessages {
|
||||
LWOOBJID playerID{};
|
||||
};
|
||||
|
||||
// Client -> server. LWOMissionComponent sends it when a mission of a journal type/subtype (Missions.defined_type,
|
||||
// defined_subtype) is offered or updated, to mark that journal tab. Every live sample carried the default state
|
||||
// (NEW). The server keeps the states and saves them in the charxml (<mis><ts>), which the client reads on load.
|
||||
struct SetMissionTypeState : public NetGameMsg {
|
||||
SetMissionTypeState();
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
||||
|
||||
eMissionLockState state; // optional, default NEW
|
||||
std::string subtype{};
|
||||
std::string type{};
|
||||
};
|
||||
|
||||
// Server -> client.
|
||||
struct NotifyLevelRewards : public NetGameMsg {
|
||||
NotifyLevelRewards() : NetGameMsg(MessageType::Game::NOTIFY_LEVEL_REWARDS) {}
|
||||
|
||||
@@ -646,7 +646,9 @@ void Mission::SetMissionState(const eMissionState state, const bool sendingRewar
|
||||
}
|
||||
|
||||
void Mission::SetMissionTypeState(eMissionLockState state, const std::string& type, const std::string& subType) {
|
||||
// TODO
|
||||
// The client sends its own SetMissionTypeState for the journal; record the same state here so it is saved
|
||||
// even if the player logs out before the client's message arrives
|
||||
if (m_MissionComponent) m_MissionComponent->SetMissionTypeState(type, subType, state);
|
||||
}
|
||||
|
||||
void Mission::SetCompletions(const uint32_t value) {
|
||||
|
||||
Reference in New Issue
Block a user