dkforest

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

commit 23e5b71aa9f2ea00ea6c970b24099076d68e0883
parent 30370f6165c6207e249f36bce954464fbfb8178f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri, 15 Dec 2023 06:20:37 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 24++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -96,8 +96,8 @@ type Ongoing struct { CommunityCards []string WaitTurnEvent PokerWaitTurnEvent WaitTurnEventMtx sync.RWMutex - MainPot atomic.Uint64 CreatedAt time.Time + mainPot atomic.Uint64 } type PokerStandingPlayer struct { @@ -163,6 +163,14 @@ type GameResult struct { Players []*PokerPlayer } +func (g *Ongoing) getMainPot() (out database.PokerChip) { + return database.PokerChip(g.mainPot.Load()) +} + +func (g *Ongoing) setMainPot(v database.PokerChip) { + g.mainPot.Store(uint64(v)) +} + // Get the player index in Ongoing.Players from a seat index (index in PokerGame.Players) // [nil p1 nil nil p2 nil] -> PokerGame.Players // [p1 p2] -> Ongoing.Players @@ -667,7 +675,7 @@ RoundIsSettled: time.Sleep(time.Second) // Calculate what is the max gain all-in players can make - mainPot := database.PokerChip(g.Ongoing.MainPot.Load()) + mainPot := g.Ongoing.getMainPot() for _, p := range newlyAllInPlayers { maxGain := mainPot for _, op := range g.Ongoing.Players { @@ -696,7 +704,7 @@ RoundIsSettled: } PokerPubSub.Pub(roomTopic, PokerMainPotUpdatedEvent{MainPot: mainPot}) - g.Ongoing.MainPot.Store(uint64(mainPot)) + g.Ongoing.setMainPot(mainPot) return playerAlive <= 1 } @@ -901,7 +909,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID RoomID) { END: winners := g.Ongoing.computeWinners() - mainPot := database.PokerChip(g.Ongoing.MainPot.Load()) + mainPot := g.Ongoing.getMainPot() playersGain, rake := processPot(winners, mainPot, collectRake) var winnersStr, winnerHand string @@ -940,7 +948,7 @@ END: tx.Commit() } - g.Ongoing.MainPot.Store(0) + g.Ongoing.setMainPot(0) PokerPubSub.Pub(roomTopic, GameIsDoneEvent{Winner: winnersStr, WinnerHand: winnerHand}) newLogEvent(g, roomLogsTopic, fmt.Sprintf("-- Game ended --")) @@ -1543,11 +1551,11 @@ func buildCardsHtml() (html string) { func buildMainPotHtml(g *PokerGame) string { html := `<div id="mainPot"></div>` - mainPot := 0 + mainPot := uint64(0) if g.Ongoing != nil { - mainPot = int(g.Ongoing.MainPot.Load()) + mainPot = uint64(g.Ongoing.getMainPot()) } - html += `<style>#mainPot:before { content: "Pot: ` + itoa(mainPot) + `"; }</style>` + html += `<style>#mainPot:before { content: "Pot: ` + itoa1(mainPot) + `"; }</style>` return html }