dkforest

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

commit 32f0c12d1b7fccce12d468288b1cb44ed224c5fa
parent 7896720e7532752ed679ff50b15886d02a38abd5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 23:37:46 -0500

publish deck hash when starting game

Diffstat:
Mpkg/web/handlers/poker.go | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -186,6 +186,8 @@ func (g *PokerGame) Deal(roomID string) { g.Ongoing.Events = append(g.Ongoing.Events, evt) } + PokerPubSub.Pub(myTopic, GameStartedEvent{DeckHash: utils.MD5([]byte(strings.Join(g.Ongoing.Deck, "")))}) + // Deal cards for j := 1; j <= 2; j++ { for i, p := range g.Ongoing.Players { @@ -304,6 +306,10 @@ type PokerEvent struct { Angle string } +type GameStartedEvent struct { + DeckHash string +} + type GameIsDoneEvent struct { DeckStr string } @@ -532,7 +538,7 @@ func PokerHandler(c echo.Context) error { if g.Ongoing != nil { deckStr = strings.Join(g.Ongoing.Deck, "") } - deckSha256 := utils.Sha256([]byte(deckStr)) + deckMd5 := utils.MD5([]byte(deckStr)) quit := hutils.CloseSignalChan(c) roomTopic := "room_" + roomID @@ -697,7 +703,7 @@ body { actions := `<iframe src="/poker/` + roomID + `/deal" id="dealBtn"></iframe>` actions += `<iframe src="/poker/` + roomID + `/unsit" id="unSitBtn"></iframe>` send(actions) - deckHash := deckSha256 + deckHash := deckMd5 send(`<div id="countdown">CD</div>`) if g.Ongoing != nil { drawCountDownStyle(g.Ongoing.WaitTurnEvent) @@ -706,7 +712,8 @@ body { if g.IsGameDone { send(`<style>#deckStr:before { content: "` + deckStr + `"; }</style>`) } - send(`<div>` + deckHash + `</div>`) + send(`<div id="deckHash"></div>`) + send(`<style>#deckHash:before { content: "` + deckHash + `"; }</style>`) if g.Ongoing != nil { for _, payload := range g.Ongoing.Events { send(getPokerEventHtml(payload, "0s")) @@ -734,6 +741,11 @@ Loop: c.Response().Flush() continue + } else if evt, ok := payload.(GameStartedEvent); ok { + send(`<style>#deckHash:before { content: "` + evt.DeckHash + `"; }</style>`) + c.Response().Flush() + continue + } else if evt, ok := payload.(GameIsDoneEvent); ok { send(`<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>`) c.Response().Flush()