commit ed9d08ba17f8c99acb995940adda8c8292008d8e
parent 4df79ee89a7ee84f322a69270a20a1e18a4e4ec8
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 19 Dec 2023 11:46:10 -0500
cleanup
Diffstat:
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -45,10 +45,36 @@ func NewPoker() *Poker {
return p
}
+func (p *Poker) GetGame(roomID RoomID) *PokerGame {
+ p.Lock()
+ defer p.Unlock()
+ g, found := PokerInstance.games[roomID]
+ if !found {
+ return nil
+ }
+ return g
+}
+
+func (p *Poker) GetOrCreateGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
+ pokerTableMinBet database.PokerChip, pokerTableIsTest bool) *PokerGame {
+ p.Lock()
+ defer p.Unlock()
+ g, found := p.games[roomID]
+ if !found {
+ g = p.createGame(db, roomID, pokerTableID, pokerTableMinBet, pokerTableIsTest)
+ }
+ return g
+}
+
func (p *Poker) CreateGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
pokerTableMinBet database.PokerChip, pokerTableIsTest bool) *PokerGame {
p.Lock()
defer p.Unlock()
+ return p.createGame(db, roomID, pokerTableID, pokerTableMinBet, pokerTableIsTest)
+}
+
+func (p *Poker) createGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
+ pokerTableMinBet database.PokerChip, pokerTableIsTest bool) *PokerGame {
g := p.newGame(db, roomID, pokerTableID, pokerTableMinBet, pokerTableIsTest)
p.games[roomID] = g
return g
@@ -71,28 +97,6 @@ func (p *Poker) newGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
return g
}
-func (p *Poker) GetOrCreateGame(db *database.DkfDB, roomID RoomID, pokerTableID int64,
- pokerTableMinBet database.PokerChip, pokerTableIsTest bool) *PokerGame {
- p.Lock()
- defer p.Unlock()
- g, found := p.games[roomID]
- if !found {
- g = p.newGame(db, roomID, pokerTableID, pokerTableMinBet, pokerTableIsTest)
- p.games[roomID] = g
- }
- return g
-}
-
-func (p *Poker) GetGame(roomID RoomID) *PokerGame {
- p.Lock()
- defer p.Unlock()
- g, found := PokerInstance.games[roomID]
- if !found {
- return nil
- }
- return g
-}
-
type playerEvent struct {
UserID database.UserID
Call bool