VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::PlayerManager Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PlayerManager() [1/2]

VoltMod::PlayerManager::PlayerManager ( SlotEvents &  slots,
EntitySystem *  entities 
)
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.

◆ PlayerManager() [2/2]

VoltMod::PlayerManager::PlayerManager ( const PlayerManager &  )
delete

Member Function Documentation

◆ Add()

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().

◆ All()

std::span< Player *const > VoltMod::PlayerManager::All ( ) const
inline

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().

◆ BySteamId()

Player * VoltMod::PlayerManager::BySteamId ( int64_t  steamId)

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().

◆ Clear()

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().

◆ Get() [1/2]

Player * VoltMod::PlayerManager::Get ( int  slot)

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().

◆ Get() [2/2]

Player * VoltMod::PlayerManager::Get ( PlayerRef  ref)

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().

◆ OnClientFullyConnected()

void VoltMod::PlayerManager::OnClientFullyConnected ( int  slot)

◆ OnClientSettingsChanged()

void VoltMod::PlayerManager::OnClientSettingsChanged ( int  slot)

Definition at line 137 of file PlayerManager.cpp.

References VoltMod::Get, VoltMod::ReadFile(), and SettingsChanged.

◆ operator=()

PlayerManager & VoltMod::PlayerManager::operator= ( const PlayerManager &  )
delete

◆ RefFor()

PlayerRef VoltMod::PlayerManager::RefFor ( int  slot)

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().

◆ Remove()

void VoltMod::PlayerManager::Remove ( int  slot)

Definition at line 90 of file PlayerManager.cpp.

References VoltMod::SlotEvents::Raise(), and VoltMod::ReadFile().

Member Data Documentation

◆ Connected

Event<Player&> VoltMod::PlayerManager::Connected

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().

◆ Connecting

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.

◆ Disconnected

Event<Player&> VoltMod::PlayerManager::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.

Definition at line 74 of file PlayerManager.hpp.

◆ FullyConnected

Event<Player&> VoltMod::PlayerManager::FullyConnected

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().

◆ Said

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.

◆ SettingsChanged

Event<Player&> VoltMod::PlayerManager::SettingsChanged

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().


The documentation for this class was generated from the following files: