Commit Graph

57 Commits

Author SHA1 Message Date
Kieran Kihn
0d5a187cba feat(server): implement Uno server functionality
- Added `UnoServer` class to handle player actions, game state, and networking.
- Supported message handling for joining, starting, drawing, and playing cards.
- Integrated `ServerGameState` with `NetworkServer` for multiplayer game logic.
- Created `main.cpp` to initialize and run the Uno server.
2025-12-02 12:28:59 +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
8a00b66047 refactor(game): return drawn cards in updateStateByDraw
- Updated `updateStateByDraw` to return a `std::vector<Card>` instead of `void`.
- Adjusted `ServerGameState`, `GameState`, and `ClientGameState` implementations to reflect the change.
2025-12-02 12:06:06 +08:00
Kieran Kihn
e5304b8c6c refactor(game): simplify GameState construction and initialization
- Removed `GameStatus` dependency from `GameState` constructors.
- Adjusted `ClientGameState` and `ServerGameState` constructors accordingly.
- Simplified `ServerGameState::init()` to handle card initialization and player actions.
- Updated tests to reflect these changes.
2025-12-02 11:08:42 +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
db69b399ec refactor(game): remove redundant colorToString logic for wild card types
- Eliminated unnecessary wild card handling in `Card::colorToString`.
2025-11-23 15:02:30 +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
Kieran Kihn
e78741bd9d refactor(game): encapsulate Player and ClientGameState state management
- Replaced public `Player::handCard` pointer with private `HandCard` member.
- Introduced `draw`, `play`, and `getCards` methods in `Player` and `ClientGameState`.
- Modified `ClientGameState` constructor to accept player name instead of `Player` object.
- Updated tests to reflect new `Player` and `ClientGameState` structure.
2025-11-18 17:15:07 +08:00
Kieran Kihn
423c237a39 fix(game): remove redundant PlayerState::play call in GameState::play
- Eliminated unnecessary `PlayerState::play` method invocation to streamline card play logic.
2025-11-17 22:10:16 +08:00
Kieran Kihn
b027e5c4db fix(game): update Card::canBePlayedOn to include draw count validation
- Modified `canBePlayedOn` method to consider `drawCount` for additional play restrictions.
- Updated `GameState::updateStateByCard` to pass `drawCount` when validating playable cards.
2025-11-17 21:33:36 +08:00
Kieran Kihn
ebac6291b0 refactor(game): introduce draw and play methods in PlayerState and subclasses
- Replaced `setRemainingCardCount` with `draw` and `play` methods.
- Added virtual overrides for player-specific behaviors in `ClientPlayerState` and `ServerPlayerState`.
- Refactored `ServerGameState::init` to centralize deck and discard pile setup.
- Updated `updateStateByDraw` to leverage `PlayerState::draw` for consistency.
2025-11-17 21:16:50 +08:00
Kieran Kihn
03e1d363e2 fix(game): move clear method to public section in CardTile 2025-11-17 21:14:59 +08:00
Kieran Kihn
091e5f33ca refactor(game): make HandCard default-constructible
- Removed the constructor requiring an array of cards.
2025-11-17 21:14:36 +08:00
Kieran Kihn
d5e1d7f03d fix(game): add validation for card existence in GameState::play
- Throw exception if card is not found in player's hand.
- Ensure loop exits correctly after playing the card.
2025-11-17 15:49:45 +08:00
Kieran Kihn
cbb49343bc fix(game): refactor GameState::onDraw logic
- Replaced direct draw and player update logic with `updateStateByDraw`.
- Simplified card drawing implementation with `handCard->draw`.
2025-11-17 15:24:40 +08:00
Kieran Kihn
b8761d1809 fix(game): refactor ServerPlayerState and update ServerGameState::updateStateByCard logic
- Replaced `handCard_` with `handCard` in `ServerPlayerState`.
- Updated `updateStateByCard` in `ServerGameState` to handle card validation and player actions.
- Made `updateStateByCard` virtual in `GameState`.
2025-11-17 15:24:21 +08:00
Kieran Kihn
2c312343d7 fix(game): ensure updateStateByDraw correctly increments player's card count and advances to the next player 2025-11-17 14:55:38 +08:00
Kieran Kihn
6a148a7e57 fix(game): mark getFront method as [[nodiscard]] 2025-11-17 14:39:34 +08:00
Kieran Kihn
0935b33605 style(game): rename Card constructor parameter from value to type 2025-11-17 14:39:16 +08:00
Kieran Kihn
562ddb25b9 fix(game): remove CardColor::WILD and update wild card handling logic 2025-11-17 14:38:58 +08:00
Kieran Kihn
c3a5a3ee5f feat(game): add getDrawCount method to GameState 2025-11-17 14:01:12 +08:00
Kieran Kihn
6003cadc88 fix(game): use std::move for name in ClientPlayerState constructor 2025-11-17 13:58:55 +08:00
Kieran Kihn
d074feaaa0 fix(game): update updateStateByDraw to correctly adjust player's card count 2025-11-17 13:58:34 +08:00
Kieran Kihn
8ef3962451 refractor(game): simplify nextPlayer logic in GameState 2025-11-17 13:58:13 +08:00
Kieran Kihn
e54bbba4f7 fix(game): update reverse and nextPlayer in GameState to protected 2025-11-17 13:57:30 +08:00
Kieran Kihn
d1fbe5c07a fix(game): preserve currentPlayer index when adding a new player 2025-11-17 12:34:32 +08:00
Kieran Kihn
a025461be8 fix(game): move GameState implementation from .cpp to .h to resolve linkage issues 2025-11-17 12:32:39 +08:00
Kieran Kihn
375abeb2bb fix(game): update Player constructor to take std::string by value instead of reference 2025-11-16 22:06:42 +08:00
Kieran Kihn
7740759f33 fix(game): add construct function of ClientGameState 2025-11-16 22:05:36 +08:00
Kieran Kihn
6b2cb78628 fix(game): add setIsUno for PlayerState 2025-11-16 21:47:23 +08:00
Kieran Kihn
9e6ded8087 fix(game): changed number of cards 2025-11-16 20:53:21 +08:00
Kieran Kihn
7e996931ef fix(game): fixed unused var in CardTile::shuffle and add const for DiscardPile::getFront() 2025-11-16 20:52:40 +08:00
Kieran Kihn
f06fee17cc fix(common): add defination of COMMON::Utils::instance_ 2025-11-16 20:50:42 +08:00
Kieran Kihn
8dbdbb395c feat(game): add PlayerState and GameState 2025-11-16 20:22:19 +08:00
Kieran Kihn
e2a27e4417 refactor(game): renamed handCard_ to handCard in Player 2025-11-16 20:21:35 +08:00
Kieran Kihn
c8c779d711 fix(game): init Deck in construct function by default 2025-11-16 20:18:19 +08:00
Kieran Kihn
49523a0384 fix(game): changed isEmpty of CardTile from protected to public 2025-11-16 19:54:18 +08:00
Kieran Kihn
da0f2160ce feat(game): add canBePlayedOn for Card 2025-11-16 19:52:47 +08:00