tome_lib/session.go

69 lines
2.4 KiB
Go

package tome_lib
import (
"fmt"
"github.com/google/uuid"
)
type SessionCmd string
type SessionResp string
const (
SessionCmdQuery SessionCmd = "query"
SessionCmdJoin = "join"
SessionCmdLeave = "leave"
SessionCmdPlay = "play"
SessionCmdPoll = "poll"
SessionCmdReady = "ready"
SessionCmdLoadDeck = "load_deck"
)
const (
SessionRespFound SessionResp = "found"
SessionRespJoined1 = "joined p1"
SessionRespJoined2 = "joined p2"
SessionRespReady = "game ready"
SessionRespJoinError = "join error"
SessionRespLeft = "left"
SessionRespPlayed = "played"
SessionRespDeckLoaded = "deck loaded"
SessionRespError = "generic error"
SessionRespLoadDeckError = "load deck error"
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"`
Data string `json:"data,omitempty"`
}
func (s *SessionCommand) String() string {
return fmt.Sprintf("%v %v %v %v\n", s.ID, s.Command, s.GameCommand, s.Data)
}
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)
}