launch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
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 StartProcess

func StartProcess(Box) error

StartProcess is not supported outside Windows yet.

func WatchStart

func WatchStart(exited <-chan uint32, wine bool) error

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

func WithoutD2UP(environ []string) []string

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.

func Boxes

func Boxes(serverDir string, p *spec.Profile, c Choices) ([]Box, error)

Boxes works out exactly what to start. Flags come from the profile's defaults, the turned-on components and the player's allowed choices, in that order, without duplicates.

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

type GameRegistry interface {
	SetGame(exe, version string) error
}

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

type GatewayList struct {
	Header   string
	Selected int
	Gateways []spec.Gateway
}

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

func New(r Registry, start Starter) *Launcher

New returns a launcher using the given registry and process starter, for the game running natively.

func NewWithPaths

func NewWithPaths(r Registry, start Starter, paths Paths) *Launcher

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 Starter

type Starter func(Box) error

Starter starts a game process.

type StartupError

type StartupError struct {
	Code uint32
	Wine bool
}

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

func (SystemRegistry) SetString

func (SystemRegistry) SetString(string, string) error

func (SystemRegistry) String

func (SystemRegistry) String(string) (string, error)

Jump to

Keyboard shortcuts

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