mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
Every game message still written or read by hand is now a NetGameMsg with Serialize and Deserialize, in per-domain files: - MovementMessages: teleport, platforms (resync and its request), orient to angle, node rotation lock, gravity scale, jetpack mode, control scheme, respawn checkpoint, rails (set/start, ready, cancel, arrived), mount inventory ID, dismount complete, possession ack, ghost reference override and position, camera cycling (eCameraTargetCyclingMode moves here). - ZoneMessages: player loaded (the old PLAYER_LOADED case), ready for updates, player ready, restore to post load stats, server done loading, invalid zone transfer list, zone summary display/dismissed, level processing complete, object world state, and the localized announcement WorldMigration wrote by hand. - PlayerMessages: chat mode, GM level, LEGO score, currency, reputation, GM invis, pickup currency, zone and player statistics, chat commands, bug reports, verify ack. - ObjectMessages: fire event client/server side, notify client (zone) object, notify object, script network vars, failed preconditions, terminate interaction, set name, request use, request server object info. - QuickBuildMessages: notify state, enable, cancel. - ActivityMessages gains match response/update/request, leaderboard request and data, shooting gallery score/rotation/fire, activity state change. - MissionMessages gains MissionDialogueCancelled (a no-op, as before). The wire structs left in GameMessages.h move to their domains (tooltip and emote to Effects, loot and item use to Inventory, model build to Building, behavior sound to Property, skill sets to Skill) and gain the missing direction. The dismount logic moves to PossessorComponent::OnDismountComplete. Every inbound message is registered in the GameMessageHandler map; the switch is gone, and GameMessages.cpp only holds the GameMsg/NetGameMsg base code. Call sites build the structs (NotifyClientObject, TerminateInteraction, Teleport, PlatformResync, FireEventClientSide, NotifyObject and NotifyClientZoneObject get convenience constructors like PlayFXEffect). Dead senders are dropped: SendSetShootingGalleryParams (no callers, field order was a guess), SendTeamPickupItem (the struct already existed), SendRequestActivitySummaryLeaderboardData (the struct covers it). Verified with RemainingMessagesTests: every old Send* function is frozen verbatim in Legacy/RemainingMessagesLegacy.h and compared byte for byte (same bits, destination and broadcast flag) over grids of inputs; every old Handle* read sequence is frozen as a Read* oracle and compared with the struct's Deserialize; round trips, truncation and a golden packet. PlayerLoaded (0x00dc36f0), SetGMLevel (0x00dd6230), MissionDialogueCancelled (0x00d9cc10) and LocalizedAnnouncementServerToSingleClient (0x00f23c50) were checked against the client. Behaviour notes: an inbound message that fails to deserialize is dropped, so ParseChatMessage over MAX_MESSAGE_LENGTH is dropped instead of truncated, and PLAYER_LOADED / READY_FOR_UPDATES / MISSION_DIALOGUE_CANCELLED now read their (unused) client fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
4.6 KiB
C++
109 lines
4.6 KiB
C++
#include "NtFactionSpyServer.h"
|
|
#include "Character.h"
|
|
#include "ProximityMonitorComponent.h"
|
|
#include "InventoryComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "EffectsMessages.h"
|
|
#include "ObjectMessages.h"
|
|
#include "MissionComponent.h"
|
|
#include "eMissionState.h"
|
|
#include "eReplicaComponentType.h"
|
|
#include "eCinematicEvent.h"
|
|
#include "ePlayerFlag.h"
|
|
|
|
void NtFactionSpyServer::OnStartup(Entity* self) {
|
|
SetVariables(self);
|
|
|
|
// Set the proximity to sense later
|
|
auto* proximityMonitor = self->GetComponent<ProximityMonitorComponent>();
|
|
if (proximityMonitor == nullptr) {
|
|
proximityMonitor = self->AddComponent<ProximityMonitorComponent>(-1, -1, -1);
|
|
}
|
|
|
|
proximityMonitor->SetProximityRadius(self->GetVar<float_t>(m_SpyProximityVariable), m_ProximityName);
|
|
}
|
|
|
|
void NtFactionSpyServer::SetVariables(Entity* self) {
|
|
self->SetVar<float_t>(m_SpyProximityVariable, 0.0f);
|
|
self->SetVar<SpyData>(m_SpyDataVariable, {});
|
|
self->SetVar<std::vector<SpyDialogue>>(m_SpyDialogueTableVariable, {});
|
|
|
|
// If there's an alternating conversation, indices should be provided using the conversationID variables
|
|
self->SetVar<std::vector<LWOOBJID>>(m_SpyCinematicObjectsVariable, { self->GetObjectID() });
|
|
}
|
|
|
|
void NtFactionSpyServer::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
|
|
if (name == m_ProximityName && status == "ENTER" && IsSpy(self, entering)) {
|
|
auto cinematic = self->GetVar<std::u16string>(m_SpyCinematicVariable);
|
|
if (!cinematic.empty()) {
|
|
|
|
// Save the root of this cinematic so we can identify updates later
|
|
auto cinematicSplit = GeneralUtils::SplitString(cinematic, u'_');
|
|
if (!cinematicSplit.empty()) {
|
|
self->SetVar<std::u16string>(m_CinematicRootVariable, cinematicSplit.at(0));
|
|
}
|
|
|
|
GameMessages::PlayCinematic playCinematic;
|
|
playCinematic.target = entering->GetObjectID();
|
|
playCinematic.pathName = cinematic;
|
|
playCinematic.allowGhostUpdates = true;
|
|
playCinematic.bCloseMultiInteract = true;
|
|
playCinematic.bSendServerNotify = true;
|
|
playCinematic.Send(entering->GetSystemAddress());
|
|
}
|
|
}
|
|
}
|
|
|
|
bool NtFactionSpyServer::IsSpy(Entity* self, Entity* possibleSpy) {
|
|
auto spyData = self->GetVar<SpyData>(m_SpyDataVariable);
|
|
if (!spyData.missionID || !spyData.flagID || !spyData.itemID)
|
|
return false;
|
|
|
|
auto* missionComponent = possibleSpy->GetComponent<MissionComponent>();
|
|
auto* inventoryComponent = possibleSpy->GetComponent<InventoryComponent>();
|
|
auto* character = possibleSpy->GetCharacter();
|
|
|
|
// A player is a spy if they have the spy mission, have the spy equipment equipped and don't have the spy flag set yet
|
|
return missionComponent != nullptr && missionComponent->GetMissionState(spyData.missionID) == eMissionState::ACTIVE
|
|
&& inventoryComponent != nullptr && inventoryComponent->IsEquipped(spyData.itemID)
|
|
&& character != nullptr && !character->GetPlayerFlag(spyData.flagID);
|
|
}
|
|
|
|
void NtFactionSpyServer::OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent event,
|
|
const std::u16string& pathName, float_t pathTime, float_t totalTime,
|
|
int32_t waypoint) {
|
|
|
|
const auto& cinematicRoot = self->GetVar<std::u16string>(m_CinematicRootVariable);
|
|
auto pathNameCopy = std::u16string(pathName); // Mutable copy
|
|
auto pathSplit = GeneralUtils::SplitString(pathNameCopy, u'_');
|
|
|
|
// Make sure we have a path of type <root>_<index>
|
|
if (pathSplit.size() >= 2) {
|
|
auto pathRoot = pathSplit.at(0);
|
|
auto pathIndex = GeneralUtils::TryParse(GeneralUtils::UTF16ToWTF8(pathSplit.at(1)), -1) - 1;
|
|
const auto& dialogueTable = self->GetVar<std::vector<SpyDialogue>>(m_SpyDialogueTableVariable);
|
|
|
|
// Make sure we're listening to the root we're interested in
|
|
if (pathRoot == cinematicRoot) {
|
|
if (event == eCinematicEvent::STARTED && pathIndex >= 0 && pathIndex < dialogueTable.size()) {
|
|
|
|
// If the cinematic started, show part of the conversation
|
|
GameMessages::NotifyClientObject(self->GetObjectID(), m_SpyDialogueNotification, 0, 0, ParamObjectForConversationID(self, dialogueTable.at(pathIndex).conversationID), dialogueTable.at(pathIndex).token).Send(sender->GetSystemAddress());
|
|
|
|
} else if (event == eCinematicEvent::ENDED && pathIndex >= dialogueTable.size() - 1) {
|
|
auto spyData = self->GetVar<SpyData>(m_SpyDataVariable);
|
|
auto* character = sender->GetCharacter();
|
|
if (character != nullptr) {
|
|
character->SetPlayerFlag(spyData.flagID, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
LWOOBJID NtFactionSpyServer::ParamObjectForConversationID(Entity* self, uint32_t conversationID) {
|
|
auto paramObjects = self->GetVar<std::vector<LWOOBJID>>(m_SpyCinematicObjectsVariable);
|
|
auto index = conversationID >= paramObjects.size() ? paramObjects.size() - 1 : conversationID;
|
|
return paramObjects.at(index);
|
|
}
|