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::NetworkSyncSystem Class Reference

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

#include <NetworkSyncSystem.hpp>

Inheritance diagram for rtp::server::NetworkSyncSystem:
Collaboration diagram for rtp::server::NetworkSyncSystem:

Public Member Functions

 NetworkSyncSystem (ServerNetwork &network, ecs::Registry &registry)
 Constructor for NetworkSyncSystem.
 
void update (float dt) override
 Update system logic for one frame.
 
void bindSessionToEntity (uint32_t sessionId, ecs::Entity entity)
 Bind a network session to an entity.
 
void unbindSession (uint32_t sessionId)
 
void handleInput (uint32_t sessionId, const net::Packet &packet)
 Handle input received from a client.
 
void handleDisconnect (uint32_t sessionId)
 Handle disconnection of a client.
 
uint32_t handlePlayerConnection (uint32_t sessionId, const net::Packet &packet)
 Handle new player connection.
 
void sendPacketToEntity (uint32_t entityId, const net::Packet &packet, net::NetworkMode mode)
 Send a packet to the entity associated with the given ID.
 
void sendPacketToSession (uint32_t sessionId, const net::Packet &packet, net::NetworkMode mode)
 Send a packet to a specific session.
 
void sendPacketToSessions (const std::vector< uint32_t > &sessions, const net::Packet &packet, net::NetworkMode mode)
 Send a packet to multiple sessions.
 
- 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::unordered_map< uint32_t, ecs::Entity_sessionToEntity
 Map of session IDs to entities (with generation)
 

Detailed Description

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

Definition at line 35 of file NetworkSyncSystem.hpp.

Constructor & Destructor Documentation

◆ NetworkSyncSystem()

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

Constructor for NetworkSyncSystem.

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

Definition at line 21 of file NetworkSyncSystem.cpp.

Member Function Documentation

◆ bindSessionToEntity()

void rtp::server::NetworkSyncSystem::bindSessionToEntity ( uint32_t  sessionId,
ecs::Entity  entity 
)

Bind a network session to an entity.

Parameters
sessionIdID of the network session
entityThe entity to bind (includes both index and generation)

Definition at line 31 of file NetworkSyncSystem.cpp.

References _sessionToEntity.

◆ handleDisconnect()

void rtp::server::NetworkSyncSystem::handleDisconnect ( uint32_t  sessionId)

Handle disconnection of a client.

Parameters
sessionIdID of the disconnected session

Definition at line 73 of file NetworkSyncSystem.cpp.

References _sessionToEntity, rtp::ecs::Entity::index(), and rtp::log::info().

◆ handleInput()

void rtp::server::NetworkSyncSystem::handleInput ( uint32_t  sessionId,
const net::Packet packet 
)

Handle input received from a client.

Parameters
sessionIdID of the network session
packetPacket containing the input data

Definition at line 42 of file NetworkSyncSystem.cpp.

References _registry, _sessionToEntity, rtp::ecs::Registry::add(), rtp::ecs::Registry::get(), rtp::log::info(), rtp::net::InputPayload::inputMask, rtp::ecs::components::server::InputComponent::lastMask, and rtp::ecs::components::server::InputComponent::mask.

◆ handlePlayerConnection()

uint32_t rtp::server::NetworkSyncSystem::handlePlayerConnection ( uint32_t  sessionId,
const net::Packet packet 
)

Handle new player connection.

Parameters
sessionIdID of the new session
packetPacket containing the connection data

Definition at line 84 of file NetworkSyncSystem.cpp.

References rtp::log::info(), and rtp::net::ConnectPayload::sessionId.

◆ sendPacketToEntity()

void rtp::server::NetworkSyncSystem::sendPacketToEntity ( uint32_t  entityId,
const net::Packet packet,
net::NetworkMode  mode 
)

Send a packet to the entity associated with the given ID.

Parameters
entityIdID of the target entity
packetPacket to send
modeNetwork mode (TCP or UDP)

Definition at line 95 of file NetworkSyncSystem.cpp.

References _network, _sessionToEntity, rtp::log::info(), rtp::server::ServerNetwork::sendPacket(), and rtp::log::warning().

Referenced by rtp::server::PlayerShootSystem::sendAmmoUpdate().

◆ sendPacketToSession()

◆ sendPacketToSessions()

void rtp::server::NetworkSyncSystem::sendPacketToSessions ( const std::vector< uint32_t > &  sessions,
const net::Packet packet,
net::NetworkMode  mode 
)

◆ unbindSession()

void rtp::server::NetworkSyncSystem::unbindSession ( uint32_t  sessionId)

◆ update()

void rtp::server::NetworkSyncSystem::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 26 of file NetworkSyncSystem.cpp.

Member Data Documentation

◆ _network

ServerNetwork& rtp::server::NetworkSyncSystem::_network
private

Reference to the server network manager.

Definition at line 104 of file NetworkSyncSystem.hpp.

Referenced by sendPacketToEntity(), sendPacketToSession(), and sendPacketToSessions().

◆ _registry

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

Reference to the entity registry.

Definition at line 105 of file NetworkSyncSystem.hpp.

Referenced by handleInput().

◆ _sessionToEntity

std::unordered_map<uint32_t, ecs::Entity> rtp::server::NetworkSyncSystem::_sessionToEntity
private

Map of session IDs to entities (with generation)

Definition at line 107 of file NetworkSyncSystem.hpp.

Referenced by bindSessionToEntity(), handleDisconnect(), handleInput(), sendPacketToEntity(), and unbindSession().


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