|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
System to handle network-related operations on the server side. More...
#include <NetworkSyncSystem.hpp>
Public Member Functions | |
| NetworkSyncSystem (ServerNetwork &network, ecs::Registry ®istry) | |
| 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) | |
System to handle network-related operations on the server side.
Definition at line 35 of file NetworkSyncSystem.hpp.
| rtp::server::NetworkSyncSystem::NetworkSyncSystem | ( | ServerNetwork & | network, |
| ecs::Registry & | registry | ||
| ) |
Constructor for NetworkSyncSystem.
| network | Reference to the server network manager |
| registry | Reference to the entity registry |
Definition at line 21 of file NetworkSyncSystem.cpp.
| void rtp::server::NetworkSyncSystem::bindSessionToEntity | ( | uint32_t | sessionId, |
| ecs::Entity | entity | ||
| ) |
Bind a network session to an entity.
| sessionId | ID of the network session |
| entity | The entity to bind (includes both index and generation) |
Definition at line 31 of file NetworkSyncSystem.cpp.
References _sessionToEntity.
| void rtp::server::NetworkSyncSystem::handleDisconnect | ( | uint32_t | sessionId | ) |
Handle disconnection of a client.
| sessionId | ID of the disconnected session |
Definition at line 73 of file NetworkSyncSystem.cpp.
References _sessionToEntity, rtp::ecs::Entity::index(), and rtp::log::info().
| void rtp::server::NetworkSyncSystem::handleInput | ( | uint32_t | sessionId, |
| const net::Packet & | packet | ||
| ) |
Handle input received from a client.
| sessionId | ID of the network session |
| packet | Packet 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.
| uint32_t rtp::server::NetworkSyncSystem::handlePlayerConnection | ( | uint32_t | sessionId, |
| const net::Packet & | packet | ||
| ) |
Handle new player connection.
| sessionId | ID of the new session |
| packet | Packet containing the connection data |
Definition at line 84 of file NetworkSyncSystem.cpp.
References rtp::log::info(), and rtp::net::ConnectPayload::sessionId.
| 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.
| entityId | ID of the target entity |
| packet | Packet to send |
| mode | Network 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().
| void rtp::server::NetworkSyncSystem::sendPacketToSession | ( | uint32_t | sessionId, |
| const net::Packet & | packet, | ||
| net::NetworkMode | mode | ||
| ) |
Send a packet to a specific session.
| sessionId | ID of the target session |
| packet | Packet to send |
| mode | Network mode (TCP or UDP) |
Definition at line 112 of file NetworkSyncSystem.cpp.
References _network, and rtp::server::ServerNetwork::sendPacket().
Referenced by rtp::server::Room::addPlayer(), rtp::server::Room::broadcastRoomState(), rtp::server::Room::broadcastSystemMessage(), rtp::server::BulletCleanupSystem::despawn(), rtp::server::CollisionSystem::despawn(), rtp::server::RoomSystem::despawnPlayerEntity(), rtp::server::CollisionSystem::spawnPowerup(), rtp::server::CollisionSystem::update(), rtp::server::PlayerShootSystem::update(), and rtp::server::Room::update().
| void rtp::server::NetworkSyncSystem::sendPacketToSessions | ( | const std::vector< uint32_t > & | sessions, |
| const net::Packet & | packet, | ||
| net::NetworkMode | mode | ||
| ) |
Send a packet to multiple sessions.
| sessions | List of session IDs |
| packet | Packet to send |
| mode | Network mode (TCP or UDP) |
Definition at line 119 of file NetworkSyncSystem.cpp.
References _network, and rtp::server::ServerNetwork::sendPacket().
Referenced by rtp::server::EnemyShootSystem::spawnBullet(), rtp::server::PlayerShootSystem::spawnBullet(), rtp::server::PlayerShootSystem::spawnChargedBullet(), rtp::server::PlayerShootSystem::spawnDebugPowerup(), rtp::server::LevelSystem::spawnEntityForRoom(), and rtp::server::PlayerShootSystem::update().
| void rtp::server::NetworkSyncSystem::unbindSession | ( | uint32_t | sessionId | ) |
Definition at line 37 of file NetworkSyncSystem.cpp.
References _sessionToEntity.
Referenced by rtp::server::RoomSystem::despawnPlayerEntity(), and rtp::server::CollisionSystem::update().
|
overridevirtual |
Update system logic for one frame.
| dt | Time elapsed since last update in seconds |
Implements rtp::ecs::ISystem.
Definition at line 26 of file NetworkSyncSystem.cpp.
|
private |
Reference to the server network manager.
Definition at line 104 of file NetworkSyncSystem.hpp.
Referenced by sendPacketToEntity(), sendPacketToSession(), and sendPacketToSessions().
|
private |
Reference to the entity registry.
Definition at line 105 of file NetworkSyncSystem.hpp.
Referenced by handleInput().
|
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().