Fix betting system to prevent overlapping bets and validate in-game bet increases#356
Fix betting system to prevent overlapping bets and validate in-game bet increases#356
Conversation
…t increases Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
|
Ok this is not bad @copilot but I don't like this part: This is not clean at all. |
Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
I've refactored the bet validation system as requested. The changes include: New Architecture:
Key Improvements:
Example Usage: // In Blackjack.cs DoubleDown method:
await TryIncreaseBetAsync(player, player.Bet); // Validates & doubles betThe bet validator is dependency-injected when creating game sessions, keeping the architecture clean while enabling proper validation across all active games. Commit: ab69b51 |
This PR addresses critical issues in the casino betting system where players could exploit the delayed token deduction mechanism.
Issues Fixed
1. Multiple Active Games Exploit
Previously, a player with 1000 tokens could join multiple games simultaneously and bet their full balance in each game:
2. In-Game Bet Increases Without Validation
Actions like Blackjack's DoubleDown could increase bets beyond available balance:
Solution
Multi-Game Bet Validation
GetCommittedTokens()method to calculate tokens locked in other active gamesSetBet()to validate against available tokens:user.Tokens - committedTokensNotStartedandInProgressstates (finished games don't lock tokens)In-Game Bet Increase Validation
ValidateBetIncrease()method for validating bet increases during gameplayEnhanced User Experience
Example After Fix
The implementation follows the suggested approach of having GameService check active games and account for committed tokens when validating new bets.
Fixes #347.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.