19#include "../common/Logger/Logger.hpp"
22#include "Core/EventBus/EventBus.hpp"
24#include "Events/NetworkEvent/NetworkEvent.hpp"
104 bool connect(
const std::string &host, uint16_t port);
222 const std::string &password);
240 bool sendLoginAccount(
const std::string &username,
const std::string &password);
258 bool sendCreateRoom(
const std::string &roomName, uint32_t maxPlayers,
bool isPrivate,
259 float gameSpeedMultiplier = 1.0f);
Type-safe event publication/subscription system.
Interface representing a remote peer in the network.
Client-server network replication manager with dedicated network thread.
bool isConnected() const
Check if connected to server.
bool sendStartGame()
Send start game request to server.
bool sendLoginAccount(const std::string &username, const std::string &password)
Send login request to server.
bool sendListRooms()
Send list rooms request to server.
bool sendAutoMatchmaking()
Send auto-matchmaking request to server.
bool connect(const std::string &host, uint16_t port)
Connect to the game server.
void startNetworkThread()
Start the dedicated network thread.
void processMessages()
Process incoming network messages.
bool getAutoMatchmakingPreference() const
Get the user's auto-matchmaking preference from server.
std::unique_ptr< IHost > _host
ThreadSafeQueue< NetworkEvent > _incomingMessages
Queue for messages from network thread.
void disconnect()
Disconnect from the server.
std::atomic< bool > _autoMatchmakingPreference
void networkThreadLoop(std::stop_token stopToken)
Network thread main loop.
uint32_t getPacketLoss() const
Get packet loss rate as percentage.
void onInputEvent(const InputEvent &event)
Handle an incoming packet from the network.
void processIncomingPacket(const std::vector< uint8_t > &packet)
bool sendRequestRoomList()
Request the list of available rooms from server.
std::jthread _networkThread
Dedicated network thread.
bool isSpectator() const
Check if in spectator mode.
uint32_t getMyPlayerId() const
Get the player ID assigned by server.
void sendPacket(NetworkMessageType type, const std::vector< uint8_t > &data)
Send a packet to the server.
static constexpr float PING_SMOOTHING_FACTOR
bool sendRegisterAccount(const std::string &username, const std::string &password)
Send register account request to server.
std::atomic< uint32_t > _myPlayerId
bool sendLeaveRoom()
Send request to leave current room.
bool updateAutoMatchmakingPreference(bool enabled)
Update auto-matchmaking preference on server.
uint32_t getLatency() const
Get current latency in milliseconds.
std::atomic< float > _smoothedLatency
bool sendCreateRoom(const std::string &roomName, uint32_t maxPlayers, bool isPrivate, float gameSpeedMultiplier=1.0f)
Send create room request to server.
std::string _lastLoginUsername
void stopNetworkThread()
Stop the dedicated network thread.
std::atomic< bool > _authenticated
bool isAuthenticated() const
Check if authenticated with server.
bool sendConnectRequest(const std::string &playerName, const std::string &username, const std::string &password)
Send connect request to server with player name.
bool sendJoinRoom(const std::string &roomId)
Send join room request to server.
std::atomic< bool > _connected
bool sendChatMessage(const std::string &message)
Send chat message to server.
std::atomic< uint32_t > _latency
Thread-safe queue for inter-thread communication.
NetworkMessageType
Types of network messages exchanged between client and server.