2021-10-01 12:43:55 -04:00
|
|
|
package tome_lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SessionCmd string
|
|
|
|
type SessionResp string
|
|
|
|
|
|
|
|
const (
|
2021-11-08 15:01:07 -05:00
|
|
|
SessionCmdQuery SessionCmd = "query"
|
|
|
|
SessionCmdJoin = "join"
|
|
|
|
SessionCmdLeave = "leave"
|
|
|
|
SessionCmdPlay = "play"
|
|
|
|
SessionCmdPoll = "poll"
|
|
|
|
SessionCmdReady = "ready"
|
|
|
|
SessionCmdLoadDeck = "load_deck"
|
2021-10-01 12:43:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
SessionRespFound SessionResp = "found"
|
|
|
|
SessionRespJoined1 = "joined p1"
|
|
|
|
SessionRespJoined2 = "joined p2"
|
|
|
|
SessionRespReady = "game ready"
|
|
|
|
SessionRespJoinError = "join error"
|
|
|
|
SessionRespLeft = "left"
|
|
|
|
SessionRespPlayed = "played"
|
2021-11-08 15:01:07 -05:00
|
|
|
SessionRespDeckLoaded = "deck loaded"
|
2021-10-01 12:43:55 -04:00
|
|
|
SessionRespError = "generic error"
|
2021-11-08 15:01:07 -05:00
|
|
|
SessionRespLoadDeckError = "load deck error"
|
2021-10-01 12:43:55 -04:00
|
|
|
SessionRespBroadcastSenTurn = "Sentinal turn"
|
|
|
|
SessionRespBroadcastScoTrun = "Scourge turn"
|
|
|
|
SessionRespBroadcastSenWin = "Sentinal wins"
|
|
|
|
SessionRespBroadcastScoWin = "Scourge wins"
|
|
|
|
SessionRespBroadcastUpdate = "update"
|
|
|
|
SessionRespBroadcastSenJoin = "Sentinal joined"
|
|
|
|
SessionRespBroadcastScoJoin = "Scourge joined"
|
|
|
|
SessionRespBroadcastSenReady = "Sentinal player is ready"
|
|
|
|
SessionRespBroadcastScoReady = "Scourge player is ready"
|
|
|
|
SessionRespBroadcastSenLeft = "Sentinal player has left"
|
|
|
|
SessionRespBroadcastScoLeft = "Scourge player has left"
|
|
|
|
SessionRespBroadcastNone = ""
|
|
|
|
)
|
|
|
|
|
|
|
|
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"`
|
2021-11-08 15:01:07 -05:00
|
|
|
Data string `json:"data,omitempty"`
|
2021-10-01 12:43:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SessionCommand) String() string {
|
2021-11-08 15:01:07 -05:00
|
|
|
return fmt.Sprintf("%v %v %v %v\n", s.ID, s.Command, s.GameCommand, s.Data)
|
2021-10-01 12:43:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|