Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::server::PlayerSystem Class Reference

System to handle player-related operations on the server side. More...

#include <PlayerSystem.hpp>

Inheritance diagram for rtp::server::PlayerSystem:
Collaboration diagram for rtp::server::PlayerSystem:

Public Member Functions

 PlayerSystem (ServerNetwork &network, ecs::Registry &registry)
 Constructor for PlayerSystem.
 
void update (float dt) override
 Update system logic for one frame.
 
PlayerPtr createPlayer (uint32_t sessionId, const std::string &username)
 Create a new player for the given session ID.
 
uint32_t removePlayer (uint32_t sessionId)
 Remove a player by their session ID.
 
void updatePlayerUsername (uint32_t sessionId, const std::string &username)
 Update the username of a player.
 
PlayerPtr getPlayer (uint32_t sessionId) const
 Get a player by their session ID.
 
PlayerPtr getPlayerByUsername (const std::string &username) const
 Get a player by their username.
 
- Public Member Functions inherited from rtp::ecs::ISystem
virtual ~ISystem () noexcept=default
 

Private Attributes

ServerNetwork_network
 Reference to the server network manager.
 
ecs::Registry_registry
 Reference to the entity registry.
 
std::map< uint32_t, PlayerPtr_players
 Map of session ID to Player instances.
 

Detailed Description

System to handle player-related operations on the server side.

Definition at line 27 of file PlayerSystem.hpp.

Constructor & Destructor Documentation

◆ PlayerSystem()

rtp::server::PlayerSystem::PlayerSystem ( ServerNetwork network,
ecs::Registry registry 
)

Constructor for PlayerSystem.

Parameters
networkReference to the server network manager
registryReference to the entity registry

Definition at line 15 of file PlayerSystem.cpp.

Member Function Documentation

◆ createPlayer()

PlayerPtr rtp::server::PlayerSystem::createPlayer ( uint32_t  sessionId,
const std::string &  username 
)

Create a new player for the given session ID.

Parameters
sessionIdID of the network session
usernameUsername of the player

Definition at line 23 of file PlayerSystem.cpp.

References _players, rtp::log::info(), and rtp::log::warning().

◆ getPlayer()

PlayerPtr rtp::server::PlayerSystem::getPlayer ( uint32_t  sessionId) const

Get a player by their session ID.

Parameters
sessionIdID of the network session
Returns
Shared pointer to the Player, or nullptr if not found

Definition at line 58 of file PlayerSystem.cpp.

References _players.

◆ getPlayerByUsername()

PlayerPtr rtp::server::PlayerSystem::getPlayerByUsername ( const std::string &  username) const

Get a player by their username.

Parameters
usernameUsername to look up
Returns
Shared pointer to the Player, or nullptr if not found

Definition at line 67 of file PlayerSystem.cpp.

References _players.

◆ removePlayer()

uint32_t rtp::server::PlayerSystem::removePlayer ( uint32_t  sessionId)

Remove a player by their session ID.

Parameters
sessionIdID of the network session
Returns
The entity ID associated with the removed player, or 0 if not found

Definition at line 36 of file PlayerSystem.cpp.

References _players, and rtp::log::info().

◆ update()

void rtp::server::PlayerSystem::update ( float  dt)
overridevirtual

Update system logic for one frame.

Parameters
dtTime elapsed since last update in seconds
Note
Currently not used

Implements rtp::ecs::ISystem.

Definition at line 18 of file PlayerSystem.cpp.

◆ updatePlayerUsername()

void rtp::server::PlayerSystem::updatePlayerUsername ( uint32_t  sessionId,
const std::string &  username 
)

Update the username of a player.

Parameters
sessionIdID of the network session
usernameNew username of the player

Definition at line 49 of file PlayerSystem.cpp.

References _players, and rtp::log::info().

Member Data Documentation

◆ _network

ServerNetwork& rtp::server::PlayerSystem::_network
private

Reference to the server network manager.

Definition at line 79 of file PlayerSystem.hpp.

◆ _players

std::map<uint32_t, PlayerPtr> rtp::server::PlayerSystem::_players
private

Map of session ID to Player instances.

Definition at line 83 of file PlayerSystem.hpp.

Referenced by createPlayer(), getPlayer(), getPlayerByUsername(), removePlayer(), and updatePlayerUsername().

◆ _registry

ecs::Registry& rtp::server::PlayerSystem::_registry
private

Reference to the entity registry.

Definition at line 80 of file PlayerSystem.hpp.


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