|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
Manages game state, rooms, and player interactions on the server side. More...
#include <GameManager.hpp>
Public Member Functions | |
| GameManager (ServerNetwork &networkManager) | |
| Constructor for GameManager. | |
| ~GameManager () | |
| Destructor for GameManager. | |
| void | gameLoop (void) |
| Main game loop. | |
| void | startGame (Room &room) |
| Start a game in the specified room. | |
Private Member Functions | |
| void | processNetworkEvents (void) |
| Process incoming network events with OpCode handling. | |
| void | handlePlayerConnect (uint32_t sessionId) |
| Handle a new player connection. | |
| void | handlePlayerDisconnect (uint32_t sessionId) |
| Handle a player disconnection. | |
| void | handlePlayerLoginAuth (uint32_t sessionId, const net::Packet &packet) |
| Handle player login with provided username if successful then join the lobby. | |
| void | handlePlayerRegisterAuth (uint32_t sessionId, const net::Packet &packet) |
| Handle player registration with provided username. | |
| void | handleListRooms (uint32_t sessionId) |
| Handle a request to list available rooms. | |
| void | handleCreateRoom (uint32_t sessionId, const net::Packet &packet) |
| Handle a generic incoming packet from a player. | |
| void | handleJoinRoom (uint32_t sessionId, const net::Packet &packet) |
| Handle a generic incoming packet from a player. | |
| void | handleLeaveRoom (uint32_t sessionId, const net::Packet &packet) |
| Handle a generic incoming packet from a player. | |
| void | handleSetReady (uint32_t sessionId, const net::Packet &packet) |
| Handle a generic incoming packet from a player. | |
| void | handleUpdateSelectedWeapon (uint32_t sessionId, const net::Packet &packet) |
| Handle an update to the selected weapon sent by client. | |
| void | handleRoomChatSended (uint32_t sessionId, const net::Packet &packet) |
| Handle a generic incoming packet from a player. | |
| void | handlePacket (uint32_t sessionId, const net::Packet &packet) |
| Handle an incoming packet from a player. | |
| void | handlePing (uint32_t sessionId, const net::Packet &packet) |
| bool | handleChatCommand (PlayerPtr player, const std::string &message) |
| void | sendChatToSession (uint32_t sessionId, const std::string &message) |
| void | sendSystemMessageToRoom (uint32_t roomId, const std::string &message) |
| void | sendEntitySpawnToSessions (const ecs::Entity &entity, const std::vector< uint32_t > &sessions) |
| void | sendRoomEntitySpawnsToSession (uint32_t roomId, uint32_t sessionId) |
Private Attributes | |
| ServerNetwork & | _networkManager |
| Reference to the ServerNetwork instance. | |
| ecs::Registry | _registry |
| ECS Registry for managing entities and components. | |
| std::unique_ptr< NetworkSyncSystem > | _networkSyncSystem |
| Server network system for handling network-related ECS operations. | |
| std::unique_ptr< MovementSystem > | _movementSystem |
| Movement system for updating entity positions. | |
| std::unique_ptr< AuthSystem > | _authSystem |
| Authentication system for handling player logins. | |
| std::unique_ptr< RoomSystem > | _roomSystem |
| Room system for handling room management. | |
| std::unique_ptr< PlayerSystem > | _playerSystem |
| Player system for handling player-related operations. | |
| std::unique_ptr< EntitySystem > | _entitySystem |
| Entity system for handling entity-related operations. | |
| std::unique_ptr< PlayerMouvementSystem > | _playerMouvementSystem |
| Player movement system for handling player-specific movement logic. | |
| std::unique_ptr< PlayerShootSystem > | _playerShootSystem |
| Player shooting system for handling bullets. | |
| std::unique_ptr< EnemyAISystem > | _enemyAISystem |
| Enemy AI system for movement patterns. | |
| std::unique_ptr< LevelSystem > | _levelSystem |
| Level system for timed spawns. | |
| std::unique_ptr< HomingSystem > | _homingSystem |
| Homing system for tracker bullets. | |
| std::unique_ptr< BoomerangSystem > | _boomerangSystem |
| Boomerang system for boomerang projectiles. | |
| std::unique_ptr< CollisionSystem > | _collisionSystem |
| Collision system for pickups/obstacles. | |
| std::unique_ptr< EnemyShootSystem > | _enemyShootSystem |
| Enemy shooting system. | |
| std::unique_ptr< BulletCleanupSystem > | _bulletCleanupSystem |
| Bullet cleanup system. | |
| uint32_t | _serverTick = 0 |
| Current server tick for synchronization. | |
| std::mutex | _mutex |
| Mutex for thread-safe operations. | |
| bool | _gamePaused = false |
| Global game pause flag. | |
| float | _gameSpeed = 1.0f |
| Global game speed multiplier. | |
Manages game state, rooms, and player interactions on the server side.
Definition at line 72 of file GameManager.hpp.
| rtp::server::GameManager::GameManager | ( | ServerNetwork & | networkManager | ) |
Constructor for GameManager.
| networkManager | Reference to the ServerNetwork instance |
Definition at line 22 of file GameManager.cpp.
References _authSystem, _boomerangSystem, _bulletCleanupSystem, _collisionSystem, _enemyAISystem, _enemyShootSystem, _entitySystem, _homingSystem, _levelSystem, _movementSystem, _networkManager, _networkSyncSystem, _playerMouvementSystem, _playerShootSystem, _playerSystem, _registry, _roomSystem, rtp::log::error(), rtp::ecs::Registry::get(), rtp::net::HealthUpdate, rtp::log::info(), rtp::server::LevelData::playerStart, rtp::net::ScoreUpdate, sendEntitySpawnToSessions(), rtp::ecs::Registry::subscribe(), and rtp::net::TCP.
| rtp::server::GameManager::~GameManager | ( | ) |
Destructor for GameManager.
Definition at line 122 of file GameManager.cpp.
References rtp::log::info().
| void rtp::server::GameManager::gameLoop | ( | void | ) |
Main game loop.
Definition at line 127 of file GameManager.cpp.
References _boomerangSystem, _bulletCleanupSystem, _collisionSystem, _enemyAISystem, _enemyShootSystem, _gamePaused, _gameSpeed, _homingSystem, _levelSystem, _movementSystem, _playerMouvementSystem, _playerShootSystem, _roomSystem, _serverTick, and processNetworkEvents().
Referenced by main().
|
private |
Definition at line 534 of file GameManager.cpp.
References _collisionSystem, _gamePaused, _gameSpeed, _networkManager, _playerSystem, _roomSystem, rtp::net::DebugModeUpdate, rtp::net::Kicked, rtp::net::LeaveRoom, sendChatToSession(), rtp::server::ServerNetwork::sendPacket(), sendSystemMessageToRoom(), and rtp::net::TCP.
Referenced by handleRoomChatSended().
|
private |
Handle a generic incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 339 of file GameManager.cpp.
References _mutex, _networkManager, _playerSystem, _roomSystem, rtp::net::CreateRoom, rtp::net::CreateRoomPayload::difficulty, rtp::net::CreateRoomPayload::duration, rtp::log::info(), rtp::net::CreateRoomPayload::levelId, rtp::net::CreateRoomPayload::maxPlayers, rtp::net::Private, rtp::net::CreateRoomPayload::roomName, rtp::net::CreateRoomPayload::roomType, rtp::net::CreateRoomPayload::seed, rtp::server::ServerNetwork::sendPacket(), rtp::net::CreateRoomPayload::speed, and rtp::net::TCP.
Referenced by processNetworkEvents().
|
private |
Handle a generic incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 386 of file GameManager.cpp.
References _mutex, _networkManager, _playerSystem, _roomSystem, rtp::server::Room::InGame, rtp::net::JoinRoomPayload::isSpectator, rtp::net::JoinRoomPayload::roomId, rtp::server::ServerNetwork::sendPacket(), sendRoomEntitySpawnsToSession(), rtp::net::StartGame, and rtp::net::TCP.
Referenced by processNetworkEvents().
|
private |
Handle a generic incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 415 of file GameManager.cpp.
References _mutex, _playerSystem, _roomSystem, and rtp::log::info().
Referenced by processNetworkEvents().
|
private |
Handle a request to list available rooms.
| sessionId | Unique identifier of the player requesting the room list |
| packet | Reference to the received Packet |
Definition at line 334 of file GameManager.cpp.
References _roomSystem.
Referenced by processNetworkEvents().
|
private |
Handle an incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 516 of file GameManager.cpp.
References _mutex, rtp::log::debug(), rtp::net::Packet::header, rtp::log::info(), rtp::net::LoginRequest, and rtp::net::Header::opCode.
Referenced by processNetworkEvents().
|
private |
Definition at line 523 of file GameManager.cpp.
References _networkManager, rtp::net::Pong, rtp::server::ServerNetwork::sendPacket(), and rtp::net::UDP.
Referenced by processNetworkEvents().
|
private |
Handle a new player connection.
| sessionId | Unique identifier of the connecting player |
Definition at line 221 of file GameManager.cpp.
References rtp::log::info().
Referenced by processNetworkEvents().
|
private |
Handle a player disconnection.
| sessionId | Unique identifier of the disconnecting player |
Definition at line 226 of file GameManager.cpp.
References _mutex, _networkManager, _networkSyncSystem, _playerSystem, _registry, _roomSystem, rtp::server::ServerNetwork::broadcastPacket(), rtp::net::Disconnect, rtp::net::EntityDeath, rtp::ecs::Registry::get(), rtp::log::info(), rtp::ecs::Registry::kill(), rtp::net::EntityDeathPayload::netId, rtp::ecs::NullEntity, rtp::net::TCP, and rtp::net::UDP.
Referenced by processNetworkEvents().
|
private |
Handle player login with provided username if successful then join the lobby.
| sessionId | Unique identifier of the player |
| username | Player's username |
Definition at line 292 of file GameManager.cpp.
References _authSystem, _mutex, _playerSystem, _roomSystem, rtp::log::error(), rtp::log::info(), and rtp::server::InLobby.
Referenced by processNetworkEvents().
|
private |
Handle player registration with provided username.
| sessionId | Unique identifier of the player |
| username | Player's username |
Definition at line 315 of file GameManager.cpp.
References _authSystem, _mutex, _playerSystem, _roomSystem, rtp::log::error(), rtp::log::info(), and rtp::server::InLobby.
Referenced by processNetworkEvents().
|
private |
Handle a generic incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 469 of file GameManager.cpp.
References _mutex, _networkManager, _playerSystem, _roomSystem, handleChatCommand(), rtp::net::RoomChatPayload::message, rtp::net::RoomChatReceived, rtp::server::ServerNetwork::sendPacket(), rtp::net::RoomChatReceivedPayload::sessionId, and rtp::net::TCP.
Referenced by processNetworkEvents().
|
private |
Handle a generic incoming packet from a player.
| sessionId | Unique identifier of the player sending the packet |
| packet | Reference to the received Packet |
Definition at line 429 of file GameManager.cpp.
References _mutex, _playerSystem, rtp::log::info(), and rtp::net::SetReadyPayload::isReady.
Referenced by processNetworkEvents().
|
private |
Handle an update to the selected weapon sent by client.
Definition at line 441 of file GameManager.cpp.
References _entitySystem, _mutex, _playerSystem, rtp::log::info(), and rtp::log::warning().
Referenced by processNetworkEvents().
|
private |
Process incoming network events with OpCode handling.
Definition at line 165 of file GameManager.cpp.
References _networkManager, _networkSyncSystem, handleCreateRoom(), handleJoinRoom(), handleLeaveRoom(), handleListRooms(), handlePacket(), handlePing(), handlePlayerConnect(), handlePlayerDisconnect(), handlePlayerLoginAuth(), handlePlayerRegisterAuth(), handleRoomChatSended(), handleSetReady(), handleUpdateSelectedWeapon(), rtp::server::None, and rtp::server::ServerNetwork::pollEvent().
Referenced by gameLoop().
|
private |
Definition at line 658 of file GameManager.cpp.
References _networkManager, rtp::net::RoomChatReceived, rtp::server::ServerNetwork::sendPacket(), rtp::net::RoomChatReceivedPayload::sessionId, and rtp::net::TCP.
Referenced by handleChatCommand().
|
private |
Definition at line 692 of file GameManager.cpp.
References _networkSyncSystem, _registry, rtp::net::EntitySpawn, rtp::log::error(), rtp::ecs::Registry::get(), rtp::ecs::Entity::index(), and rtp::net::TCP.
Referenced by GameManager().
|
private |
Definition at line 748 of file GameManager.cpp.
References _networkSyncSystem, _registry, rtp::net::EntitySpawn, rtp::ecs::Registry::get(), rtp::net::TCP, and rtp::ecs::Registry::zipView().
Referenced by handleJoinRoom().
|
private |
Definition at line 671 of file GameManager.cpp.
References _networkManager, _roomSystem, rtp::net::RoomChatReceived, rtp::server::ServerNetwork::sendPacket(), rtp::net::RoomChatReceivedPayload::sessionId, and rtp::net::TCP.
Referenced by handleChatCommand().
| void rtp::server::GameManager::startGame | ( | Room & | room | ) |
Start a game in the specified room.
| room | Reference to the Room where the game will start |
|
private |
Authentication system for handling player logins.
Definition at line 204 of file GameManager.hpp.
Referenced by GameManager(), handlePlayerLoginAuth(), and handlePlayerRegisterAuth().
|
private |
Boomerang system for boomerang projectiles.
Definition at line 213 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Bullet cleanup system.
Definition at line 216 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Collision system for pickups/obstacles.
Definition at line 214 of file GameManager.hpp.
Referenced by GameManager(), gameLoop(), and handleChatCommand().
|
private |
Enemy AI system for movement patterns.
Definition at line 210 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Enemy shooting system.
Definition at line 215 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Entity system for handling entity-related operations.
Definition at line 207 of file GameManager.hpp.
Referenced by GameManager(), and handleUpdateSelectedWeapon().
|
private |
Global game pause flag.
Definition at line 220 of file GameManager.hpp.
Referenced by gameLoop(), and handleChatCommand().
|
private |
Global game speed multiplier.
Definition at line 221 of file GameManager.hpp.
Referenced by gameLoop(), and handleChatCommand().
|
private |
Homing system for tracker bullets.
Definition at line 212 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Level system for timed spawns.
Definition at line 211 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Movement system for updating entity positions.
Definition at line 203 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
mutableprivate |
Mutex for thread-safe operations.
Definition at line 219 of file GameManager.hpp.
Referenced by handleCreateRoom(), handleJoinRoom(), handleLeaveRoom(), handlePacket(), handlePlayerDisconnect(), handlePlayerLoginAuth(), handlePlayerRegisterAuth(), handleRoomChatSended(), handleSetReady(), and handleUpdateSelectedWeapon().
|
private |
Reference to the ServerNetwork instance.
Definition at line 198 of file GameManager.hpp.
Referenced by GameManager(), handleChatCommand(), handleCreateRoom(), handleJoinRoom(), handlePing(), handlePlayerDisconnect(), handleRoomChatSended(), processNetworkEvents(), sendChatToSession(), and sendSystemMessageToRoom().
|
private |
Server network system for handling network-related ECS operations.
Definition at line 202 of file GameManager.hpp.
Referenced by GameManager(), handlePlayerDisconnect(), processNetworkEvents(), sendEntitySpawnToSessions(), and sendRoomEntitySpawnsToSession().
|
private |
Player movement system for handling player-specific movement logic.
Definition at line 208 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Player shooting system for handling bullets.
Definition at line 209 of file GameManager.hpp.
Referenced by GameManager(), and gameLoop().
|
private |
Player system for handling player-related operations.
Definition at line 206 of file GameManager.hpp.
Referenced by GameManager(), handleChatCommand(), handleCreateRoom(), handleJoinRoom(), handleLeaveRoom(), handlePlayerDisconnect(), handlePlayerLoginAuth(), handlePlayerRegisterAuth(), handleRoomChatSended(), handleSetReady(), and handleUpdateSelectedWeapon().
|
private |
ECS Registry for managing entities and components.
Definition at line 200 of file GameManager.hpp.
Referenced by GameManager(), handlePlayerDisconnect(), sendEntitySpawnToSessions(), and sendRoomEntitySpawnsToSession().
|
private |
Room system for handling room management.
Definition at line 205 of file GameManager.hpp.
Referenced by GameManager(), gameLoop(), handleChatCommand(), handleCreateRoom(), handleJoinRoom(), handleLeaveRoom(), handleListRooms(), handlePlayerDisconnect(), handlePlayerLoginAuth(), handlePlayerRegisterAuth(), handleRoomChatSended(), and sendSystemMessageToRoom().
|
private |
Current server tick for synchronization.
Definition at line 218 of file GameManager.hpp.
Referenced by gameLoop().