Files
DarkflameServer/dGame/dGameMessages/ActivityMessages.cpp
Aaron Kimbrell 7fb75f0484 refactor: activity game messages as structs
Converts ActivityEnter, ActivityExit, ActivityStart, ActivityStop,
ActivityPause, StartActivityTime, RequestActivityEnter,
RequestActivityExit and ShowActivityCountdown to NetGameMsgs in
ActivityMessages.{h,cpp}, switches their callers (racing, shooting
gallery, survival, waves, AG course, NT combat challenge) and deletes
the old GameMessages::Send* / HandleRequestActivityExit functions.
REQUEST_ACTIVITY_EXIT is registered in GameMessageHandler's map.

No wire change. Verified by comparing every struct byte for byte with a
frozen verbatim copy of the old functions (tests/.../Legacy) over a
grid of inputs, both to one client and as a broadcast (a temporary test
proved the copy matched production before it was deleted), plus hand
computed golden bytes, round trips and a deliberate field mutation that
made the tests fail. Layouts confirmed against the 1.10.64 client in
Ghidra. Only difference: a broadcast no longer makes
the extra Send(UNASSIGNED, false) that RakNet already rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:35 -05:00

83 lines
2.3 KiB
C++

#include "ActivityMessages.h"
#include "BitStreamUtils.h"
#include "Entity.h"
#include "EntityManager.h"
#include "Game.h"
namespace GameMessages {
void ActivityStop::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(bExit);
bitStream.Write(bUserCancel);
}
bool ActivityStop::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(bExit));
VALIDATE_READ(bitStream.Read(bUserCancel));
return true;
}
void ActivityPause::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(bPause);
}
bool ActivityPause::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(bPause));
return true;
}
void StartActivityTime::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(startTime);
}
bool StartActivityTime::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(startTime));
return true;
}
void RequestActivityEnter::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(bStart);
bitStream.Write(userID);
}
bool RequestActivityEnter::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(bStart));
VALIDATE_READ(bitStream.Read(userID));
return true;
}
void RequestActivityExit::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(bUserCancel);
bitStream.Write(userID);
}
bool RequestActivityExit::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(bUserCancel));
VALIDATE_READ(bitStream.Read(userID));
return true;
}
void RequestActivityExit::Handle(Entity& entity, const SystemAddress& sysAddr) {
if (!bUserCancel) return;
auto* player = Game::entityManager->GetEntity(userID);
if (!player) return;
entity.RequestActivityExit(&entity, userID, bUserCancel);
}
void ShowActivityCountdown::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(bPlayAdditionalSound);
bitStream.Write(bPlayCountdownSound);
BitStreamUtils::WriteLengthPrefixed<uint32_t>(bitStream, sndName);
bitStream.Write(stateToPlaySoundOn);
}
bool ShowActivityCountdown::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(bPlayAdditionalSound));
VALIDATE_READ(bitStream.Read(bPlayCountdownSound));
VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed<uint32_t>(bitStream, sndName));
VALIDATE_READ(bitStream.Read(stateToPlaySoundOn));
return true;
}
}