Commit Graph

23 Commits

Author SHA1 Message Date
Kieran Kihn
8d9f76eab3 refactor(game): standardize card color and type serialization format 2025-12-10 21:41:30 +08:00
Kieran Kihn
98a7ef7d41 feat(network): add async connect with onConnect callback
- Replaced synchronous `connect` with asynchronous connection logic.
- Introduced `onConnect` callback to handle connection success events.
- Ensured proper `io_context` work guard management.
2025-12-09 19:42:26 +08:00
Kieran Kihn
ebb49a02ef refactor(network): replace PlayerPublicState with ClientPlayerState
- Updated `InitGamePayload` to use `ClientPlayerState` instead of `PlayerPublicState`.
- Adjusted serialization and deserialization methods in `MessageSerializer` accordingly.
2025-12-07 13:59:40 +08:00
Kieran Kihn
ea87fca1fd fix(network): ensure write continuation upon successful async_write
- Added a check in `Session::doWrite` to invoke subsequent writes when the message queue is not empty.
2025-12-04 17:17:32 +08:00
Kieran Kihn
8335769cc8 feat(network): enhance NetworkClient with run and stop methods
- Added `run` and `stop` methods to manage the IO context lifecycle.
- Updated `send` to post messages to the IO context.
2025-12-04 17:17:24 +08:00
Kieran Kihn
024f99fc01 feat(network): add PlayerPublicState to InitGamePayload
- Introduced `PlayerPublicState` structure to represent player state.
- Updated `InitGamePayload` to include `PlayerPublicState` for all players.
- Enhanced `MessageSerializer` to handle serialization and deserialization of `PlayerPublicState`.
2025-12-04 17:15:49 +08:00
Kieran Kihn
731ed5a890 feat(network): add playerId to InitGamePayload
- Updated `InitGamePayload` to include `playerId`.
- Modified `MessageSerializer` to handle serialization and deserialization of `playerId`.
- Added validation for `playerId` in INIT_GAME payload.
2025-12-04 16:21:11 +08:00
Kieran Kihn
1d2e77aca3 refactor(network): integrate NetworkClient with Session
- Moved `Session` implementation to `Session.cpp` and `Session.h`.
- Updated `Session` to use a `message` queue for sending data, improving handling of writes.
- Adjusted `NetworkClient` and `NetworkServer` to integrate with the new `Session` logic.
2025-12-04 14:42:22 +08:00
Kieran Kihn
271d89df0d refactor(network): change DrawCardPayload::drawCount to size_t 2025-12-02 12:17:28 +08:00
Kieran Kihn
016e87288d refactor(network): replace HandCard with std::multiset<Card> in InitGamePayload
- Updated `InitGamePayload` to use `std::multiset<Card>` for `handCard`.
- Removed `serializeHandCard` method and replaced its usage with `serializeCards`.
- Adjusted `deserializeHandCard` to return `std::multiset<Card>` and simplified insertion logic.
- Cleaned up unused declarations in `MessageSerializer`.
2025-12-02 12:06:21 +08:00
Kieran Kihn
c2ccaaf17e fix(network): ensure disconnect before connect in NetworkClient
- Added `disconnect` method to gracefully close existing connections before establishing a new one.
- Updated `connect` to call `disconnect` to prevent resource conflicts.
2025-11-29 18:51:58 +08:00
Kieran Kihn
12d1d6c93f fix(network): call accept on NetworkServer initialization and after player addition
- Ensure `accept` is called during `NetworkServer` initialization and after successfully adding a player to handle new connections continuously.
2025-11-29 18:51:41 +08:00
Kieran Kihn
b6144d33e9 fix(network): reattempt read in NetworkServer after message handling
- Added a call to `read()` after successfully processing an incoming message in `NetworkServer`.
2025-11-29 18:51:30 +08:00
Kieran Kihn
27cf988ee5 fix(network): validate and reattempt read if message length is invalid
- Updated `NetworkServer` to validate `messageLength` and reattempt `read` if it exceeds the maximum allowed size.
2025-11-29 18:51:18 +08:00
Kieran Kihn
3dd07e4b20 fix(network): use shared pointer for message length in Session::read
- Updated `Session::read` to use `std::shared_ptr` for message length to ensure proper memory handling in async operations.
2025-11-29 18:50:44 +08:00
Kieran Kihn
f4f66bb397 fix(network): send message length before body 2025-11-29 18:50:17 +08:00
Kieran Kihn
b0b6d78630 feat(network): add stop method to NetworkServer
- Implemented `stop` method in `NetworkServer` to close the acceptor and stop the IO context.
- Updated `NetworkServer.h` with corresponding method declaration and documentation.
2025-11-29 18:47:33 +08:00
Kieran Kihn
042ab95dda feat(network): add NetworkClient for TCP communication
- Introduced `NetworkClient` class for client-side TCP communication.
- Implemented `connect`, `send`, and `read` methods for message handling.
- Updated `CMakeLists.txt` to include `NetworkClient.cpp` in the build configuration.
2025-11-28 22:22:03 +08:00
Kieran Kihn
84c470859b feat(network): add NetworkServer for managing player sessions and communication
- Implemented `NetworkServer` and `Session` classes for handling TCP communication with players.
- Added `NetworkServer.cpp` and `NetworkServer.h` to the project.
- Integrated `asio` library into the build configuration in `CMakeLists.txt`.
2025-11-28 20:40:14 +08:00
Kieran Kihn
7300de3fe4 feat(network): refactor MessageSerializer for modular serialization and validation
- Added reusable `serializeCards` function for card list serialization.
- Enhanced `DrawCardPayload` with a `cards` field.
- Introduced `serializeMessageStatus` and `deserializeMessageStatus` for message status handling.
- Updated deserialization logic to validate and include `status_code` field.
- Improved error messaging and validation for payload deserialization methods.
2025-11-23 15:02:14 +08:00
Kieran Kihn
7301a2c787 feat(network): enhance Message validation and add EMPTY payload type
- Introduced `MessageStatus` for message validation and tracking.
- Added `EMPTY` payload type to `MessagePayloadType` for invalid or empty messages.
- Updated `Message` constructor to validate payload type and status.
- Implemented `getMessageStatus` to retrieve the message status.
2025-11-23 15:01:08 +08:00
Kieran Kihn
6ea7ad71c2 feat(network): add MessageSerializer for message serialization/deserialization
- Implemented `MessageSerializer` class to handle JSON serialization and deserialization of game messages and payloads.
- Added `MessageSerializer.cpp` and `MessageSerializer.h` to `CMakeLists.txt`.
- Linked `nlohmann_json` library to the project.
2025-11-21 22:50:31 +08:00
Kieran Kihn
820358e0a3 feat(network): add Message class with payload types
- Introduced `Message` class in `src/network` for handling game-related message payloads (e.g., `JOIN_GAME`, `START_GAME`, etc.).
- Added `Message.cpp` and `Message.h` to `CMakeLists.txt`.
2025-11-21 22:49:23 +08:00