coordinator

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(conf coordinator.Config, log *logger.Logger) (services service.Group)

func NewHTTPServer

func NewHTTPServer(conf coordinator.Config, log *logger.Logger, fnMux func(*httpx.Mux) *httpx.Mux) (*httpx.Server, error)

func RequestToHandshake added in v3.0.5

func RequestToHandshake(data string) (*api.ConnectionRequest[com.Uid], error)

func StateRoom added in v3.0.5

func StateRoom[T api.Id](id T, rid string) api.StatefulRoom[T]

Types

type Connection added in v3.0.5

type Connection interface {
	Disconnect()
	Id() com.Uid
	ProcessPackets(func(api.In[com.Uid]) error) chan struct{}

	Send(api.PT, any) ([]byte, error)
	Notify(api.PT, any)
}

type HasServerInfo added in v3.0.5

type HasServerInfo interface {
	GetServerList() []api.Server
}

type HasUserRegistry added in v3.0.5

type HasUserRegistry interface {
	Find(com.Uid) (*User, bool)
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub(conf coordinator.Config, lib games.GameLibrary, log *logger.Logger) *Hub

func (*Hub) GetServerList

func (h *Hub) GetServerList() (r []api.Server)

type RegionalClient added in v3.0.5

type RegionalClient interface {
	In(region string) bool
}

type User

type User struct {
	Connection
	// contains filtered or unexported fields
}

func NewUser added in v3.0.5

func NewUser(sock *com.Connection, log *logger.Logger) *User

func (*User) Bind added in v3.0.5

func (u *User) Bind(w *Worker)

func (*User) CheckLatency

CheckLatency sends a list of server addresses to the user and waits get back this list with tested ping times for each server.

func (*User) Disconnect

func (u *User) Disconnect()

func (*User) HandleChangePlayer

func (u *User) HandleChangePlayer(rq api.ChangePlayerUserRequest)

func (*User) HandleLoadGame

func (u *User) HandleLoadGame() error

func (*User) HandleQuitGame

func (u *User) HandleQuitGame(rq api.GameQuitRequest[com.Uid])

func (*User) HandleRecordGame

func (u *User) HandleRecordGame(rq api.RecordGameRequest[com.Uid])

func (*User) HandleRequests

func (u *User) HandleRequests(info HasServerInfo, launcher games.Launcher, conf coordinator.Config) chan struct{}

func (*User) HandleSaveGame

func (u *User) HandleSaveGame() error

func (*User) HandleStartGame

func (u *User) HandleStartGame(rq api.GameStartUserRequest, launcher games.Launcher, conf coordinator.Config)

func (*User) HandleToggleMultitap

func (u *User) HandleToggleMultitap()

func (*User) HandleWebrtcAnswer

func (u *User) HandleWebrtcAnswer(rq api.WebrtcAnswerUserRequest)

func (*User) HandleWebrtcIceCandidate

func (u *User) HandleWebrtcIceCandidate(rq api.WebrtcUserIceCandidate)

func (*User) HandleWebrtcInit

func (u *User) HandleWebrtcInit()

func (*User) InitSession

func (u *User) InitSession(wid string, ice []webrtc.IceServer, games []string)

InitSession signals the user that the app is ready to go.

func (*User) SendWebrtcIceCandidate

func (u *User) SendWebrtcIceCandidate(candidate string)

SendWebrtcIceCandidate sends remote ICE candidate back to the user.

func (*User) SendWebrtcOffer

func (u *User) SendWebrtcOffer(sdp string)

SendWebrtcOffer sends SDP offer back to the user.

func (*User) StartGame

func (u *User) StartGame()

StartGame signals the user that everything is ready to start a game.

type Worker

type Worker struct {
	Connection
	RegionalClient

	Addr       string
	PingServer string
	Port       string
	RoomId     string // room reference
	Tag        string
	Zone       string
	// contains filtered or unexported fields
}

func NewWorker added in v3.0.5

func NewWorker(sock *com.Connection, handshake api.ConnectionRequest[com.Uid], log *logger.Logger) *Worker

func (*Worker) ChangePlayer

func (w *Worker) ChangePlayer(id com.Uid, index int) (*api.ChangePlayerResponse, error)

func (*Worker) Disconnect

func (w *Worker) Disconnect()

func (*Worker) FreeSlots

func (s *Worker) FreeSlots()

func (*Worker) HandleCloseRoom

func (w *Worker) HandleCloseRoom(rq api.CloseRoomRequest)

func (*Worker) HandleIceCandidate

func (w *Worker) HandleIceCandidate(rq api.WebrtcIceCandidateRequest[com.Uid], users HasUserRegistry) error

func (*Worker) HandleRegisterRoom

func (w *Worker) HandleRegisterRoom(rq api.RegisterRoomRequest)

func (*Worker) HandleRequests

func (w *Worker) HandleRequests(users HasUserRegistry) chan struct{}

func (*Worker) HasSlot

func (s *Worker) HasSlot() bool

HasSlot checks if the current worker has a free slot to start a new game. Workers support only one game at a time, so it returns true in case if there are no players in the room (worker).

func (*Worker) In

func (w *Worker) In(region string) bool

In say whether some worker from this region (zone). Empty region always returns true.

func (*Worker) LoadGame

func (w *Worker) LoadGame(id com.Uid) (*api.LoadGameResponse, error)

func (*Worker) PrintInfo

func (w *Worker) PrintInfo() string

func (*Worker) QuitGame

func (w *Worker) QuitGame(id com.Uid)

func (*Worker) RecordGame

func (w *Worker) RecordGame(id com.Uid, rec bool, recUser string) (*api.RecordGameResponse, error)

func (*Worker) Reserve

func (s *Worker) Reserve()

Reserve increments user counter of the worker.

func (*Worker) SaveGame

func (w *Worker) SaveGame(id com.Uid) (*api.SaveGameResponse, error)

func (*Worker) StartGame

func (w *Worker) StartGame(id com.Uid, app games.AppMeta, req api.GameStartUserRequest) (*api.StartGameResponse, error)

func (*Worker) TerminateSession

func (w *Worker) TerminateSession(id com.Uid)

func (*Worker) ToggleMultitap

func (w *Worker) ToggleMultitap(id com.Uid)

func (*Worker) UnReserve

func (s *Worker) UnReserve()

UnReserve decrements user counter of the worker.

func (*Worker) WebrtcAnswer

func (w *Worker) WebrtcAnswer(id com.Uid, sdp string)

func (*Worker) WebrtcIceCandidate

func (w *Worker) WebrtcIceCandidate(id com.Uid, can string)

func (*Worker) WebrtcInit

func (w *Worker) WebrtcInit(id com.Uid) (*api.WebrtcInitResponse, error)

Jump to

Keyboard shortcuts

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