commit c71d989cdd34685c0f7d339cdbd84e31e5a5017b
parent 4090c080e3a6a33eba6bed03372212f6ceeedf22
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 18 Dec 2023 04:31:06 -0500
cleanup
Diffstat:
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -233,10 +233,11 @@ func (g *Ongoing) computeWinners() (winner []GameResult) {
continue
}
- p.Cards.RLock()
- playerCard1 := (*p.Cards.Val())[0].Name
- playerCard2 := (*p.Cards.Val())[1].Name
- p.Cards.RUnlock()
+ var playerCard1, playerCard2 string
+ p.Cards.RWith(func(pCards *[]PlayerCard) {
+ playerCard1 = (*pCards)[0].Name
+ playerCard2 = (*pCards)[1].Name
+ })
if len(g.CommunityCards) != 5 {
return []GameResult{}
@@ -484,10 +485,11 @@ func showCards(g *PokerGame, seats []Seat) {
roomTopic := g.RoomID.Topic()
for _, p := range ongoing.Players {
if !p.Folded.Load() {
- p.Cards.RLock()
- firstCard := (*p.Cards.Val())[0]
- secondCard := (*p.Cards.Val())[1]
- p.Cards.RUnlock()
+ var firstCard, secondCard PlayerCard
+ p.Cards.RWith(func(pCards *[]PlayerCard) {
+ firstCard = (*pCards)[0]
+ secondCard = (*pCards)[1]
+ })
seatData := seats[p.SeatIdx]
if p.SeatIdx == 0 {
seatData.Left -= 30
@@ -553,10 +555,14 @@ func execBettingRound(g *PokerGame, skip int, minBet database.PokerChip) bool {
foldPlayer := func(p *PokerPlayer) {
p.Folded.Store(true)
- p.Cards.RLock()
- evt1 := PokerEvent{ID: "card" + itoa((*p.Cards.Val())[0].Idx), Name: "", Idx: (*p.Cards.Val())[0].Idx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
- evt2 := PokerEvent{ID: "card" + itoa((*p.Cards.Val())[1].Idx), Name: "", Idx: (*p.Cards.Val())[1].Idx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
- p.Cards.RUnlock()
+
+ var firstCardIdx, secondCardIdx int
+ p.Cards.RWith(func(pCards *[]PlayerCard) {
+ firstCardIdx = (*pCards)[0].Idx
+ secondCardIdx = (*pCards)[1].Idx
+ })
+ evt1 := PokerEvent{ID: "card" + itoa(firstCardIdx), Name: "", Idx: firstCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
+ evt2 := PokerEvent{ID: "card" + itoa(secondCardIdx), Name: "", Idx: secondCardIdx, Top: BurnStackY, Left: BurnStackX, Angle: "0deg", Reveal: false}
PokerPubSub.Pub(roomTopic, evt1)
PokerPubSub.Pub(roomTopic, evt2)
ongoing.AddEvent(evt1, evt2)