|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
System to handle room-related operations on the server side. More...
#include <RoomSystem.hpp>
Public Types | |
| using | RoomStartedCb = std::function< void(uint32_t roomId)> |
| Callback type for when a room starts. | |
Public Member Functions | |
| void | setOnRoomStarted (RoomStartedCb cb) |
| Set the callback to be invoked when a room starts. | |
| RoomSystem (ServerNetwork &network, ecs::Registry ®istry, NetworkSyncSystem &networkSync) | |
| Constructor for RoomSystem. | |
| void | update (float dt) override |
| Update system logic for one frame. | |
| uint32_t | createRoom (uint32_t sessionId, const std::string &roomName, uint8_t maxPlayers, float difficulty, float speed, Room::RoomType type, uint32_t levelId, uint32_t seed, uint32_t durationMinutes) |
| Create a new room based on client request. | |
| bool | joinRoom (PlayerPtr player, uint32_t roomId, bool asSpectator=false) |
| Join an existing room based on client request. | |
| bool | joinLobby (PlayerPtr player) |
| Join the lobby room. | |
| bool | leaveRoom (PlayerPtr player) |
| Leave the current room based on client request. | |
| void | disconnectPlayer (uint32_t sessionId) |
| Disconnect a player from all rooms. | |
| void | listAllRooms (uint32_t sessionId) |
| List all available rooms based on client request. | |
| void | chatInRoom (uint32_t sessionId, const net::Packet &packet) |
| Handle chat message in the room based on client request. | |
| void | launchReadyRooms (float dt) |
| Launch all rooms that are ready to start the game. | |
| std::shared_ptr< Room > | getRoom (uint32_t roomId) |
| Get a room by its ID. | |
Public Member Functions inherited from rtp::ecs::ISystem | |
| virtual | ~ISystem () noexcept=default |
Private Member Functions | |
| void | despawnPlayerEntity (const PlayerPtr &player, const std::shared_ptr< Room > &room) |
Private Attributes | |
| ServerNetwork & | _network |
| Reference to the server network manager. | |
| NetworkSyncSystem & | _networkSync |
| Reference to the network sync system. | |
| ecs::Registry & | _registry |
| Reference to the entity registry. | |
| std::map< uint32_t, std::shared_ptr< Room > > | _rooms {} |
| Map of room ID to Room instances. | |
| std::map< uint32_t, uint32_t > | _playerRoomMap |
| Map of player session ID to room ID. | |
| uint32_t | _nextRoomId = 1 |
| Next available room ID. | |
| uint32_t | _lobbyId = 0 |
| ID of the main lobby room. | |
| std::mutex | _mutex |
| Mutex for thread-safe operations. | |
| RoomStartedCb | _onRoomStarted |
| Callback for when a room starts. | |
System to handle room-related operations on the server side.
Definition at line 33 of file RoomSystem.hpp.
Callback type for when a room starts.
Definition at line 40 of file RoomSystem.hpp.
| rtp::server::RoomSystem::RoomSystem | ( | ServerNetwork & | network, |
| ecs::Registry & | registry, | ||
| NetworkSyncSystem & | networkSync | ||
| ) |
Constructor for RoomSystem.
| network | Reference to the server network manager |
| registry | Reference to the entity registry |
Definition at line 22 of file RoomSystem.cpp.
References _lobbyId, _networkSync, _nextRoomId, _registry, _rooms, rtp::log::info(), and rtp::server::Room::Lobby.
| void rtp::server::RoomSystem::chatInRoom | ( | uint32_t | sessionId, |
| const net::Packet & | packet | ||
| ) |
Handle chat message in the room based on client request.
| sessionId | ID of the network session |
| packet | Packet containing the chat message data |
Definition at line 296 of file RoomSystem.cpp.
| uint32_t rtp::server::RoomSystem::createRoom | ( | uint32_t | sessionId, |
| const std::string & | roomName, | ||
| uint8_t | maxPlayers, | ||
| float | difficulty, | ||
| float | speed, | ||
| Room::RoomType | type, | ||
| uint32_t | levelId, | ||
| uint32_t | seed, | ||
| uint32_t | durationMinutes | ||
| ) |
Create a new room based on client request.
| sessionId | ID of the network session |
| roomName | Name of the room |
| maxPlayers | Maximum number of players allowed in the room |
| difficulty | Difficulty setting for the room |
| speed | Speed setting for the room |
| type | Type of the room (Public/Private) |
| levelId | ID of the level to be played in the room |
| seed | Seed for level generation |
| durationMinutes | Duration of the game in minutes |
Definition at line 43 of file RoomSystem.cpp.
References _networkSync, _nextRoomId, _registry, _rooms, and rtp::log::info().
|
private |
Definition at line 370 of file RoomSystem.cpp.
References _networkSync, _registry, rtp::net::EntityDeath, rtp::ecs::Registry::get(), rtp::ecs::Entity::isNull(), rtp::ecs::Registry::kill(), rtp::server::Room::Lobby, rtp::net::EntityDeathPayload::netId, rtp::ecs::NullEntity, rtp::server::NetworkSyncSystem::sendPacketToSession(), rtp::net::TCP, and rtp::server::NetworkSyncSystem::unbindSession().
Referenced by disconnectPlayer(), and leaveRoom().
| void rtp::server::RoomSystem::disconnectPlayer | ( | uint32_t | sessionId | ) |
Disconnect a player from all rooms.
| sessionId | ID of the network session |
Definition at line 198 of file RoomSystem.cpp.
References _mutex, _playerRoomMap, _rooms, despawnPlayerEntity(), and rtp::server::Room::Lobby.
| std::shared_ptr< Room > rtp::server::RoomSystem::getRoom | ( | uint32_t | roomId | ) |
Get a room by its ID.
| roomId | ID of the room |
Definition at line 359 of file RoomSystem.cpp.
References _mutex, and _rooms.
Referenced by rtp::server::BulletCleanupSystem::despawn(), rtp::server::CollisionSystem::despawn(), rtp::server::EnemyShootSystem::spawnBullet(), rtp::server::PlayerShootSystem::spawnBullet(), rtp::server::PlayerShootSystem::spawnChargedBullet(), rtp::server::PlayerShootSystem::spawnDebugPowerup(), rtp::server::LevelSystem::spawnEntityForRoom(), rtp::server::CollisionSystem::spawnPowerup(), rtp::server::LevelSystem::update(), rtp::server::CollisionSystem::update(), and rtp::server::PlayerShootSystem::update().
| bool rtp::server::RoomSystem::joinLobby | ( | PlayerPtr | player | ) |
Join the lobby room.
| sessionId | ID of the network session |
Definition at line 161 of file RoomSystem.cpp.
References _lobbyId, and joinRoom().
| bool rtp::server::RoomSystem::joinRoom | ( | PlayerPtr | player, |
| uint32_t | roomId, | ||
| bool | asSpectator = false |
||
| ) |
Join an existing room based on client request.
| sessionId | ID of the network session |
| packet | Packet containing the room join data |
Definition at line 64 of file RoomSystem.cpp.
References _mutex, _network, _playerRoomMap, _rooms, rtp::log::error(), rtp::log::info(), rtp::server::InGame, rtp::server::Room::InGame, rtp::server::InLobby, rtp::net::JoinRoom, leaveRoom(), rtp::server::Room::Lobby, rtp::server::Room::Player, rtp::server::ServerNetwork::sendPacket(), rtp::server::Room::Spectator, rtp::net::TCP, rtp::server::Room::Waiting, and rtp::log::warning().
Referenced by joinLobby().
| void rtp::server::RoomSystem::launchReadyRooms | ( | float | dt | ) |
Launch all rooms that are ready to start the game.
Definition at line 302 of file RoomSystem.cpp.
References _mutex, _network, _onRoomStarted, _rooms, rtp::log::debug(), rtp::log::info(), rtp::server::Room::InGame, rtp::server::Room::Lobby, rtp::server::ServerNetwork::sendPacket(), rtp::net::StartGame, rtp::net::TCP, and rtp::server::Room::Waiting.
Referenced by update().
| bool rtp::server::RoomSystem::leaveRoom | ( | PlayerPtr | player | ) |
Leave the current room based on client request.
| sessionId | ID of the network session |
| packet | Packet containing the room leave data |
Definition at line 166 of file RoomSystem.cpp.
References _mutex, _playerRoomMap, _rooms, despawnPlayerEntity(), and rtp::server::Room::Lobby.
Referenced by joinRoom().
| void rtp::server::RoomSystem::listAllRooms | ( | uint32_t | sessionId | ) |
List all available rooms based on client request.
| sessionId | ID of the network session |
| packet | Packet containing the room list request data |
Definition at line 234 of file RoomSystem.cpp.
References _mutex, _network, _rooms, rtp::log::info(), rtp::server::Room::InGame, rtp::server::Room::Lobby, rtp::server::Room::Private, rtp::server::Room::Public, rtp::net::RoomInfo::roomId, rtp::net::RoomList, rtp::server::ServerNetwork::sendPacket(), and rtp::net::TCP.
|
inline |
Set the callback to be invoked when a room starts.
| cb | Callback function |
Definition at line 46 of file RoomSystem.hpp.
References _onRoomStarted.
|
overridevirtual |
Update system logic for one frame.
| dt | Time elapsed since last update in seconds |
Implements rtp::ecs::ISystem.
Definition at line 34 of file RoomSystem.cpp.
References _rooms, and launchReadyRooms().
|
private |
ID of the main lobby room.
Definition at line 141 of file RoomSystem.hpp.
Referenced by RoomSystem(), and joinLobby().
|
mutableprivate |
Mutex for thread-safe operations.
Definition at line 142 of file RoomSystem.hpp.
Referenced by disconnectPlayer(), getRoom(), joinRoom(), launchReadyRooms(), leaveRoom(), and listAllRooms().
|
private |
Reference to the server network manager.
Definition at line 134 of file RoomSystem.hpp.
Referenced by joinRoom(), launchReadyRooms(), and listAllRooms().
|
private |
Reference to the network sync system.
Definition at line 135 of file RoomSystem.hpp.
Referenced by RoomSystem(), createRoom(), and despawnPlayerEntity().
|
private |
Next available room ID.
Definition at line 140 of file RoomSystem.hpp.
Referenced by RoomSystem(), and createRoom().
|
private |
Callback for when a room starts.
Definition at line 143 of file RoomSystem.hpp.
Referenced by launchReadyRooms(), and setOnRoomStarted().
|
private |
Map of player session ID to room ID.
Definition at line 139 of file RoomSystem.hpp.
Referenced by disconnectPlayer(), joinRoom(), and leaveRoom().
|
private |
Reference to the entity registry.
Definition at line 136 of file RoomSystem.hpp.
Referenced by RoomSystem(), createRoom(), and despawnPlayerEntity().
|
private |
Map of room ID to Room instances.
Definition at line 138 of file RoomSystem.hpp.
Referenced by RoomSystem(), createRoom(), disconnectPlayer(), getRoom(), joinRoom(), launchReadyRooms(), leaveRoom(), listAllRooms(), and update().