gameinstance

package
v0.0.0-...-d0596f5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GameInstance

type GameInstance struct {
	Conn network.Connection
	// contains filtered or unexported fields
}

func (*GameInstance) AskInfo

AskInfo sends a PT_ASKINFO request to the game server behind this instance, returning the resulting PT_SERVERINFO and PT_PLAYERINFO packets. A timeout context should always be provided in order to prevent an application hang in the event that the server doesn't respond.

func (*GameInstance) DeserializeSelf

func (gi *GameInstance) DeserializeSelf(data []byte) error

func (*GameInstance) GetID

func (gi *GameInstance) GetID() string

func (*GameInstance) GetPort

func (gi *GameInstance) GetPort() int

func (*GameInstance) HydrateDeserialized

func (gi *GameInstance) HydrateDeserialized(client *client.Client, server *net.UDPConn)

func (*GameInstance) SerializeSelf

func (gi *GameInstance) SerializeSelf() ([]byte, error)

func (*GameInstance) ShouldClose

func (gi *GameInstance) ShouldClose(server UDPServer, ctx context.Context) (bool, error)

ShouldClose returns true if the instance has been active for more than a few minutes and has no players. A timeout context should always be provided in order to prevent an application hang in the event that the server doesn't respond.

func (*GameInstance) Stop

func (gi *GameInstance) Stop() error

type GameInstanceCached

type GameInstanceCached struct {
	ID   string
	Port int
	Addr *net.UDPAddr
}

GameInstanceCached represents the least information needed to reconstruct the state of a full GameInstance.

type GameInstanceManager

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

func NewManager

NewManager creates a new game instance manager. The maxInstances parameter controls how many rooms may exist at one time. Setting this to -1 (not recommended) will effectively uncap the instance limit.

func (*GameInstanceManager) AskInfo

AskInfo sends a PT_ASKINFO request to the game server behind the first available instance we're tracking, returning the resulting PT_SERVERINFO and PT_PLAYERINFO packets. A timeout context should always be provided in order to prevent an application hang in the event that the server doesn't respond.

func (*GameInstanceManager) Close

func (m *GameInstanceManager) Close()

Close stops the reaper loop.

func (*GameInstanceManager) CreateInstance

func (m *GameInstanceManager) CreateInstance(conn *net.UDPConn, startFn func(string)) (*GameInstance, error)

CreateInstance creates a new instance, returning an error if this fails for any reason, including the maximum number of instances already having been created. A callback may be provided that gets called when the instance is started.

func (*GameInstanceManager) DeserializeSelf

func (m *GameInstanceManager) DeserializeSelf(data []byte) error

func (*GameInstanceManager) GetInstance

func (m *GameInstanceManager) GetInstance(addr string) (*GameInstance, error)

GetInstance returns the instance with the specified address, or an error if that instance is not registered with this manager.

func (*GameInstanceManager) GetNumInstances

func (m *GameInstanceManager) GetNumInstances() int

func (*GameInstanceManager) GetOrCreateOpenInstance

func (m *GameInstanceManager) GetOrCreateOpenInstance(conn *net.UDPConn, server UDPServer, startFn func(string)) (*GameInstance, error)

GetOrCreateOpenInstance gets an open game instance, preferring instances with fewer players in order to balance players across all instances. In the event that this isn't possible, a new instance will be created. If we are already tracking our maximum number of instances, an error is returned. A callback may be provided that gets called when the instance is started.

func (*GameInstanceManager) HydrateDeserialized

func (m *GameInstanceManager) HydrateDeserialized(server *net.UDPConn, opts *GameInstanceManagerOptions)

func (*GameInstanceManager) Reaper

func (m *GameInstanceManager) Reaper(server UDPServer, stopFn func(string))

Reaper runs a blocking loop that cleans up dead instances. A callback function may be provided to be called when an instance is stopped. The first argument is the address of the instance.

func (*GameInstanceManager) SerializeSelf

func (m *GameInstanceManager) SerializeSelf() ([]byte, error)

type GameInstanceManagerCached

type GameInstanceManagerCached struct {
	Instances map[string]string
}

GameInstanceManagerCached represents the least information needed to restore the state of a full GameInstanceManager.

type GameInstanceManagerOptions

type GameInstanceManagerOptions struct {
	MaxInstances   int
	DockerImage    string
	GameConfigPath string
	GameAddonPath  string

	// Callback function called when an instance is stopped. The first argument
	// is the address of the instance.
	OnInstanceStop func(string)

	// Callback function called when an instance is started. The first argument
	// is the address of the instance.
	OnInstanceStart func(string)
}

type UDPCallbackKey

type UDPCallbackKey struct {
	Context  string
	GamePort int
	Message  gamenet.Opcode
}

type UDPServer

type UDPServer interface {
	// WaitForMessage waits for a message with the provided opcode from the specified internal port.
	// This function should always be called with a timeout context in order to avoid hanging.
	WaitForInstanceMessage(key *UDPCallbackKey, result chan []byte, err chan error, ctx context.Context)
}

Jump to

Keyboard shortcuts

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