service

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONSENT_EXPIRATION = 30 * 24 * time.Hour
	AUTOEXEC_KEY       = "autoexec-%s"
)
View Source
const (
	DuelPhaseWarmup = iota
	DuelPhaseBattle
	DuelPhaseOvertime
	DuelPhaseDone
)
View Source
const (
	DEMO_KEY = "demo-%s"
	DEMO_TTL = time.Duration(48 * time.Hour)
)
View Source
const (
	UserStatusConnecting = iota
	UserStatusConnected
	UserStatusDisconnected
)
View Source
const (
	CREATE_SERVER_COOLDOWN = time.Duration(10 * time.Second)
)
View Source
const INITIAL_SCRIPT = `` /* 144-byte string literal not displayed */
View Source
const RUN_WAIT_TIMEOUT = 15 * time.Second
View Source
const TUNNEL_MODE = true

Variables

View Source
var (
	DEMO_PATH_REGEX = regexp.MustCompile(`^/api/demo/([\w-]+)$`)
)
View Source
var PURGATORY []byte

Functions

func Compress

func Compress(data []byte) ([]byte, error)

func EncodeDemo

func EncodeDemo(startTime time.Time, messages []RecordedPacket) ([]byte, error)

func EncodeSession

func EncodeSession(startTime time.Time, messages []RecordedPacket) ([]byte, error)

func RecordSession

func RecordSession(ctx context.Context, redis *redis.Client, shouldSave bool, user *User) error

func WriteFile

func WriteFile(path string, data []byte) error

Types

type Cluster

type Cluster struct {

	// Services
	Users *UserOrchestrator
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(
	ctx context.Context,
	serverManager *servers.ServerManager,
	maps *assets.AssetFetcher,
	settings config.ServerSettings,
) *Cluster

func (*Cluster) AnnounceInServer

func (c *Cluster) AnnounceInServer(ctx context.Context, server *servers.GameServer, message string)

func (*Cluster) CreateGame

func (server *Cluster) CreateGame(ctx context.Context, params *CreateParams, user *User) error

func (*Cluster) ForwardGlobalChat

func (server *Cluster) ForwardGlobalChat(ctx context.Context, sender *User, message string)

func (*Cluster) GetClientInfo

func (server *Cluster) GetClientInfo() []*servers.ClientExtInfo

We need client information, so this is not on the ServerManager like GetServerInfo is

func (*Cluster) GetDemo

func (c *Cluster) GetDemo(ctx context.Context, id string) ([]byte, error)

func (*Cluster) GetServerInfo

func (server *Cluster) GetServerInfo() *servers.ServerInfo

func (*Cluster) GetTeamInfo

func (server *Cluster) GetTeamInfo() *servers.TeamInfo

func (*Cluster) GetUptime

func (server *Cluster) GetUptime() int

func (*Cluster) GivePrivateMatchHelp

func (server *Cluster) GivePrivateMatchHelp(ctx context.Context, user *User, gameServer *servers.GameServer)

func (*Cluster) GreetClient

func (server *Cluster) GreetClient(ctx context.Context, user *User)

func (*Cluster) HandleCommand

func (s *Cluster) HandleCommand(ctx context.Context, user *User, command string)

func (*Cluster) HandleTeleport

func (c *Cluster) HandleTeleport(ctx context.Context, user *User, source int32)

func (*Cluster) NotifyClientChange

func (server *Cluster) NotifyClientChange(ctx context.Context, user *User, joined bool)

func (*Cluster) NotifyNameChange

func (c *Cluster) NotifyNameChange(ctx context.Context, user *User, name string)

func (*Cluster) PollDuels

func (server *Cluster) PollDuels(ctx context.Context)

func (*Cluster) PollFromMessages

func (c *Cluster) PollFromMessages(ctx context.Context, user *User)

func (*Cluster) PollServers

func (server *Cluster) PollServers(ctx context.Context)

func (*Cluster) PollToMessages

func (c *Cluster) PollToMessages(ctx context.Context, user *User)

func (*Cluster) PollUser

func (c *Cluster) PollUser(ctx context.Context, user *User)

func (*Cluster) PollUsers

func (server *Cluster) PollUsers(ctx context.Context, newConnections chan ingress.Connection)

func (*Cluster) SendMap

func (c *Cluster) SendMap(ctx context.Context, user *User, name string) error

func (*Cluster) ServeHTTP

func (c *Cluster) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Cluster) Shutdown

func (server *Cluster) Shutdown()

func (*Cluster) StartServers

func (server *Cluster) StartServers(ctx context.Context)

type ConnectionEvent

type ConnectionEvent struct {
	Server *servers.GameServer
}

type CreateParams

type CreateParams struct {
	Map    opt.Option[string]
	Preset opt.Option[string]
	Mode   opt.Option[int]
}

type Duel

type Duel struct {
	Mutex sync.Mutex
	Phase DuelPhase
	Type  config.DuelType

	A *User
	B *User

	Manager  *servers.ServerManager
	Finished chan DuelDone
	// contains filtered or unexported fields
}

func (*Duel) Cleanup

func (d *Duel) Cleanup()

Free up resources and move clients back to their original servers

func (*Duel) Logger

func (d *Duel) Logger() zerolog.Logger

func (*Duel) MonitorClient

func (d *Duel) MonitorClient(
	ctx context.Context,
	user *User,
	oldServer *servers.GameServer,
	cancelMatch context.CancelFunc,
	matchResult chan DuelResult,
)

func (*Duel) PollDeaths

func (d *Duel) PollDeaths(ctx context.Context)

func (*Duel) Respawn

func (d *Duel) Respawn(ctx context.Context, user *User)

func (*Duel) Run

func (d *Duel) Run(ctx context.Context)

type DuelDone

type DuelDone struct {
	Duel   *Duel
	Result DuelResult
}

type DuelPhase

type DuelPhase byte

type DuelQueue

type DuelQueue struct {
	User *User
	Type string
}

type DuelResult

type DuelResult struct {
	Winner       *User
	Loser        *User
	Type         string
	IsDraw       bool
	Disconnected bool
}

type ELO

type ELO struct {
	Rating uint
	Wins   uint
	Draws  uint
	Losses uint
}

func NewELO

func NewELO() *ELO

type ELOState

type ELOState struct {
	Ratings map[string]*ELO
	Mutex   sync.Mutex
}

func NewELOState

func NewELOState(duels []config.DuelType) *ELOState

type Matchmaker

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

func NewMatchmaker

func NewMatchmaker(manager *servers.ServerManager, duelTypes []config.DuelType) *Matchmaker

func (*Matchmaker) Dequeue

func (m *Matchmaker) Dequeue(user *User)

func (*Matchmaker) FindDuelType

func (m *Matchmaker) FindDuelType(name string) opt.Option[config.DuelType]

func (*Matchmaker) NotifyProgress

func (m *Matchmaker) NotifyProgress(queued *QueuedClient)

Inform the client regularly as to how long they've been in the queue.

func (*Matchmaker) Poll

func (m *Matchmaker) Poll(ctx context.Context)

func (*Matchmaker) Queue

func (m *Matchmaker) Queue(user *User, typeName string) error

func (*Matchmaker) ReceiveQueues

func (m *Matchmaker) ReceiveQueues() <-chan DuelQueue

func (*Matchmaker) ReceiveResults

func (m *Matchmaker) ReceiveResults() <-chan DuelResult

type QueuedClient

type QueuedClient struct {
	JoinTime time.Time
	User     *User
	Type     string
	// Valid for the duration of the client being in the queue
	Context context.Context
	Cancel  context.CancelFunc
}

type RecordedPacket

type RecordedPacket struct {
	From   bool
	Time   time.Time
	Packet io.RawPacket
}

func NewPacket

func NewPacket(from bool, packet io.RawPacket) RecordedPacket

type TrackedPacket

type TrackedPacket struct {
	Packet P.Packet
	Error  chan error
}

type User

type User struct {
	*utils.Session

	Id ingress.ClientID
	// Whether the user is connected (or connecting) to a game server
	Status UserStatus
	Name   string

	Connection ingress.Connection

	// Created when the user connects to a server and canceled when they
	// leave, regardless of reason (network or being disconnected by the
	// server)
	// This is NOT the same thing as Client.Connection.SessionContext(), which refers to
	// the lifecycle of the client's ingress connection
	ServerSession utils.Session
	Server        *servers.GameServer
	ServerClient  *gameserver.Client

	ELO *ELOState

	Space *verse.SpaceInstance

	From *P.MessageProxy
	To   *P.MessageProxy

	RawFrom *utils.Topic[io.RawPacket]
	RawTo   *utils.Topic[io.RawPacket]

	Mutex deadlock.RWMutex
	// contains filtered or unexported fields
}

func (*User) AnnounceELO

func (u *User) AnnounceELO()

func (*User) Connect

func (u *User) Connect(server *servers.GameServer) (<-chan bool, error)

func (*User) ConnectToServer

func (u *User) ConnectToServer(server *servers.GameServer, target string, shouldCopy bool, isSpace bool) (<-chan bool, error)

func (*User) ConnectToSpace

func (u *User) ConnectToSpace(server *servers.GameServer, id string) (<-chan bool, error)

func (*User) DelayMessages

func (c *User) DelayMessages()

func (*User) DisconnectFromServer

func (u *User) DisconnectFromServer() error

Mark the client's status as disconnected and cancel its session context. Called both when the client disconnects from ingress AND when the server kicks them out.

func (*User) GetAutoexecKey

func (u *User) GetAutoexecKey() string

func (*User) GetClientNum

func (u *User) GetClientNum() int

func (*User) GetFormattedName

func (u *User) GetFormattedName() string

func (*User) GetFormattedReference

func (u *User) GetFormattedReference() string

func (*User) GetName

func (u *User) GetName() string

func (*User) GetServer

func (u *User) GetServer() *servers.GameServer

func (*User) GetServerInfo

func (u *User) GetServerInfo() P.ServerInfo

func (*User) GetServerName

func (u *User) GetServerName() string

func (*User) GetSessionID

func (u *User) GetSessionID() string

func (*User) GetSpace

func (u *User) GetSpace() *verse.SpaceInstance

func (*User) GetStatus

func (c *User) GetStatus() UserStatus

func (*User) HasCubeScript

func (u *User) HasCubeScript() bool

func (*User) IsAtHome

func (u *User) IsAtHome(ctx context.Context) (bool, error)

func (*User) IsInSpace

func (u *User) IsInSpace() bool

SPAAAAAAAAACE

func (*User) Logger

func (u *User) Logger() zerolog.Logger

func (*User) Message

func (u *User) Message(message string)

func (*User) RawMessage

func (u *User) RawMessage(message string)

func (*User) ReceiveConnections

func (c *User) ReceiveConnections() <-chan ConnectionEvent

func (*User) ReceiveToMessages

func (c *User) ReceiveToMessages() <-chan TrackedPacket

func (*User) Reference

func (u *User) Reference() string

func (*User) Response

func (u *User) Response(ctx context.Context, code P.MessageCode, messages ...P.Message) (P.Message, error)

func (*User) ResponseTimeout

func (u *User) ResponseTimeout(ctx context.Context, timeout time.Duration, code P.MessageCode, messages ...P.Message) (P.Message, error)

ResponseTimeout sends a message for a user and waits for a response of type `code`.

func (*User) RestoreMessages

func (c *User) RestoreMessages()

func (*User) RunCubeScript

func (u *User) RunCubeScript(ctx context.Context, code string) error

func (*User) Send

func (c *User) Send(messages ...P.Message) <-chan error

func (*User) SendChannel

func (c *User) SendChannel(channel uint8, messages ...P.Message) <-chan error

func (*User) SendChannelSync

func (c *User) SendChannelSync(channel uint8, messages ...P.Message) error

func (*User) SendSync

func (c *User) SendSync(messages ...P.Message) error

func (*User) ServerSessionContext

func (u *User) ServerSessionContext() context.Context

func (*User) SetName

func (u *User) SetName(ctx context.Context, name string)

type UserOrchestrator

type UserOrchestrator struct {
	Duels   []config.DuelType
	Users   []*User
	Servers map[*servers.GameServer][]*User
	Mutex   deadlock.RWMutex
}

func NewUserOrchestrator

func NewUserOrchestrator(duels []config.DuelType) *UserOrchestrator

func (*UserOrchestrator) AddUser

func (u *UserOrchestrator) AddUser(ctx context.Context, connection ingress.Connection) (*User, error)

func (*UserOrchestrator) FindUser

func (u *UserOrchestrator) FindUser(id ingress.ClientID) *User

func (*UserOrchestrator) PollUser

func (u *UserOrchestrator) PollUser(ctx context.Context, user *User)

func (*UserOrchestrator) RemoveUser

func (u *UserOrchestrator) RemoveUser(user *User)

type UserStatus

type UserStatus uint8

The status of the user's connection to their game server.

Jump to

Keyboard shortcuts

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