VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Messages.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <string>
9#include <string_view>
10
11namespace VoltMod
12{
13
14/** Where a message renders on the client. */
15enum class MessageKind
16{
17 Chat, ///< Chat box line (color escapes honored).
18 Center, ///< Plain center-screen print.
19 CenterHtml, ///< Center HTML panel (same channel the menu system renders into).
20 Alert, ///< Top-center alert bar.
21};
22
23/**
24 * @brief Send chat, center print, center HTML, and alert messages.
25 *
26 * Chat sends preserve a leading color escape or prepend the default color. `Send` and `Broadcast`
27 * send finished text; `SendKey` and `BroadcastKey` translate a key into each player's language.
28 */
30{
31public:
32 /** @p interfaces, @p events, and @p translations must outlive this service. */
34 Messages(const Messages&) = delete;
35 Messages& operator=(const Messages&) = delete;
36
37 /** NotReady when the engine's event or network message system is missing. */
38 Status Available() const;
39
40 void Send(int slot, std::string_view message, MessageKind kind = MessageKind::Chat);
41
42 /** Broadcast to connected human players. */
43 void Broadcast(std::string_view message, MessageKind kind = MessageKind::Chat);
44
45 /** Translate @p key into @p slot's language, substitute @p tokens, and send it. */
46 void SendKey(int slot, std::string_view key, const Tokens& tokens = {}, MessageKind kind = MessageKind::Chat);
47
48 /** `SendKey` to every connected client, each in their own language. */
49 void BroadcastKey(std::string_view key, const Tokens& tokens = {}, MessageKind kind = MessageKind::Chat);
50
51 /**
52 * Shake @p slot's screen, the engine's own CUserMessageShake.
53 *
54 * @param slot Recipient player slot.
55 * @param durationSec how long the shake lasts.
56 * @param frequency oscillations per second; higher reads as a rattle, lower as a sway.
57 * @param amplitude how far the view is thrown.
58 */
59 void Shake(int slot, float durationSec, float frequency, float amplitude);
60
61 /** Write a raw center-HTML panel. Menus and @ref CenterHtml use this path. */
62 void SendCenterHtml(int slot, const std::string& html);
63 void ClearCenterHtml(int slot);
64
65private:
66 void SendTextMsg(int slot, int destination, const std::string& message);
67 void PostTextMsg(IRecipientFilter& filter, int destination, const std::string& message);
68
69 Interfaces& _interfaces;
70 GameEvents& _events;
71 Translations& _translations;
72 INetworkMessageInternal* _textMsgInternal = nullptr;
73 INetworkMessageInternal* _shakeInternal = nullptr;
74};
75
76} // namespace VoltMod
Re-sends a center-HTML panel until stopped, since CS2 drops center HTML on death, a team switch and H...
Creates, fires and listens to game events.
Send chat, center print, center HTML, and alert messages.
Definition Messages.hpp:30
void BroadcastKey(std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:147
Status Available() const
Definition Messages.cpp:61
void ClearCenterHtml(int slot)
Definition Messages.cpp:201
void SendCenterHtml(int slot, const std::string &html)
Definition Messages.cpp:75
Messages(const Messages &)=delete
void Broadcast(std::string_view message, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:115
void SendKey(int slot, std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:142
void Shake(int slot, float durationSec, float frequency, float amplitude)
Definition Messages.cpp:184
Messages & operator=(const Messages &)=delete
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
@ Center
Plain center-screen print.
@ Chat
Chat box line (color escapes honored).
@ Alert
Top-center alert bar.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
std::map< std::string, std::string > Tokens
Definition Strings.hpp:14
@ Send
point the client at AddonDecision::Id and wait for its reconnect
Centralized holder for all HL2SDK interface pointers.