dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit bf71235b90ab70b23bc2604963fd7d663cddd1b8
parent abc6f36b415b41b5a4f94931835c957bb2f3f6c6
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu,  7 Dec 2023 04:08:34 -0500

prevent multiple deal

Diffstat:
Mpkg/web/handlers/poker/poker.go | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -120,6 +120,7 @@ type PokerGame struct { bigBlindIdx int underTheGunIdx int DealerIdxMtx sync.RWMutex + IsGameStarted atomic.Bool IsGameDone atomic.Bool IsGameOver atomic.Bool } @@ -703,6 +704,7 @@ END: // Wait a minimum of X seconds before allowing a new game time.Sleep(MinTimeAfterGame * time.Second) g.IsGameOver.Store(true) + g.IsGameStarted.Store(false) fmt.Println("GAME IS OVER") } @@ -714,7 +716,10 @@ func cardToPokerCard(name string) string { func (g *PokerGame) Deal(db *database.DkfDB, roomID string, authUser *database.User) { roomTopic := "room_" + roomID roomUserTopic := "room_" + roomID + "_" + authUser.Username.String() - + if !g.IsGameStarted.CompareAndSwap(false, true) { + PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: "game already ongoing"}) + return + } if g.Ongoing != nil && !g.IsGameOver.Load() { PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: "game already ongoing"}) return