mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
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>
102 lines
3.3 KiB
C++
102 lines
3.3 KiB
C++
#include "DashboardNotify.h"
|
|
#include "MasterPackets.h"
|
|
|
|
#include <chrono>
|
|
#include <set>
|
|
|
|
#include "BitStreamUtils.h"
|
|
#include "master/DataChanged.h"
|
|
#include "Game.h"
|
|
#include "dServer.h"
|
|
#include "MessageType/Master.h"
|
|
#include "ServiceType.h"
|
|
#include "master/DashboardMessages.h"
|
|
#include "PlayerManager.h"
|
|
#include "Entity.h"
|
|
#include "Character.h"
|
|
#include "dZoneManager.h"
|
|
#include "GameMessages.h"
|
|
#include "EffectsMessages.h"
|
|
#include "ChatPackets.h"
|
|
#include "Amf3.h"
|
|
#include "GeneralUtils.h"
|
|
|
|
namespace {
|
|
constexpr auto SEND_INTERVAL = std::chrono::milliseconds(500);
|
|
constexpr auto POSITION_INTERVAL = std::chrono::seconds(1);
|
|
std::chrono::steady_clock::time_point g_LastPositions{};
|
|
bool g_HadPlayers = false;
|
|
std::set<std::pair<std::string, LWOOBJID>> g_Pending;
|
|
std::chrono::steady_clock::time_point g_LastSend{};
|
|
}
|
|
|
|
namespace DashboardNotify {
|
|
void Changed(const std::string& table, LWOOBJID id) {
|
|
if (g_Pending.size() >= DataChanged::MAX_ENTRIES) return; // a burst this big reaches the dashboard's own check anyway
|
|
g_Pending.emplace(table, id);
|
|
}
|
|
|
|
void Flush(bool force) {
|
|
if (g_Pending.empty() || !Game::server) return;
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (!force && now - g_LastSend < SEND_INTERVAL) return;
|
|
g_LastSend = now;
|
|
|
|
DataChanged message;
|
|
for (const auto& [table, id] : g_Pending) message.entries.push_back({ table, id });
|
|
g_Pending.clear();
|
|
|
|
MasterPackets::SendToMaster(message);
|
|
}
|
|
}
|
|
|
|
namespace DashboardNotify {
|
|
void SendPlayerPositions(uint32_t instanceId) {
|
|
if (!Game::server || !Game::zoneManager) return;
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (now - g_LastPositions < POSITION_INTERVAL) return;
|
|
g_LastPositions = now;
|
|
|
|
const auto& players = PlayerManager::GetAllPlayers();
|
|
// Once more after the last player leaves, so the dashboard clears this world
|
|
if (players.empty() && !g_HadPlayers) return;
|
|
g_HadPlayers = !players.empty();
|
|
|
|
PlayerPositions message;
|
|
const auto zone = Game::zoneManager->GetZoneID();
|
|
message.zoneId = zone.GetMapID();
|
|
message.instanceId = instanceId;
|
|
message.cloneId = zone.GetCloneID();
|
|
for (const auto* player : players) {
|
|
const auto* character = player ? player->GetCharacter() : nullptr;
|
|
if (!character) continue;
|
|
const auto position = player->GetPosition();
|
|
message.players.push_back({ character->GetID(), position.x, position.y, position.z });
|
|
}
|
|
|
|
MasterPackets::SendToMaster(message);
|
|
}
|
|
|
|
std::string ChatLine(const std::string& title, const std::string& message) {
|
|
if (title.empty()) return message;
|
|
const char last = title.back();
|
|
const bool punctuated = last == '!' || last == '?' || last == '.' || last == ':';
|
|
return title + (punctuated ? " " : ": ") + message;
|
|
}
|
|
|
|
void Announce(const std::string& title, const std::string& message) {
|
|
AMFArrayValue args;
|
|
args.Insert("title", title);
|
|
args.Insert("message", message);
|
|
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()) {
|
|
if (player) ChatPackets::SendSystemMessage(player->GetSystemAddress(), text);
|
|
}
|
|
}
|
|
}
|