Documentation
¶
Overview ¶
Package launch starts the game for a server: it points Battle.net at the server's gateway, then starts each box from the server's folder.
Index ¶
- Constants
- Variables
- func StartProcess(Box) error
- func WatchStart(exited <-chan uint32, wine bool) error
- func WithoutD2UP(environ []string) []string
- type Box
- type Choices
- type Committer
- type GameRegistry
- type GatewayList
- type Launcher
- type Paths
- type Registry
- type Starter
- type StartupError
- type SystemRegistry
Constants ¶
const DefaultGatewayHeader = "1001"
DefaultGatewayHeader is written when there's no existing list to keep the header from. It is the value PvPGN's own gateway installer writes.
Variables ¶
var HostPaths = Paths{ ToGame: func(p string) string { return p }, FromGame: func(p string) (string, bool) { return p, true }, Sep: string(filepath.Separator), }
HostPaths is the identity mapping, for the game running natively.
var StartWatch = 3 * time.Second
StartWatch is how long a box is watched after it starts. A game that can't load closes within it; one still running is left to run.
Functions ¶
func WatchStart ¶
WatchStart waits up to StartWatch for a box's exit code. A box that closes in that time with a failure is a StartupError; a clean exit isn't one, as a game that shows its own error closes cleanly once it's dismissed.
func WithoutD2UP ¶
WithoutD2UP is environ with every D2UP_ variable taken out, so a stale login in the launcher's own environment never reaches a game.
Types ¶
type Box ¶
type Box struct {
Exe string
Args []string
Dir string
// D2GL is set when the d2gl renderer is on, which a starter running the
// game under Wine needs to know.
D2GL bool
// Env is added to the game's environment. It may hold a login ticket, so
// it is never logged.
Env []string
}
Box is one game process to start.
type Choices ¶
type Choices struct {
// Components maps each turned-on component to its version.
Components map[string]string
// Flags are the flags the player turned on, through flag settings or the
// advanced page. Only flags in the profile's allowedFlags are used.
Flags []string
// Instances is how many boxes to start.
Instances int
// SplitD2GL launches the first box with the d2gl "main" profile and the
// rest with "loader", so each can keep its own resolution.
SplitD2GL bool
// Env, when set, gives each box its extra environment just before it
// starts, such as a single-use login ticket, which must not be fetched
// early or shared between boxes.
Env func(ctx context.Context, box int) ([]string, error)
}
Choices are the player's per-server selections that affect how the game starts.
type Committer ¶
type Committer interface {
Commit() error
}
Committer is a Registry that holds its writes until Commit, such as one writing into a Wine prefix, where every write costs a process. Launch commits once the settings are all written, before starting any box.
type GameRegistry ¶
GameRegistry is a Registry told which game a launch is for, by its exe's file name and game.version: under Wine, an older game needs Wine to report an older Windows to it.
type GatewayList ¶
GatewayList is the game's "Diablo II Battle.net Gateways" registry value: a header, the selected gateway as a 1-based two digit index, then a host, timezone and name for each gateway.
func Merge ¶
func Merge(existing GatewayList, server []spec.Gateway) GatewayList
Merge adds a server's gateways to the player's existing list and selects the server's first one. Gateways the player added themselves are kept; an existing entry for the same host is replaced so it isn't listed twice.
func ParseGatewayList ¶
func ParseGatewayList(values []string) GatewayList
ParseGatewayList reads the multi-string registry value. A malformed or empty value gives an empty list rather than an error, since the launcher is about to write a good one.
func (GatewayList) Values ¶
func (l GatewayList) Values() []string
Values renders the list as the registry's multi-string.
type Launcher ¶
type Launcher struct {
// contains filtered or unexported fields
}
Launcher starts servers one at a time. Battle.net settings are global, so two servers launching together could each pick up the other's gateway.
func New ¶
New returns a launcher using the given registry and process starter, for the game running natively.
func NewWithPaths ¶
NewWithPaths returns a launcher whose registry values hold paths as mapped by paths, such as for the game running under Wine.
func (*Launcher) Launch ¶
func (l *Launcher) Launch(ctx context.Context, base, serverDir string, p *spec.Profile, c Choices, delay time.Duration) error
Launch points Battle.net at the server and starts its boxes, waiting delay between each so the game's own startup reads of the registry don't overlap.
type Paths ¶
type Paths struct {
// ToGame is a host path as the game sees it.
ToGame func(string) string
// FromGame is the host path for one the game sees, or false if it has
// none, such as a path on another Wine drive.
FromGame func(string) (string, bool)
// Sep is the game's path separator.
Sep string
}
Paths maps host paths to the paths the game sees, for registry values. On Windows they're the same; under Wine the game sees them on drive Z:.
type Registry ¶
type Registry interface {
GatewayList() ([]string, error)
SetGatewayList([]string) error
// String reads a value under the game's own key; one not set is "".
String(name string) (string, error)
SetString(name, value string) error
}
Registry is the game's Battle.net settings in the registry. It's an interface so launches can be tested without touching the real registry.
type StartupError ¶
StartupError is a box that closed as it started, with what the player can do about it.
func (*StartupError) Error ¶
func (e *StartupError) Error() string
type SystemRegistry ¶
type SystemRegistry struct{}
SystemRegistry has nothing to write to outside Windows yet. A Linux build will write into the Wine prefix instead.
func (SystemRegistry) GatewayList ¶
func (SystemRegistry) GatewayList() ([]string, error)
func (SystemRegistry) SetGatewayList ¶
func (SystemRegistry) SetGatewayList([]string) error