refactor: effects, audio, animation and UI text game messages as structs

Converts PlayAnimation, PlayNDAudioEmitter, PlayEmbeddedEffectOnAllClientsNearObject,
PlayFXEffect, StopFXEffect, BroadcastTextToChatbox, Play2DAmbientSound,
Stop2DAmbientSound, UIMessageServerToSingleClient, UIMessageServerToAllClients,
StartCelebrationEffect, DisplayMessageBox, DisplayChatBubble, ChangeIdleFlags,
SetNameBillboardState, ShowBillboardInteractIcon, PlayCinematic, EndCinematic,
SlashCommandTextFeedback, PlayEmote and SetEmoteLockState (21 old Send
functions, 23 with overloads) and the received MessageBoxRespond,
ChoiceBoxRespond, CinematicUpdate and PlayEmote to NetGameMsgs in
EffectsMessages.{h,cpp}. The high traffic messages get a constructor for their
required fields. UI messages own their AMF arguments. Every caller is switched,
the received messages are registered in GameMessageHandler's map, and the old
functions and switch cases are deleted. Handlers are copied verbatim.

No wire change and no change in recipients: functions that always broadcast
whatever address they were given are sent with Send(UNASSIGNED_SYSTEM_ADDRESS),
functions that only did SEND_PACKET use SendToClient. Quirks are kept and
documented on the structs (PlayAnimation's UTF-8 sized name, the always written
null terminator in BroadcastTextToChatbox, StartCelebrationEffect always
writing celebrationID, SetNameBillboardState having no payload).

Verified byte for byte against a frozen verbatim copy of the old functions over
an input grid, to one client and broadcast; received messages compared with the
old handlers' read sequences and every truncated payload rejected; hand
computed golden bytes; round trips; a deliberate width mutation made the tests
fail. The byte-equality helper gains a Broadcast mode for functions that
ignored their address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 19:06:00 -05:00
parent 5a9a3e380b
commit dae1925d1a
117 changed files with 2832 additions and 1058 deletions

View File

@@ -11,6 +11,7 @@
#include "CharacterComponent.h"
#include "ChatPackets.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "PlayerManager.h"
#include "User.h"
#include "UserManager.h"
@@ -70,7 +71,7 @@ namespace {
GameMessages::ToggleGMInvisEvent msg;
msg.Send(entity->GetObjectID());
}
GameMessages::SendSlashCommandFeedbackText(entity, u"Your game master level has been changed.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Your game master level has been changed.").SendToClient(entity->GetSystemAddress());
LOG("Dashboard lowered GM level of %s to %i", user->GetUsername().c_str(), static_cast<int>(info->maxGmLevel));
}
return static_cast<uint32_t>(users.size());
@@ -96,7 +97,11 @@ namespace {
AMFArrayValue args;
args.Insert("title", std::string("Warning from a moderator"));
args.Insert("message", text);
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "ToggleAnnounce", args);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = player->GetObjectID();
uiMessage.strMessageName = "ToggleAnnounce";
uiMessage.args = std::move(args);
uiMessage.SendToClient(player->GetSystemAddress());
ChatPackets::SendSystemMessage(player->GetSystemAddress(), u"Warning from a moderator: " + GeneralUtils::UTF8ToUTF16(text));
affected++;
}

View File

@@ -16,6 +16,7 @@
#include "Character.h"
#include "dZoneManager.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "ChatPackets.h"
#include "Amf3.h"
#include "GeneralUtils.h"
@@ -87,7 +88,10 @@ namespace DashboardNotify {
AMFArrayValue args;
args.Insert("title", title);
args.Insert("message", message);
GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args);
GameMessages::UIMessageServerToAllClients uiMessage;
uiMessage.strMessageName = "ToggleAnnounce";
uiMessage.args = std::move(args);
uiMessage.Send(UNASSIGNED_SYSTEM_ADDRESS);
// Also in chat, for anyone who closes the popup without reading it
const auto text = GeneralUtils::UTF8ToUTF16(ChatLine(title, message));
for (const auto* player : PlayerManager::GetAllPlayers()) {

View File

@@ -27,6 +27,7 @@
#include "InventoryComponent.h"
#include "DestroyableComponent.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "ChatPackets.h"
#include "DashboardNotify.h"
#include "CDClientManager.h"
@@ -218,7 +219,7 @@ namespace {
const auto itemCount = std::clamp<uint32_t>(event.config.value("itemCount", 1u), 1, 999);
if (auto* inventory = player->GetComponent<InventoryComponent>(); inventory && item > 0) inventory->AddItem(item, itemCount, eLootSourceType::ACTIVITY);
if (const auto effect = event.config.value("foundEffectId", 0); effect > 0) {
GameMessages::SendPlayFXEffect(player->GetObjectID(), effect, GeneralUtils::UTF8ToUTF16(event.config.value("foundEffectType", std::string{})), "live_event_found");
GameMessages::PlayFXEffect(player->GetObjectID(), effect, GeneralUtils::UTF8ToUTF16(event.config.value("foundEffectType", std::string{})), "live_event_found").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
const auto left = std::ranges::count_if(event.treasures, [](const Treasure& t) { return !t.gone; });
TellAll(PlayerName(player) + " found a treasure! " + (left == 0 ? "That was the last one." : std::to_string(left) + " left to find."));
@@ -353,7 +354,7 @@ namespace {
if (effect <= 0) return;
const auto name = "live_event_" + std::to_string(event.row.id);
for (auto* player : PlayerManager::GetAllPlayers()) {
if (player) GameMessages::SendPlayFXEffect(player->GetObjectID(), effect, type, name);
if (player) GameMessages::PlayFXEffect(player->GetObjectID(), effect, type, name).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
event.bursts++;
event.dirty = true;
@@ -458,7 +459,7 @@ namespace {
event.alive.clear();
if (event.type == eEventType::CELEBRATION) {
const auto name = "live_event_" + std::to_string(event.row.id);
for (auto* player : PlayerManager::GetAllPlayers()) if (player) GameMessages::SendStopFXEffect(player, true, name);
for (auto* player : PlayerManager::GetAllPlayers()) if (player) GameMessages::StopFXEffect(player->GetObjectID(), true, name).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
FlushScores(event);
WriteStatus(event, true);

View File

@@ -31,6 +31,7 @@
#include "PlayerManager.h"
#include "User.h"
#include "eObjectBits.h"
#include "EffectsMessages.h"
namespace {
// Each command once, by the first alias it got
@@ -259,7 +260,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity*
}
if (!error.empty()) {
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(error));
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(error)).SendToClient(entity->GetSystemAddress());
}
}
@@ -290,7 +291,7 @@ void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const st
if (page < 1 || page > totalPages) {
feedback << "Invalid page number. Total pages: " << totalPages;
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(feedback.str())).SendToClient(entity->GetSystemAddress());
return;
}
@@ -305,7 +306,7 @@ void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const st
const auto feedbackStr = feedback.str();
if (!feedbackStr.empty()) {
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(feedbackStr)).SendToClient(entity->GetSystemAddress());
}
return;
}
@@ -328,7 +329,7 @@ void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const st
const auto feedbackStr = feedback.str();
if (!feedbackStr.empty()) {
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(feedbackStr)).SendToClient(entity->GetSystemAddress());
}
}
@@ -338,7 +339,10 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::
args.Insert("title", title);
args.Insert("message", message);
GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args);
GameMessages::UIMessageServerToAllClients uiMessage;
uiMessage.strMessageName = "ToggleAnnounce";
uiMessage.args = std::move(args);
uiMessage.Send(UNASSIGNED_SYSTEM_ADDRESS);
//Notify chat about it
ChatPackets::Announcement announcement;

View File

