distance

package
v0.0.0-...-54df73f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (c Car) IsFinished() bool

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

type Client struct {
	Client http.Client
	// contains filtered or unexported fields
}

Client is a Distance Server client with a custom endpoint.

func NewClient

func NewClient(endpoint string) (*Client, error)

NewClient creates a new Distance Server client.

func (*Client) AllPlaylist

func (c *Client) AllPlaylist() (*PlaylistState, error)

AllPlaylist fetches all playlists and automatically paginates.

func (*Client) Chat

func (c *Client) Chat(playerToken, message string) error

Chat sends a message using the given player token obtained from calling Link() and the private Distance token.

func (c *Client) Link(playerGUID string) (string, error)

Link links the given player GUID with a private Distance token.

func (*Client) LinkSession

func (c *Client) LinkSession(linkCode string) (string, error)

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 (c *Client) Links() (*Links, error)

Links fetches the links registry from the server.

func (*Client) PlayerGUID

func (c *Client) PlayerGUID(session string) (string, error)

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

func (c *Client) ServerChat(message string) error

ServerChat sends a message as the server using the private Distance token.

func (*Client) SetPrivateToken

func (c *Client) SetPrivateToken(privToken string)

SetPrivateToken sets the private token to use. Endpoints that need the token will automatically use it if needed.

func (*Client) Summary

func (c *Client) Summary() (*Summary, error)

Summary gets the server summary.

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext creates a copy of the Client with the given context for cancelation and timeout.

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

func (lvl Level) WorkshopURL() string

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 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

func NewObserver(c *Client, dura time.Duration) *Observer

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 Playlist

type Playlist struct {
	Total  int
	Start  int
	Count  int
	Levels []Level
}

Playlist is the server's playlist.

type PlaylistState

type PlaylistState struct {
	CurrentLevelIndex int
	Playlist          Playlist
}

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

func (s Summary) FindPlayer(guid string) *Player

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.

Directories

Path Synopsis
Package markup provides functions to handle Distance chat markup format.
Package markup provides functions to handle Distance chat markup format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL