Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
stryan | 7447fc8a59 | |
stryan | 88c66f455c | |
stryan | 785936fada | |
stryan | 469c6606a3 | |
stryan | 9e34cab257 |
|
@ -67,7 +67,15 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
|
|||
resp := m.Join(cmd.ID)
|
||||
if m.p1 != uuid.Nil && m.p2 != uuid.Nil {
|
||||
log.Printf("Starting game for %v and %v\n", m.p1, m.p2)
|
||||
m.Game = tome_game.NewGame()
|
||||
d1 := []int{}
|
||||
d2 := []int{}
|
||||
if m.p1Deck != nil {
|
||||
d1 = m.p1Deck
|
||||
}
|
||||
if m.p2Deck != nil {
|
||||
d2 = m.p2Deck
|
||||
}
|
||||
m.Game = tome_game.NewGame(d1, d2)
|
||||
m.Active = true
|
||||
}
|
||||
return &SessionCommandResult{
|
||||
|
@ -97,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) {
|
||||
|
|
6
go.mod
6
go.mod
|
@ -3,7 +3,11 @@ module git.saintnet.tech/tomecraft/tome_server
|
|||
go 1.16
|
||||
|
||||
require (
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.1
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.5
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.3
|
||||
github.com/google/uuid v1.3.0
|
||||
)
|
||||
|
||||
replace git.saintnet.tech/tomecraft/tome_game => ../tome_game
|
||||
replace git.saintnet.tech/tomecraft/tome_lib => ../tome_lib
|
||||
|
||||
|
|
17
go.sum
17
go.sum
|
@ -2,8 +2,16 @@ git.saintnet.tech/tomecraft/tome_game v0.0.0-20211001174426-36013e0b8925 h1:Td26
|
|||
git.saintnet.tech/tomecraft/tome_game v0.0.0-20211001174426-36013e0b8925/go.mod h1:mwjKGgwOXGgviCbrtgk0yFRVyIwi8LQWELIOQfV2KlE=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.0 h1:lX+nGeshZiM69aOdvaSYr4GT+Im+m/6VxdY8MY9oobc=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.0/go.mod h1:o+aG3K2HNczRR+u7YlUiRmtukHLcrYTO12MiqGERAyY=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.1-0.20211004155409-e8ea424a5e68 h1:3hEhdispzgd/qERuo9NEA+BOwyiuQrs8YvslJKK+9Ow=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.1-0.20211004155409-e8ea424a5e68/go.mod h1:o+aG3K2HNczRR+u7YlUiRmtukHLcrYTO12MiqGERAyY=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.1 h1:oAW/VjrpdFQ1msVml255Fo0CJ+FWQjaGitZLQZbaMY8=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.1/go.mod h1:NvCnRvwYVZh5Qy65QxjEAaGZrnDM9bD+FlGb6oZV7y4=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.2-0.20211007173712-596291bbf881 h1:igUMSriLf7UKLcrQLQjbwkOuuqQglxFXF55l5C4mrGk=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.2-0.20211007173712-596291bbf881/go.mod h1:NvCnRvwYVZh5Qy65QxjEAaGZrnDM9bD+FlGb6oZV7y4=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.3 h1:/zihJ5eZnk9LWahll1LyPnR/OLUbSvPRW0L73SBKZ08=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.3/go.mod h1:NvCnRvwYVZh5Qy65QxjEAaGZrnDM9bD+FlGb6oZV7y4=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.5 h1:YWpBR3qgUQxpfzo2FwLUOl8PYohgNdl/VhX+/JGFvSQ=
|
||||
git.saintnet.tech/tomecraft/tome_game v0.1.5/go.mod h1:NvCnRvwYVZh5Qy65QxjEAaGZrnDM9bD+FlGb6oZV7y4=
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.0 h1:c+AMtXgLKUFErrYFx7g8M2zVcrHUwLRY18v/+N8nn2I=
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.0/go.mod h1:Jekqa9ojNDOrcO1aL0IWKuhCQSE5+MNHVcYtTWA6uko=
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.1 h1:WAX/9oQxkZeftWvy/dow00XUO+ZCp0/yOStCSL+T3nE=
|
||||
|
@ -12,5 +20,14 @@ git.saintnet.tech/tomecraft/tome_lib v0.1.2 h1:S2BHgsWBGFv9fy+qBHuKXv0kcjT7VP/7g
|
|||
git.saintnet.tech/tomecraft/tome_lib v0.1.2/go.mod h1:Jekqa9ojNDOrcO1aL0IWKuhCQSE5+MNHVcYtTWA6uko=
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.3 h1:JHW5ozFDfikLcRakAUSX+xxXlwNb4nmlcl8/ja7dKAo=
|
||||
git.saintnet.tech/tomecraft/tome_lib v0.1.3/go.mod h1:Jekqa9ojNDOrcO1aL0IWKuhCQSE5+MNHVcYtTWA6uko=
|
||||
github.com/alvaroloes/enumer v1.1.2 h1:5khqHB33TZy1GWCO/lZwcroBFh7u+0j40T83VUbfAMY=
|
||||
github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT0m65DJ+Wo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
|
|
55
session.go
55
session.go
|
@ -1,7 +1,8 @@
|
|||
package coordinator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
. "git.saintnet.tech/tomecraft/tome_game"
|
||||
|
@ -14,6 +15,8 @@ type Session struct {
|
|||
p1 uuid.UUID
|
||||
p2 uuid.UUID
|
||||
pMap map[uuid.UUID]int
|
||||
p1Deck []int
|
||||
p2Deck []int
|
||||
Active bool
|
||||
Game *Game
|
||||
Watcher chan bool
|
||||
|
@ -80,29 +83,35 @@ func (s *Session) Play(id uuid.UUID, cmd *Command) *CommandResult {
|
|||
return res
|
||||
}
|
||||
|
||||
func (s *Session) LoadDeck(id uuid.UUID, data string) SessionResp {
|
||||
var deck []int
|
||||
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 s.Game == nil {
|
||||
log.Println("attmpted to load deck before game created")
|
||||
return SessionRespError
|
||||
}
|
||||
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
|
||||
}
|
||||
return SessionRespDeckLoaded
|
||||
}
|
||||
|
||||
func (s *Session) PlayerIn(id uuid.UUID) bool {
|
||||
_, exists := s.pMap[id]
|
||||
return exists
|
||||
}
|
||||
|
||||
type SessionCommand struct {
|
||||
ID uuid.UUID `json:"player_id"`
|
||||
MatchID uuid.UUID `json:"match_id"`
|
||||
Command SessionCmd `json:"command"`
|
||||
GameCommand *Command `json:"game_command,omitempty"`
|
||||
}
|
||||
|
||||
func (s *SessionCommand) String() string {
|
||||
return fmt.Sprintf("%v %v %v\n", s.ID, s.Command, s.GameCommand)
|
||||
}
|
||||
|
||||
type SessionCommandResult struct {
|
||||
ID uuid.UUID `json:"player_id"`
|
||||
MatchID uuid.UUID `json:"match_id"`
|
||||
Result SessionResp `json:"result"`
|
||||
GameResult *CommandResult `json:"game_result,omitempty"`
|
||||
}
|
||||
|
||||
func (s *SessionCommandResult) String() string {
|
||||
return fmt.Sprintf("%v %v %v\n", s.ID, s.Result, s.GameResult)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue