Documentation ¶
Index ¶
- type GameInstance
- func (gi *GameInstance) AskInfo(askInfo *gamenet.AskInfoPak, server UDPServer, ctx context.Context) (*gamenet.ServerInfoPak, *gamenet.PlayerInfoPak, error)
- func (gi *GameInstance) DeserializeSelf(data []byte) error
- func (gi *GameInstance) GetID() string
- func (gi *GameInstance) GetPort() int
- func (gi *GameInstance) HydrateDeserialized(client *client.Client, server *net.UDPConn)
- func (gi *GameInstance) SerializeSelf() ([]byte, error)
- func (gi *GameInstance) ShouldClose(server UDPServer, ctx context.Context) (bool, error)
- func (gi *GameInstance) Stop() error
- type GameInstanceCached
- type GameInstanceManager
- func (m *GameInstanceManager) AskInfo(askInfo *gamenet.AskInfoPak, server UDPServer, ctx context.Context) (*gamenet.ServerInfoPak, *gamenet.PlayerInfoPak, error)
- func (m *GameInstanceManager) Close()
- func (m *GameInstanceManager) CreateInstance(conn *net.UDPConn, startFn func(string)) (*GameInstance, error)
- func (m *GameInstanceManager) DeserializeSelf(data []byte) error
- func (m *GameInstanceManager) GetInstance(addr string) (*GameInstance, error)
- func (m *GameInstanceManager) GetNumInstances() int
- func (m *GameInstanceManager) GetOrCreateOpenInstance(conn *net.UDPConn, server UDPServer, startFn func(string)) (*GameInstance, error)
- func (m *GameInstanceManager) HydrateDeserialized(server *net.UDPConn, opts *GameInstanceManagerOptions)
- func (m *GameInstanceManager) Reaper(server UDPServer, stopFn func(string))
- func (m *GameInstanceManager) SerializeSelf() ([]byte, error)
- type GameInstanceManagerCached
- type GameInstanceManagerOptions
- type UDPCallbackKey
- type UDPServer
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 ¶
func (gi *GameInstance) AskInfo(askInfo *gamenet.AskInfoPak, server UDPServer, ctx context.Context) (*gamenet.ServerInfoPak, *gamenet.PlayerInfoPak, error)
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 ¶
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 ¶
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 ¶
func NewManager(opts *GameInstanceManagerOptions) (*GameInstanceManager, error)
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 ¶
func (m *GameInstanceManager) AskInfo(askInfo *gamenet.AskInfoPak, server UDPServer, ctx context.Context) (*gamenet.ServerInfoPak, *gamenet.PlayerInfoPak, error)
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 ¶
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 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) }