8#ifndef RTYPE_CLIENT_NETWORK_SYSTEM_HPP_
9 #define RTYPE_CLIENT_NETWORK_SYSTEM_HPP_
63 void update(
float dt)
override;
72 void tryLogin(
const std::string& username,
const std::string& password, uint8_t weaponKind)
const;
80 void tryRegister(
const std::string& username,
const std::string& password)
const;
99 void tryCreateRoom(
const std::string& roomName, uint32_t maxPlayers,
float difficulty,
float speed, uint32_t duration, uint32_t seed, uint32_t levelId, uint8_t roomType);
105 void tryJoinRoom(uint32_t roomId,
bool asSpectator =
false);
291 std::unordered_map<uint32_t, std::vector<std::pair<ecs::Entity, float>>>
_beamEntities;
Interface for ECS systems.
Network packet implementation for R-Type protocol.
System to handle network-related operations on the client side.
bool _isLoggedIn
Flag indicating if the client is logged in.
void onSpawnEntityFromServer(net::Packet &packet)
std::deque< std::string > _chatHistory
Recent chat messages.
State getState(void) const
Get the current state of the client.
void tryRegister(const std::string &username, const std::string &password) const
Send a request to server attempting to register with provided credentials.
uint16_t getAmmoCurrent(void) const
bool isInGame(void) const
Check if the client is in game.
void onEntityDeath(net::Packet &packet)
void trySetReady(bool isReady)
Send a request to set the client's ready status in the current room.
void onLeaveRoomResponse(net::Packet &packet)
void onRoomResponse(net::Packet &packet)
bool isInRoom(void) const
Check if the client is in a room.
ecs::Registry & _registry
Reference to the entity registry.
std::unordered_map< uint32_t, ecs::Entity > _netIdToEntity
Map of network IDs to entities.
int _healthMax
Latest max health.
bool isReloading(void) const
void onDebugModeUpdate(net::Packet &packet)
void setGameOverSummary(const GameOverSummary &summary)
void pushChatMessage(const std::string &message)
float _ammoReloadRemaining
Reload time remaining.
bool _isReady
Flag indicating if the client is ready.
bool isReady(void) const
Check if the client is ready.
uint32_t getPingMs(void) const
bool _isInRoom
Flag indicating if the client is in a room.
void onBeamState(net::Packet &packet)
std::list< net::RoomInfo > _availableRooms
List of available rooms from the server.
uint32_t _currentLevelId
Current level id used by client visuals.
int getHealthCurrent(void) const
bool consumeGameOver(void)
float _pingTimer
Ping timer accumulator.
void onPong(net::Packet &packet)
bool _udpReady
Flag indicating if UDP is ready.
void onRegisterResponse(net::Packet &packet)
void tryLogin(const std::string &username, const std::string &password, uint8_t weaponKind) const
Send a request to server attempting to log in with provided credentials.
bool isLoggedIn(void) const
Check if the client is logged in.
float _pingInterval
Ping interval in seconds.
void tryJoinRoom(uint32_t roomId, bool asSpectator=false)
Send a request to join an existing room on the server.
void tryLeaveRoom(void)
Send a request to leave the current room on the server.
void onAmmoUpdate(net::Packet &packet)
uint16_t _ammoMax
Max ammo.
void tryStartSolo(void)
Start a solo game by creating a private room and auto-joining/readying.
std::unordered_map< uint32_t, std::vector< std::pair< ecs::Entity, float > > > _beamEntities
bool _ammoReloading
Reload state.
std::unordered_map< uint32_t, std::vector< float > > _beamLengths
bool _gameOverPending
Game over pending flag.
uint16_t getAmmoMax(void) const
uint16_t _ammoCurrent
Current ammo.
float getReloadCooldownRemaining(void) const
void onJoinRoomResponse(net::Packet &packet)
EntityBuilder _builder
Entity builder for spawning entities.
void handleEvent(net::NetworkEvent &event)
Handle a network event.
std::size_t _chatHistoryLimit
Max chat messages to keep.
void onCreateRoomResponse(net::Packet &packet)
uint32_t getCurrentLevelId(void) const
Get the current level ID for client-side visuals (parallax)
int _score
Latest server score.
bool isUdpReady(void) const
Check if UDP is ready.
void onRoomChatReceived(net::Packet &packet)
int getHealthMax(void) const
void tryCreateRoom(const std::string &roomName, uint32_t maxPlayers, float difficulty, float speed, uint32_t duration, uint32_t seed, uint32_t levelId, uint8_t roomType)
Send a request to create a new room on the server.
void trySendMessage(const std::string &message) const
Send a chat message to the server.
int _healthCurrent
Latest health.
void requestListRooms(void)
Send a request to have the list of available rooms from the server.
std::string _username
The username of the client.
void update(float dt) override
Update system logic for one frame.
ClientNetwork & _network
Reference to the client network manager.
bool _isStartingSolo
Check if the client is starting a solo game.
GameOverSummary _gameOverSummary
Cached game over summary.
std::string getLastChatMessage(void) const
Get the last received room chat message.
std::string getUsername(void) const
Get the username of the client.
void onLoginResponse(net::Packet &packet)
std::string _lastChatMessage
Last received chat message.
const std::deque< std::string > & getChatHistory(void) const
Get chat history buffer (most recent last)
void onRoomUpdate(net::Packet &packet)
void sendSelectedWeapon(uint8_t weaponKind) const
Send currently selected weapon to server to apply immediately.
GameOverSummary getGameOverSummary(void) const
State _currentState
Current state of the client.
std::list< net::RoomInfo > getAvailableRooms(void) const
Get a list of available rooms from the server.
uint32_t _pingMs
Latest ping in ms.
Abstract base class for all ECS systems.
Network packet with header and serializable body.
Represents a network event containing session ID and packet data.