@@ -57,6 +57,7 @@
#include "ePlayerFlag.h"
#include "StringifiedEnum.h"
#include "BinaryPathFinder.h"
#include "EffectsMessages.h"
namespace DEVGMCommands {
void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -64,7 +65,7 @@ namespace DEVGMCommands {
const auto level_intermed = GeneralUtils::TryParse<uint32_t>(args);
if (!level_intermed) {
GameMessages::SendSlashCommandFeedbackText(entity, u"Invalid GM level.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Invalid GM level.").SendToClient(entity->GetSystemAddress());
return;
}
eGameMasterLevel level = static_cast<eGameMasterLevel>(level_intermed.value());
@@ -106,7 +107,7 @@ namespace DEVGMCommands {
GameMessages::ToggleGMInvisEvent msg;
msg.Send(entity->GetObjectID());
GameMessages::SendSlashCommandFeedbackText(entity, u"Your game master level has been changed, you may not be able to use all commands.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Your game master level has been changed, you may not be able to use all commands.").SendToClient(entity->GetSystemAddress());
}
#endif
}
@@ -118,10 +119,10 @@ namespace DEVGMCommands {
auto* character = entity->GetCharacter();
if (character && character->GetBillboardVisible()) {
character->SetBillboardVisible(false);
GameMessages::SendSlashCommandFeedbackText(entity, u"Your nameplate has been turned off and is not visible to players currently in this zone.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Your nameplate has been turned off and is not visible to players currently in this zone.").SendToClient(entity->GetSystemAddress());
} else {
character->SetBillboardVisible(true);
GameMessages::SendSlashCommandFeedbackText(entity, u"Your nameplate is now on and visible to all players.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Your nameplate is now on and visible to all players.").SendToClient(entity->GetSystemAddress());
}
}
@@ -132,9 +133,9 @@ namespace DEVGMCommands {
bool current = character->GetPlayerFlag(ePlayerFlag::DLU_SKIP_CINEMATICS);
character->SetPlayerFlag(ePlayerFlag::DLU_SKIP_CINEMATICS, !current);
if (!current) {
GameMessages::SendSlashCommandFeedbackText(entity, u"You have elected to skip cinematics. Note that not all cinematics can be skipped, but most will be skipped now.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"You have elected to skip cinematics. Note that not all cinematics can be skipped, but most will be skipped now.").SendToClient(entity->GetSystemAddress());
} else {
GameMessages::SendSlashCommandFeedbackText(entity, u"Cinematics will no longer be skipped.");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Cinematics will no longer be skipped.").SendToClient(entity->GetSystemAddress());
}
}
@@ -327,7 +328,11 @@ namespace DEVGMCommands {
uiState.Insert("state", splitArgs[0]);
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, "pushGameState", uiState);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = "pushGameState";
uiMessage.args = std::move(uiState);
uiMessage.SendToClient(sysAddr);
ChatPackets::SendSystemMessage(sysAddr, u"Switched UI state.");
}
@@ -340,7 +345,11 @@ namespace DEVGMCommands {
amfArgs.Insert("visible", true);
GameMessages::SendUIMessageServerToSingleClient(entity, sysAddr, splitArgs[0], amfArgs);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = splitArgs[0];
uiMessage.args = std::move(amfArgs);
uiMessage.SendToClient(sysAddr);
ChatPackets::SendSystemMessage(sysAddr, u"Toggled UI state.");
}
@@ -499,14 +508,14 @@ namespace DEVGMCommands {
if (!effectID) return;
// FIXME: use fallible ASCIIToUTF16 conversion, because non-ascii isn't valid anyway
GameMessages::SendPlayFXEffect(entity->GetObjectID(), effectID.value(), GeneralUtils::ASCIIToUTF16(splitArgs.at(1)), splitArgs.at(2));
GameMessages::PlayFXEffect(entity->GetObjectID(), effectID.value(), GeneralUtils::ASCIIToUTF16(splitArgs.at(1)), splitArgs.at(2)).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
void StopEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.empty()) return;
GameMessages::SendStopFXEffect(entity, true, splitArgs[0]);
GameMessages::StopFXEffect(entity->GetObjectID(), true, splitArgs[0]).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
void SetAnnTitle(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -739,7 +748,10 @@ namespace DEVGMCommands {
return;
}
GameMessages::SendStartCelebrationEffect(entity, entity->GetSystemAddress(), celebration.value());
GameMessages::StartCelebrationEffect celebrationEffect;
celebrationEffect.target = entity->GetObjectID();
celebrationEffect.celebrationID = celebration.value();
celebrationEffect.SendToClient(entity->GetSystemAddress());
}
void BuffMed(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -807,7 +819,10 @@ namespace DEVGMCommands {
for (const auto& [name, lot] : nameToLot) {
auto& entry = nameSort.PushDebug<AMFStringValue>(name) = std::to_string(lot);
}
GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr);
GameMessages::UIMessageServerToAllClients uiMessage;
uiMessage.strMessageName = "ToggleObjectDebugger";
uiMessage.args = std::move(response);
uiMessage.SendToClient(sysAddr);
}
}
@@ -1021,11 +1036,11 @@ namespace DEVGMCommands {
}
void PlayLvlFx(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
GameMessages::SendPlayFXEffect(entity, 7074, u"create", "7074", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
GameMessages::PlayFXEffect(entity->GetObjectID(), 7074, u"create", "7074").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
void PlayRebuildFx(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
GameMessages::SendPlayFXEffect(entity, 230, u"rebuild", "230", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
GameMessages::PlayFXEffect(entity->GetObjectID(), 230, u"rebuild", "230").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
void FreeMoney(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -1354,7 +1369,10 @@ namespace DEVGMCommands {
processInfo.PushDebug<AMFStringValue>("Peak RSS") = std::to_string(static_cast<double>(Metrics::GetPeakRSS()) / 1.024e6) + "MB";
processInfo.PushDebug<AMFStringValue>("Current RSS") = std::to_string(static_cast<double>(Metrics::GetCurrentRSS()) / 1.024e6) + "MB";
processInfo.PushDebug<AMFIntValue>("Process ID") = Metrics::GetProcessID();
GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr);
GameMessages::UIMessageServerToAllClients uiMessage;
uiMessage.strMessageName = "ToggleObjectDebugger";
uiMessage.args = std::move(response);
uiMessage.SendToClient(sysAddr);
}
void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args) {

View File

@@ -21,6 +21,7 @@
#include "MessageType/Chat.h"
#include "eServerDisconnectIdentifiers.h"
#include "eObjectBits.h"
#include "EffectsMessages.h"
namespace GMGreaterThanZeroCommands {
@@ -288,7 +289,7 @@ namespace GMGreaterThanZeroCommands {
void FindPlayer(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
if (args.empty()) {
GameMessages::SendSlashCommandFeedbackText(entity, u"No player Given");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"No player Given").SendToClient(entity->GetSystemAddress());
return;
}
@@ -306,10 +307,10 @@ namespace GMGreaterThanZeroCommands {
auto player = PlayerManager::GetPlayer(args);
if (!player) {
GameMessages::SendSlashCommandFeedbackText(entity, u"Player not found");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Player not found").SendToClient(entity->GetSystemAddress());
return;
}
GameMessages::SendSlashCommandFeedbackText(entity, u"Spectating Player");
GameMessages::SlashCommandTextFeedback(entity->GetObjectID(), u"Spectating Player").SendToClient(entity->GetSystemAddress());
GameMessages::SendForceCameraTargetCycle(entity, false, eCameraTargetCyclingMode::DISALLOW_CYCLING, player->GetObjectID());
}
}

View File

@@ -23,6 +23,7 @@
// Emuns
#include "eGameMasterLevel.h"
#include "EffectsMessages.h"
namespace GMZeroCommands {
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -101,7 +102,11 @@ namespace GMZeroCommands {
args.Insert("state", "Story");
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = "pushGameState";
uiMessage.args = std::move(args);
uiMessage.SendToClient(entity->GetSystemAddress());
}
entity->AddCallbackTimer(0.5f, [customText, entity]() {
@@ -112,7 +117,11 @@ namespace GMZeroCommands {
LOG("Sending %s", customText.c_str());
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = "ToggleStoryBox";
uiMessage.args = std::move(args);
uiMessage.SendToClient(entity->GetSystemAddress());
});
}
@@ -124,7 +133,11 @@ namespace GMZeroCommands {
args.Insert("state", "Story");
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = "pushGameState";
uiMessage.args = std::move(args);
uiMessage.SendToClient(entity->GetSystemAddress());
}
entity->AddCallbackTimer(0.5f, [customText, entity]() {
@@ -135,7 +148,11 @@ namespace GMZeroCommands {
LOG("Sending %s", customText.c_str());
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
GameMessages::UIMessageServerToSingleClient uiMessage;
uiMessage.target = entity->GetObjectID();
uiMessage.strMessageName = "ToggleStoryBox";
uiMessage.args = std::move(args);
uiMessage.SendToClient(entity->GetSystemAddress());
});
}