4#include <igameevents.h>
14#include <engine2/igameeventsystem.h>
15#include <networksystem/inetworkmessages.h>
16#include <recipientfilter.h>
17#include <shareddefs.h>
18#include <usermessages.pb.h>
26 std::string_view prefix =
27 (!message.empty() &&
static_cast<unsigned char>(message.front()) <= 0x10)
32 out.reserve(prefix.size() + message.size());
48 return HUD_PRINTCENTER;
50 return HUD_PRINTALERT;
57 : _interfaces(interfaces), _events(events), _translations(translations)
62 if (!_interfaces.GameEventSystem)
64 return std::unexpected(
Error::NotReady(
"IGameEventSystem not available"));
67 if (!_interfaces.NetworkMessages)
69 return std::unexpected(
Error::NotReady(
"INetworkMessages not available"));
76 auto* gameEventManager = _interfaces.GameEventManager;
88 pEvent->SetString(
"loc_token", html.c_str());
89 pEvent->SetInt(
"userid", slot);
90 pEvent->SetInt(
"duration", 5);
93 if (IGameEventListener2* listener = _events.GetClientLegacyListener(slot))
95 listener->FireGameEvent(pEvent);
96 gameEventManager->FreeEvent(pEvent);
100 gameEventManager->FireEvent(pEvent);
116 auto rendered =
Render(message, kind);
123 if (_events.GetClientLegacyListener(slot))
132 CRecipientFilter filter;
133 filter.AddAllPlayers();
134 filter.MakeReliable();
141 Send(slot, _translations.Get(key, slot, tokens), kind);
148 if (_events.GetClientLegacyListener(slot))
150 SendKey(slot, key, tokens, kind);
155void Messages::SendTextMsg(
int slot,
int destination,
const std::string& message)
162 CReliableSingleUserRecipientFilter filter(slot);
163 PostTextMsg(filter, destination, message);
166void Messages::PostTextMsg(IRecipientFilter& filter,
int destination,
const std::string& message)
169 PostUserMessage(_interfaces, _textMsgType,
"TextMsg", filter, [&](CNetMessage* raw) {
170 auto* textMsg = raw->ToPB<CUserMessageTextMsg>();
175 textMsg->set_dest(destination);
176 textMsg->add_param(message.c_str());
183 CReliableSingleUserRecipientFilter filter(slot);
184 PostUserMessage(_interfaces, _shakeType,
"Shake", filter, [&](CNetMessage* raw) {
185 auto* shake = raw->ToPB<CUserMessageShake>();
190 shake->set_duration(durationSec);
191 shake->set_frequency(frequency);
192 shake->set_amplitude(amplitude);
193 shake->set_command(0);
Creates, fires and listens to game events.
void BroadcastKey(std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
void ClearCenterHtml(int slot)
void SendCenterHtml(int slot, const std::string &html)
void Send(int slot, std::string_view message, MessageKind kind=MessageKind::Chat)
void Broadcast(std::string_view message, MessageKind kind=MessageKind::Chat)
Messages(Interfaces &interfaces, GameEvents &events, Translations &translations)
void SendKey(int slot, std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
void Shake(int slot, float durationSec, float frequency, float amplitude)
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
constexpr std::string_view Default
@ Center
Plain center-screen print.
@ Chat
Chat box line (color escapes honored).
@ CenterHtml
Center HTML panel (same channel the menu system renders into).
@ Alert
Top-center alert bar.
bool PostUserMessage(Interfaces &interfaces, NetMessageInfo_t *&cached, std::string_view partialName, IRecipientFilter &filter, const std::function< bool(CNetMessage *)> &fill)
static std::string EnsureColorPrefix(std::string_view message)
std::expected< void, Error > Status
constexpr bool IsValidSlot(int slot)
std::map< std::string, std::string > Tokens
static std::string Render(std::string_view message, MessageKind kind)
static int HudDestination(MessageKind kind)
static Error NotReady(std::string detail)
Centralized holder for all SDK interface pointers.
static constexpr std::string_view EventName