|
VoltMod
C++23 framework for CS2 server plugins
|
The roster: every connected player, and the signals for the connection lifecycle. More...
#include <PlayerManager.hpp>
Public Member Functions | |
| PlayerManager (SlotEvents &slots, EntitySystem *entities) | |
| PlayerManager (const PlayerManager &)=delete | |
| PlayerManager & | operator= (const PlayerManager &)=delete |
| Player * | Get (int slot) |
| Player * | Get (PlayerRef ref) |
| Player * | BySteamId (int64_t steamId) |
| std::span< Player *const > | All () const |
| PlayerRef | RefFor (int slot) |
| Player * | Add (int slot, int64_t steamId, std::string name, std::string ip) |
| void | Remove (int slot) |
| void | Clear () |
| void | OnClientFullyConnected (int slot) |
| void | OnClientSettingsChanged (int slot) |
Public Attributes | |
| Event< ConnectRequest & > | Connecting |
A player is asking to join, before the engine admits them and before they are in the roster. A handler that sets Rejected keeps them out. | |
| Event< Player & > | Connected |
| A player joined and is now in the roster. Their name is not meaningful yet - FullyConnected is the first point it is. | |
| Event< Player & > | Disconnected |
| A player is leaving. Raised while they are still in the roster, so the handler can read their identity and flush whatever it keyed on them; the Player is destroyed immediately afterwards. | |
| Event< Player & > | FullyConnected |
| A player finished connecting (post ClientFullyConnect) - the first point their name and replicated convars mean anything. | |
| Event< Player & > | SettingsChanged |
| A player changed a replicated setting (name, userinfo cvars). Fires on every change, including the ones the engine sends at connect. | |
| Event< ChatMessage & > | Said |
| A player said something in chat that no menu or command took. | |
The roster: every connected player, and the signals for the connection lifecycle.
Main-thread-only (no mutex) - the engine callbacks that drive it and everything that reads it run on the game thread. The framework owns the mutations; plugins look players up and subscribe to its events.
A returned Player* is null when nobody matched, and lives only as long as that connection. Keep a PlayerRef instead of a pointer or a bare slot.
Definition at line 47 of file PlayerManager.hpp.
|
inline |
slots is the Core-level "this slot changed hands" signal this manager raises; subscribe on that feed (runtime.Slots.Changed) rather than here when all you need is to drop per-slot state - it lives in Core precisely so services below Players can hear it. entities builds the wrappers Player::Controller and Player::Pawn return. Null only in the framework's SDK-free unit tests, where there is no engine. Both must outlive the manager.
Definition at line 58 of file PlayerManager.hpp.
|
delete |
| Player * VoltMod::PlayerManager::Add | ( | int | slot, |
| int64_t | steamId, | ||
| std::string | name, | ||
| std::string | ip | ||
| ) |
Definition at line 69 of file PlayerManager.cpp.
References Connected, VoltMod::SlotEvents::Raise(), and VoltMod::ReadFile().
Every connected player, in slot order. Backed by a vector the manager keeps up to date, so this allocates nothing; it is invalidated by the next Add/Remove/Clear, which means a loop over it must not connect or disconnect anybody.
Definition at line 107 of file PlayerManager.hpp.
Referenced by VoltMod::EngineArgBinder::Resolve(), and VoltMod::Vote::Start().
The connected player with this SteamID, or null. Bots are never reachable this way - they all share SteamID 0.
Definition at line 157 of file PlayerManager.cpp.
References VoltMod::ReadFile().
| void VoltMod::PlayerManager::Clear | ( | ) |
Drops everyone, raising Disconnected for each first.
Definition at line 101 of file PlayerManager.cpp.
References VoltMod::SlotEvents::Raise(), and VoltMod::ReadFile().
The player in slot, or null when it is empty.
Definition at line 145 of file PlayerManager.cpp.
References VoltMod::ReadFile().
Referenced by VoltMod::Policy::Authorize(), VoltMod::Policy::AuthorizeSteamId(), and VoltMod::EngineArgBinder::Resolve().
The player ref names: the same slot and the same SteamID. Null when the slot is empty or has changed hands, rather than the wrong player - which is the whole reason a slot captured earlier is stored as a ref. A bot ref (SteamId == 0) only says "a bot is
still in that slot"; no reference can pin one down across a reconnect.
Definition at line 151 of file PlayerManager.cpp.
References VoltMod::Get, and VoltMod::ReadFile().
Definition at line 127 of file PlayerManager.cpp.
References VoltMod::SlotEvents::FullyConnected, FullyConnected, VoltMod::Get, VoltMod::Event< Args >::Raise(), and VoltMod::ReadFile().
Definition at line 137 of file PlayerManager.cpp.
References VoltMod::Get, VoltMod::ReadFile(), and SettingsChanged.
|
delete |
The ref for whoever occupies slot, or an unset ref when it is empty. The way a transient slot - a menu row, an engine callback - becomes a storable identity.
Definition at line 163 of file PlayerManager.cpp.
References VoltMod::Get, and VoltMod::ReadFile().
Definition at line 90 of file PlayerManager.cpp.
References VoltMod::SlotEvents::Raise(), and VoltMod::ReadFile().
A player joined and is now in the roster. Their name is not meaningful yet - FullyConnected is the first point it is.
Definition at line 69 of file PlayerManager.hpp.
Referenced by Add().
| Event<ConnectRequest&> VoltMod::PlayerManager::Connecting |
A player is asking to join, before the engine admits them and before they are in the roster. A handler that sets Rejected keeps them out.
Definition at line 65 of file PlayerManager.hpp.
A player is leaving. Raised while they are still in the roster, so the handler can read their identity and flush whatever it keyed on them; the Player is destroyed immediately afterwards.
Definition at line 74 of file PlayerManager.hpp.
A player finished connecting (post ClientFullyConnect) - the first point their name and replicated convars mean anything.
Definition at line 78 of file PlayerManager.hpp.
Referenced by OnClientFullyConnected().
| Event<ChatMessage&> VoltMod::PlayerManager::Said |
A player said something in chat that no menu or command took.
Definition at line 85 of file PlayerManager.hpp.
A player changed a replicated setting (name, userinfo cvars). Fires on every change, including the ones the engine sends at connect.
Definition at line 82 of file PlayerManager.hpp.
Referenced by OnClientSettingsChanged().