From 88c66f455cff52689c60399d7be5ab731b05dece Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 8 Nov 2021 16:57:58 -0500 Subject: [PATCH] actually use custom decks --- coordinator.go | 22 ++++++++++++++++++++++ session.go | 7 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/coordinator.go b/coordinator.go index 3a12afd..73fb06f 100644 --- a/coordinator.go +++ b/coordinator.go @@ -105,6 +105,28 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult { Result: SessionRespError, } } + case SessionCmdLoadDeck: + m, exists := c.Matches[cmd.MatchID] + if !exists || !m.PlayerIn(cmd.ID) { + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: uuid.Nil, + Result: SessionRespError, + } + } + if m.Game != nil && m.Game.Status != StatusLobby { + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: m.ID, + Result: SessionRespLoadDeckError, + } + } + resp := m.LoadDeck(cmd.ID, cmd.Data) + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: m.ID, + Result: resp, + } case SessionCmdLeave: m, exists := c.Matches[cmd.MatchID] if exists && m.PlayerIn(cmd.ID) { diff --git a/session.go b/session.go index 1a49afb..2f743c6 100644 --- a/session.go +++ b/session.go @@ -2,6 +2,7 @@ package coordinator import ( "encoding/json" + "log" "time" . "git.saintnet.tech/tomecraft/tome_game" @@ -84,18 +85,22 @@ func (s *Session) Play(id uuid.UUID, cmd *Command) *CommandResult { func (s *Session) LoadDeck(id uuid.UUID, data string) SessionResp { var deck []int - err := json.Unmarshal([]byte(data), &data) + err := json.Unmarshal([]byte(data), &deck) if err != nil { + log.Printf("bad deck load error:%v data: %v", err, data) return SessionRespLoadDeckError } valid := ValidateDeck(deck) if !valid { + log.Printf("%v attempted to load invalid deck: %v", id, data) return SessionRespLoadDeckError } if id == s.p1 { s.p1Deck = deck + s.Game.SentinalDeck = LoadDeck(SentinalID, s.p1Deck) } else if id == s.p2 { s.p2Deck = deck + s.Game.ScourgeDeck = LoadDeck(ScourgeID, s.p2Deck) } else { return SessionRespError }