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. */
33 Messages(Interfaces& interfaces, GameEvents& events, Translations& translations);
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 NetMessageInfo_t* _textMsgType = nullptr;
73 NetMessageInfo_t* _shakeType = nullptr;
74};
75
76} // namespace VoltMod
Shows a center-HTML panel until stopped. render runs every refresh, so live values stay current; a pa...
Creates, fires and listens to game events.
void BroadcastKey(std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:144
Status Available() const
Definition Messages.cpp:60
void ClearCenterHtml(int slot)
Definition Messages.cpp:198
void SendCenterHtml(int slot, const std::string &html)
Definition Messages.cpp:74
void Send(int slot, std::string_view message, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:103
Messages(const Messages &)=delete
void Broadcast(std::string_view message, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:114
Messages(Interfaces &interfaces, GameEvents &events, Translations &translations)
Definition Messages.cpp:56
void SendKey(int slot, std::string_view key, const Tokens &tokens={}, MessageKind kind=MessageKind::Chat)
Definition Messages.cpp:139
void Shake(int slot, float durationSec, float frequency, float amplitude)
Definition Messages.cpp:181
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.
Definition Messages.hpp:18
@ Chat
Chat box line (color escapes honored).
Definition Messages.hpp:17
@ Alert
Top-center alert bar.
Definition Messages.hpp:20
std::expected< void, Error > Status
Definition Result.hpp:67
std::map< std::string, std::string > Tokens
Definition Strings.hpp:14
Centralized holder for all SDK interface pointers.