Documentation ¶
Index ¶
- Variables
- type AutoServer
- type Car
- type ChatMessage
- type ChatMessageType
- type Client
- func (c *Client) AllPlaylist() (*PlaylistState, error)
- func (c *Client) Chat(playerToken, message string) error
- func (c *Client) Link(playerGUID string) (string, error)
- func (c *Client) LinkSession(linkCode string) (string, error)
- func (c *Client) Links() (*Links, error)
- func (c *Client) PlayerGUID(session string) (string, error)
- func (c *Client) Playlist(start, count int) (*PlaylistState, error)
- func (c *Client) ServerChat(message string) error
- func (c *Client) SetPrivateToken(privToken string)
- func (c *Client) Summary() (*Summary, error)
- func (c *Client) WithContext(ctx context.Context) *Client
- type ErrStatusCode
- type FinishType
- type Level
- type LevelCompatibilityInfo
- type Links
- type ObservedState
- type Observer
- type Player
- type PlayerState
- type Playlist
- type PlaylistState
- type Server
- type Summary
- type VoteCommands
Constants ¶
This section is empty.
Variables ¶
var ErrLinkCodeNotFound = errors.New("link code not found")
ErrLinkCodeNotFound is returned when the link code cannot be found. It is returned by LinkSession.
Functions ¶
This section is empty.
Types ¶
type AutoServer ¶
type AutoServer struct { IdleTimeout int64 LevelTimeout int64 AdvanceWhenStartingPlayersFinish bool WelcomeMessage string LevelEndTime float64 StartingPlayerGuids []string }
AutoServer is part of Summary.
type Car ¶
type Car struct { Colors [][4]float32 `json:"CarColors"` Name string `json:"CarName"` Points int Finished bool FinishType FinishType FinishData int Spectator bool Alive bool WingsOpen bool Position []float32 Rotation []float32 Velocity []float32 AngularVelocity []float32 }
Car describes a Player's car in Summary.
func (Car) IsFinished ¶
IsFinished returns true if the car finished normally.
type ChatMessage ¶
type ChatMessage struct { Sender string GUID string `json:"Guid"` Timestamp float64 Chat string Type ChatMessageType Description string }
ChatMessage is part of Summary. It describes a message in the ChatLog.
func (ChatMessage) Time ¶
func (msg ChatMessage) Time() time.Time
Time returns the timestamp in time.Time.
type ChatMessageType ¶
type ChatMessageType string
ChatMessageType is the enumerated type for a message's type.
const ( PlayerCustomMessage ChatMessageType = "PlayerCustom" ServerCustomMessage ChatMessageType = "ServerCustom" ServerVanillaMessage ChatMessageType = "ServerVanilla" PlayerActionMessage ChatMessageType = "PlayerAction" PlayerChatMessage ChatMessageType = "PlayerChatMessage" )
type Client ¶
Client is a Distance Server client with a custom endpoint.
func (*Client) AllPlaylist ¶
func (c *Client) AllPlaylist() (*PlaylistState, error)
AllPlaylist fetches all playlists and automatically paginates.
func (*Client) Chat ¶
Chat sends a message using the given player token obtained from calling Link() and the private Distance token.
func (*Client) LinkSession ¶
LinkSession matches the given link code to a player's GUID and links that GUID to a new session. The session token is returned.
func (*Client) PlayerGUID ¶
PlayerGUID returns the player's GUID from the session string.
func (*Client) Playlist ¶
func (c *Client) Playlist(start, count int) (*PlaylistState, error)
Playlist fetches a single playlist page.
func (*Client) ServerChat ¶
ServerChat sends a message as the server using the private Distance token.
func (*Client) SetPrivateToken ¶
SetPrivateToken sets the private token to use. Endpoints that need the token will automatically use it if needed.
type ErrStatusCode ¶
type ErrStatusCode int
ErrStatusCode is returned if the request has an unexpected status code.
func (ErrStatusCode) Error ¶
func (err ErrStatusCode) Error() string
type FinishType ¶
type FinishType string
const ( NoneFinish FinishType = "None" NormalFinish FinishType = "Normal" DNFFinish FinishType = "DNF" SpectateFinish FinishType = "Spectate" JoinedLateFinish FinishType = "JoinedLate" ViewingReplayFinish FinishType = "ViewingReplay" LeavingLevelFinish FinishType = "LeavingLevel" )
type Level ¶
type Level struct { Index int Name string RelativeLevelPath string WorkshopFileID string `json:"WorkshopFileId"` GameMode string Difficulty string }
Level describes a level in Summary.
func (Level) WorkshopURL ¶
WorkshopURL returns the workshop URL to this level.
type LevelCompatibilityInfo ¶
type LevelCompatibilityInfo struct { LevelCompatibilityID int `json:"LevelCompatibilityId"` HasLevel bool LevelVersion string }
LevelCompatibilityInfo describes the level compatibility information from Summary.
type Links ¶
type Links struct { CodesForward map[string]string // 6-digit link code, UnityPlayer GUID CodesReverse map[string]string // 6-digit link code, Session token Links map[string]string // Session token, UnityPlayer GUID }
Links is the links registry linking players and API sessions.
type ObservedState ¶
type ObservedState struct { Summary *Summary PlaylistState *PlaylistState Links *Links LastRenew time.Time }
ObservedState describes the last observed state.
type Observer ¶
type Observer struct { // OnError is called on a fetch error. By default, it logs to console. OnError func(error) // contains filtered or unexported fields }
Observer observes the server for changes periodically.
func NewObserver ¶
NewObserver creates a new periodic observer.
func (*Observer) Renew ¶
func (obs *Observer) Renew()
Renew queues a renew. It does not wait for the renew to finish.
func (*Observer) State ¶
func (obs *Observer) State() ObservedState
State returns the current observed state. The user must not mutate fields inside the state, as that is racy.
func (*Observer) Stop ¶
func (obs *Observer) Stop()
Stop stops the observer. Calling stop more than once does nothing.
func (*Observer) Subscribe ¶
func (obs *Observer) Subscribe() (<-chan ObservedState, func())
Subscribe subscribes to the current observer. The returned channel will be ticked everytime the observed state is updated. If the returned callback is called, the channel will be closed, and the channel will be unsubscribed.
If the observee fail to observe the next tick, then it is queued once. All consecutive states will be dropped before the buffer is free again.
When the Observer is shut down, its subscribed channels will be closed.
type Player ¶
type Player struct { UnityPlayerGUID string `json:"UnityPlayerGuid"` State PlayerState Stuck bool LevelID int `json:"LevelId"` ReceivedInfo bool Index int Name string JoinedAt float64 ValidatedAt float64 Ready bool Car Car LevelCompatibilityInfo LevelCompatibilityInfo LevelCompatibility string Valid bool IPAddress string `json:"IpAddress"` Port int }
Player describes a player in Summary.
type PlayerState ¶
type PlayerState string
PlayerState describes the current state of a Player in Summary.
const ( PlayerInitializing PlayerState = "Initializing" PlayerInitialized PlayerState = "Initialized" PlayerLoadingLobbyScene PlayerState = "LoadingLobbyScene" PlayerLoadedLobbyScene PlayerState = "LoadedLobbyScene" PlayerSubmittedLobbyInfo PlayerState = "SubmittedLobbyInfo" PlayerWaitingForCompatibilityStatus PlayerState = "WaitingForCompatibilityStatus" PlayerLoadingGameModeScene PlayerState = "LoadingGameModeScene" PlayerLoadedGameModeScene PlayerState = "LoadedGameModeScene" PlayerSubmittedGameModeInfo PlayerState = "SubmittedGameModeInfo" PlayerStartedMode PlayerState = "StartedMode" PlayerCantLoadLevelSoInLobby PlayerState = "CantLoadLevelSoInLobby" )
type PlaylistState ¶
PlaylistState is the state of the server and its playlist.
type Server ¶
type Server struct { CurrentLevelID int64 `json:"CurrentLevelId"` MaxPlayers int64 Port int64 ReportToMasterServer bool MasterServerGameModeOverride string DistanceVersion int64 IsInLobby bool HasModeStarted bool ModeStartTime float64 }
Server describes the server in Summary.
type Summary ¶
type Summary struct { Server Server Level Level ChatLog []ChatMessage Players []Player AutoServer AutoServer VoteCommands VoteCommands }
Summary is the structure of a summary response from /summary.
func (Summary) FindPlayer ¶
FindPlayer finds the player by the given Unity Player GUID string. Nil is returned if no players are found.
type VoteCommands ¶
type VoteCommands struct { SkipThreshold float64 HasSkipped bool ExtendThreshold float64 ExtendTime float64 LeftAt map[string]float64 PlayerVotes map[string]Level AgainstVotes map[string]int SkipVotes []string ExtendVotes []string }
VoteCommands describes the vote commands in Summary.