commit bf0c9dd11810a57dabbc7d3e45f4dde03f0cf5aa
parent de623b4401e9a688df4f731d792eace572441821
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 6 Dec 2023 06:07:37 -0500
fixes
Diffstat:
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -295,6 +295,7 @@ OUTER:
playerAlive--
if playerAlive == 1 {
+ PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: ""})
break OUTER
}
} else if evt.Check {
@@ -608,20 +609,21 @@ func cardToPokerCard(name string) string {
return r.Replace(name)
}
-func (g *PokerGame) Deal(roomID string) {
+func (g *PokerGame) Deal(roomID string, authUser *database.User) {
roomTopic := "room_" + roomID
+ roomUserTopic := "room_" + roomID + "_" + authUser.Username.String()
- if g.Ongoing != nil {
- if !g.IsGameOver.Load() {
- fmt.Println("game already ongoing")
- return
- }
+ if g.Ongoing != nil && !g.IsGameOver.Load() {
+ PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: "game already ongoing"})
+ return
}
if g.CountSeated() < 2 {
- fmt.Println("need at least 2 players")
+ PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: "need at least 2 players"})
return
}
+ PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: ""})
+
g.IsGameOver.Store(false)
PokerPubSub.Pub(roomTopic, ResetCardsEvent{})
time.Sleep(time.Second)
@@ -723,12 +725,13 @@ func PokerFoldHandler(c echo.Context) error {
func PokerDealHandler(c echo.Context) error {
roomID := c.Param("roomID")
+ authUser := c.Get("authUser").(*database.User)
g := PokerInstance.GetGame(roomID)
if g == nil {
return c.NoContent(http.StatusNotFound)
}
if c.Request().Method == http.MethodPost {
- g.Deal(roomID)
+ g.Deal(roomID, authUser)
}
return c.HTML(http.StatusOK, `<form method="post"><button>Deal</button></form>`)
}