commit 829e13f78ed4322a3cb0d961599e4adaea3007c9
parent 34cd39b25133e1620d7a501fa7b3a00a60bd0d82
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 6 Dec 2023 04:45:45 -0500
cleanup
Diffstat:
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -184,6 +184,12 @@ func NewOngoing(g *PokerGame) *Ongoing {
return &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}}
}
+func newLogEvent(g *PokerGame, roomLogsTopic, msg string) {
+ logEvt := LogEvent{Message: msg}
+ PokerPubSub.Pub(roomLogsTopic, logEvt)
+ g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+}
+
// Return either or not the game ended because only 1 player left playing
func waitPlayersActionFn(g *PokerGame, roomID string) bool {
roomTopic := "room_" + roomID
@@ -241,10 +247,7 @@ OUTER:
g.Ongoing.Events = append(g.Ongoing.Events, evt1, evt2)
//PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx})
-
- logEvt := LogEvent{Message: fmt.Sprintf("%s auto fold", p.Username)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto fold", p.Username))
playerAlive--
if playerAlive == 1 {
@@ -252,9 +255,7 @@ OUTER:
}
break LOOP
}
- logEvt := LogEvent{Message: fmt.Sprintf("%s auto check", p.Username)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto check", p.Username))
break LOOP
}
@@ -271,10 +272,7 @@ OUTER:
g.Ongoing.Events = append(g.Ongoing.Events, evt1, evt2)
//PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx})
-
- logEvt := LogEvent{Message: fmt.Sprintf("%s fold", p.Username)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s fold", p.Username))
playerAlive--
if playerAlive == 1 {
@@ -286,10 +284,7 @@ OUTER:
PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg})
continue
}
-
- logEvt := LogEvent{Message: fmt.Sprintf("%s check", p.Username)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", p.Username))
} else if evt.Call {
bet := minBet - p.Bet
@@ -303,10 +298,7 @@ OUTER:
p.Cash -= bet
}
PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: i, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash})
-
- logEvt := LogEvent{Message: fmt.Sprintf("%s call", p.Username)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s call", p.Username))
} else if evt.Bet > 0 {
if (p.Bet + evt.Bet) < minBet {
@@ -321,10 +313,7 @@ OUTER:
p.Bet += evt.Bet
p.Cash -= evt.Bet
PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: i, Player: p.Username, Bet: evt.Bet, TotalBet: p.Bet, Cash: p.Cash})
-
- logEvt := LogEvent{Message: fmt.Sprintf("%s bet %d", p.Username, evt.Bet)}
- PokerPubSub.Pub(roomLogsTopic, logEvt)
- g.Ongoing.LogEvents = append(g.Ongoing.LogEvents, logEvt)
+ newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s bet %d", p.Username, evt.Bet))
} else {
continue