VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
CenterHtml.cpp
Go to the documentation of this file.
5#include <utility>
6
7namespace VoltMod
8{
9
13
14void CenterHtml::Show(int slot, int refreshMs, std::function<std::string(int slot)> render)
15{
16 if (!IsValidSlot(slot) || !render || refreshMs <= 0)
17 {
18 return;
19 }
20
21 Stop(slot);
22
23 // _timers cancels it before `this` goes.
24 auto send = [this, slot, render = std::move(render)]() { _messages.SendCenterHtml(slot, render(slot)); };
25 send();
26 _timers[slot] = _scheduler.Repeat(refreshMs, send);
27}
28
30{
31 if (!IsValidSlot(slot) || !_timers[slot])
32 {
33 return;
34 }
35 _timers[slot].Reset();
36 _messages.ClearCenterHtml(slot);
37}
38
40{
41 for (int slot = 0; slot < MaxPlayers; ++slot)
42 {
43 Stop(slot);
44 }
45}
46
47} // namespace VoltMod
CenterHtml(Messages &messages, Scheduler &scheduler, SlotEvents &slots)
void Show(int slot, int refreshMs, std::function< std::string(int slot)> render)
void Stop(int slot)
Send chat, center print, center HTML, and alert messages.
Definition Messages.hpp:30
void ClearCenterHtml(int slot)
Definition Messages.cpp:201
void SendCenterHtml(int slot, const std::string &html)
Definition Messages.cpp:75
One-shot delays and repeating timers, run on the game thread.
Definition Scheduler.hpp:18
Subscription Repeat(int64_t intervalMs, std::function< void()> callback)
Definition Scheduler.cpp:25
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
constexpr int MaxPlayers
Definition Slot.hpp:7