![]() |
ConnectX 3.0
ConnectX Game Suite
|
#include <client.hpp>
Public Types | |
| using | DisconnectedCallback = std::function< void()> |
| using | GameStateUpdateCallback = std::function< void(const GameStateUpdate &)> |
| using | MoveResultCallback = std::function< void(bool success, const std::string &message)> |
| using | ErrorCallback = std::function< void(uint16_t error_code, const std::string &message)> |
Public Member Functions | |
| Client () | |
| ~Client () | |
| bool | connect (const std::string &host, uint16_t port) |
| void | disconnect () |
| bool | isConnected () const |
| bool | isRunning () const |
| void | run () |
| void | stop () |
| bool | sendConnectRequest (const std::string &player_name) |
| bool | sendCreateGame (const GameConfig &config, const std::string &name="") |
| bool | sendListGames () |
| bool | sendJoinGame (uint32_t game_id) |
| bool | sendMove (uint8_t column) |
| bool | sendDisconnect (const std::string &reason="Client disconnecting") |
| std::optional< ConnectResponse > | requestConnect (const std::string &player_name, int timeout_ms=3000) |
| std::optional< CreateGameResponse > | requestCreateGame (const GameConfig &config, const std::string &name="", int timeout_ms=3000) |
| std::optional< ListGamesResponse > | requestGamesList (int timeout_ms=3000) |
| std::optional< JoinGameResponse > | requestJoinGame (uint32_t game_id, int timeout_ms=3000) |
| void | onDisconnected (DisconnectedCallback callback) |
| void | onGameStateUpdate (GameStateUpdateCallback callback) |
| void | onMoveResult (MoveResultCallback callback) |
| void | onError (ErrorCallback callback) |
| const std::string & | getSessionToken () const |
| uint8_t | getPlayerId () const |
| std::optional< uint8_t > | getPlayerIndex (const GameStateUpdate &state, uint8_t player_id) |
| const std::optional< GameInfo > & | getGameInfo () const |
| uint32_t | getGameId () const |
| std::string | getGameName () const |
| const std::optional< GameStateUpdate > & | getCurrentState () const |
| bool | isMyTurn () const |
High-level client for Connect X game Handles connection, message serialization, and state management
| using Client::DisconnectedCallback = std::function<void()> |
| using Client::ErrorCallback = std::function<void(uint16_t error_code, const std::string &message)> |
| using Client::GameStateUpdateCallback = std::function<void(const GameStateUpdate &)> |
| using Client::MoveResultCallback = std::function<void(bool success, const std::string &message)> |
| Client::Client | ( | ) |
| Client::~Client | ( | ) |
| bool Client::connect | ( | const std::string & | host, |
| uint16_t | port | ||
| ) |
Connect to server
| host | Server hostname or IP |
| port | Server port |
| void Client::disconnect | ( | ) |
Disconnect from server
|
inline |
Get current game state (updated by server)
|
inline |
Get current game ID
|
inline |
Get current game info
|
inline |
Get current game name
|
inline |
Get assigned player ID
|
inline |
|
inline |
Get current session token
|
inline |
Check if connected to server
|
inline |
Check if it's my turn
|
inline |
Check if event loop is running
|
inline |
|
inline |
|
inline |
|
inline |
| std::optional< ConnectResponse > Client::requestConnect | ( | const std::string & | player_name, |
| int | timeout_ms = 3000 |
||
| ) |
| std::optional< CreateGameResponse > Client::requestCreateGame | ( | const GameConfig & | config, |
| const std::string & | name = "", |
||
| int | timeout_ms = 3000 |
||
| ) |
| std::optional< ListGamesResponse > Client::requestGamesList | ( | int | timeout_ms = 3000 | ) |
| std::optional< JoinGameResponse > Client::requestJoinGame | ( | uint32_t | game_id, |
| int | timeout_ms = 3000 |
||
| ) |
| void Client::run | ( | ) |
Run the client event loop (blocking) Processes incoming messages until disconnected
| bool Client::sendConnectRequest | ( | const std::string & | player_name | ) |
Send connection request with player name
| player_name | Your display name |
| bool Client::sendCreateGame | ( | const GameConfig & | config, |
| const std::string & | name = "" |
||
| ) |
Create a new game with custom configuration
| bool Client::sendDisconnect | ( | const std::string & | reason = "Client disconnecting" | ) |
Send disconnect message
| bool Client::sendJoinGame | ( | uint32_t | game_id | ) |
Join an existing game by ID
| bool Client::sendListGames | ( | ) |
Request list of available games
| bool Client::sendMove | ( | uint8_t | column | ) |
Make a move (place piece in column)
| column | Column index (0-based) |
| void Client::stop | ( | ) |
Stop the event loop