dkforest

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

commit 87d7d77ad07de136d97b9a52908f4fad652cc4f1
parent 4e48b22fc3e0db5f3c0f50b3a8e91784ea557c4c
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri, 15 Dec 2023 04:38:10 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 55++++++++++++++++++++++++++++++-------------------------
1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -364,10 +364,11 @@ func (g *PokerGame) UnSitPlayer(db *database.DkfDB, roomID string, authUser *dat return errors.New("player is not sit") } -func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *PokerStandingPlayer, idx int) error { +func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, standingPlayer *PokerStandingPlayer, idx int) error { roomTopic := "room_" + roomID + standingPlayerUsername := standingPlayer.Username - user, err := db.GetUserByUsername(player.Username) + user, err := db.GetUserByUsername(standingPlayerUsername) if err != nil { return err } @@ -387,7 +388,7 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke tx.Commit() if g.Ongoing != nil { - if player := g.Ongoing.GetPlayer(player.Username); player != nil { + if player := g.Ongoing.GetPlayer(standingPlayerUsername); player != nil { select { case g.PlayersEventCh <- PlayerEvent{Player: player.Username, Unsit: true}: default: @@ -517,7 +518,8 @@ OUTER: for { // Repeat until all players have played playerToPlayIdx = (playerToPlayIdx + 1) % len(g.Ongoing.Players) p := g.Ongoing.Players[playerToPlayIdx] - roomUserTopic := "room_" + roomID + "_" + p.Username.String() + pUsername := p.Username + roomUserTopic := "room_" + roomID + "_" + pUsername.String() if playerToPlayIdx == lastRaisePlayerIdx { break @@ -558,7 +560,7 @@ OUTER: g.Ongoing.AddEvent(evt1, evt2) //PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx}) - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto fold", p.Username)) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto fold", pUsername)) playerAlive-- if playerAlive == 1 { @@ -566,7 +568,7 @@ OUTER: } break LOOP } - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto check", p.Username)) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto check", pUsername)) break LOOP } @@ -578,7 +580,7 @@ OUTER: continue } - if evt.Player != p.Username { + if evt.Player != pUsername { continue } @@ -594,7 +596,7 @@ OUTER: g.Ongoing.AddEvent(evt1, evt2) //PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx}) - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s fold", p.Username)) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s fold", pUsername)) playerAlive-- if playerAlive == 1 { @@ -607,16 +609,16 @@ OUTER: PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) continue } - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", p.Username)) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", pUsername)) } else if evt.Call { bet := utils.MinInt(minBet-p.Bet, p.Cash) if bet == 0 { - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", p.Username)) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", pUsername)) } else { p.doBet(db, bet, g.PokerTableID) - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) - logMsg := fmt.Sprintf("%s call (%d)", p.Username, bet) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: pUsername, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + logMsg := fmt.Sprintf("%s call (%d)", pUsername, bet) if p.isAllIn() { logMsg += " (all-in)" newlyAllInPlayers = append(newlyAllInPlayers, p) @@ -631,8 +633,8 @@ OUTER: } minBet = p.Bet + bet p.doBet(db, bet, g.PokerTableID) - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) - logMsg := fmt.Sprintf("%s all-in (%d)", p.Username, bet) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: pUsername, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + logMsg := fmt.Sprintf("%s all-in (%d)", pUsername, bet) if p.isAllIn() { newlyAllInPlayers = append(newlyAllInPlayers, p) } @@ -662,8 +664,8 @@ OUTER: } minBet = p.Bet + bet p.doBet(db, bet, g.PokerTableID) - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) - logMsg := fmt.Sprintf("%s bet %d", p.Username, bet) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: pUsername, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + logMsg := fmt.Sprintf("%s bet %d", pUsername, bet) if p.isAllIn() { logMsg += " (all-in)" newlyAllInPlayers = append(newlyAllInPlayers, p) @@ -748,10 +750,11 @@ func dealPlayersCards(g *PokerGame, roomTopic string, seats []Seat, idx *int) { var card string for cardIdx := 1; cardIdx <= NbCardsPerPlayer; cardIdx++ { for _, p := range g.Ongoing.Players { + pUsername := p.Username if p.isAllIn() { continue } - roomUserTopic := roomTopic + "_" + p.Username.String() + roomUserTopic := roomTopic + "_" + pUsername.String() seatData := seats[p.SeatIdx] time.Sleep(time.Second) if p.Folded.Load() { @@ -779,7 +782,7 @@ func dealPlayersCards(g *PokerGame, roomTopic string, seats []Seat, idx *int) { } evt := PokerEvent{ID: "card" + itoa(*idx), Name: "", Idx: *idx, Top: top, Left: left, Angle: seatData.Angle} - evt1 := PokerEvent{ID: "card" + itoa(*idx), Name: card, Idx: *idx, Top: seatData1.Top, Left: seatData1.Left, Reveal: true, Player: p.Username} + evt1 := PokerEvent{ID: "card" + itoa(*idx), Name: card, Idx: *idx, Top: seatData1.Top, Left: seatData1.Left, Reveal: true, Player: pUsername} PokerPubSub.Pub(roomTopic, evt) PokerPubSub.Pub(roomUserTopic, evt1) @@ -847,18 +850,19 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) { newLogEvent(g, roomLogsTopic, fmt.Sprintf("-- New game --")) p := g.Ongoing.Players[g.smallBlindIdx] + pUsername := p.Username bet := bigBlindBet / 2 p.doBet(db, bet, g.PokerTableID) - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s small blind %d", p.Username, bet)) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: pUsername, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s small blind %d", pUsername, bet)) time.Sleep(time.Second) p = g.Ongoing.Players[g.bigBlindIdx] bet = bigBlindBet p.doBet(db, bet, g.PokerTableID) - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) - newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s big blind %d", p.Username, bet)) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: pUsername, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s big blind %d", pUsername, bet)) time.Sleep(time.Second) @@ -1621,13 +1625,14 @@ func drawSeatsStyle(authUser *database.User, g *PokerGame) string { html += `.takeSeat` + itoa(i+1) + ` { display: block; }` } if p != nil { - if p.Username == authUser.Username { + pUsername := p.Username + if pUsername == authUser.Username { html += `#seat` + itoa(i+1) + ` { border: 2px solid #0d1b8f; }` } - html += `#seat` + itoa(i+1) + ` .inner:before { content: "` + p.Username.String() + `"; }` + html += `#seat` + itoa(i+1) + ` .inner:before { content: "` + pUsername.String() + `"; }` html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.getDisplayCash(g)) + `"; }` if g.Ongoing != nil { - if op := g.Ongoing.GetPlayer(p.Username); op != nil && op.Bet > 0 { + if op := g.Ongoing.GetPlayer(pUsername); op != nil && op.Bet > 0 { html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa2(op.Bet) + `"; }` } }