Documentation
¶
Overview ¶
Package core is what the launcher does, independent of any UI: it loads servers, keeps their folders up to date, reads and writes their settings, and starts them.
Index ¶
- Constants
- Variables
- func BuildIndex(dir string) ([]byte, error)
- func LegacyConfigPath() string
- type BaseInstaller
- type BaseSetup
- type Board
- type Choices
- type DEP
- type DirListing
- type ErrNeedsCopy
- type Index
- type Ladder
- type LadderEntry
- type Listing
- type Login
- type Manager
- func (m *Manager) AddServer(ctx context.Context, profileURL string) (*spec.Profile, error)
- func (m *Manager) Asset(ctx context.Context, id, which string) ([]byte, error)
- func (m *Manager) Base() string
- func (m *Manager) BaseSetup() BaseSetup
- func (m *Manager) CheckBase() (install.Report, string, error)
- func (m *Manager) Choices(ctx context.Context, id string) (Choices, error)
- func (m *Manager) ClearBaseCache() error
- func (m *Manager) DEP(ctx context.Context, id string) (DEP, error)
- func (m *Manager) DetectBase() error
- func (m *Manager) Favourites() []string
- func (m *Manager) FinishWelcome(pins []string) error
- func (m *Manager) FirstRun() bool
- func (m *Manager) ImportLegacy(ctx context.Context, configPath string) (bool, error)
- func (m *Manager) InstallBase(ctx context.Context, o basegame.Options, progress func(basegame.Progress)) (basegame.Result, error)
- func (m *Manager) InstallRosetta(ctx context.Context) error
- func (m *Manager) Ladder(ctx context.Context, id string) (*Ladder, error)
- func (m *Manager) LaunchDelay() int
- func (m *Manager) LogIn(ctx context.Context, id string, open func(url string) error) (Login, error)
- func (m *Manager) LogOut(id string) error
- func (m *Manager) LoginStatus(ctx context.Context, id string) (Login, error)
- func (m *Manager) News(ctx context.Context, id string) ([]NewsItem, error)
- func (m *Manager) Play(ctx context.Context, id string) error
- func (m *Manager) PostReport(ctx context.Context, id, contentType string, body []byte) ([]byte, error)
- func (m *Manager) Profile(ctx context.Context, id string) (*spec.Profile, error)
- func (m *Manager) RemoveServer(id string) error
- func (m *Manager) ServerFolder(id string) (string, error)
- func (m *Manager) Servers(ctx context.Context) ([]ServerInfo, error)
- func (m *Manager) SetBase(dir string) (install.Report, error)
- func (m *Manager) SetBaseInstaller(b BaseInstaller)
- func (m *Manager) SetChannel(ctx context.Context, id, channel string) error
- func (m *Manager) SetComponent(ctx context.Context, id, comp, version string) error
- func (m *Manager) SetD2GLResolutions(id, main, loader string) error
- func (m *Manager) SetFavourite(id string, on bool) error
- func (m *Manager) SetFavouriteOrder(ids []string) error
- func (m *Manager) SetInstances(ctx context.Context, id string, n int, splitD2GL bool) error
- func (m *Manager) SetLaunchDelay(ms int) error
- func (m *Manager) SetSetting(ctx context.Context, id, settingID string, value interface{}) error
- func (m *Manager) SetWine(h *wine.Host)
- func (m *Manager) Settings(ctx context.Context, id string) ([]SettingValue, error)
- func (m *Manager) SetupWine(ctx context.Context, progress func(wine.Progress)) error
- func (m *Manager) Status(ctx context.Context, id string) Status
- func (m *Manager) TurnOffDEP(ctx context.Context, id string) error
- func (m *Manager) Update(ctx context.Context, id string, allowCopy bool, progress func(sync.Progress)) error
- func (m *Manager) Verify(ctx context.Context, id string) Status
- func (m *Manager) WineStatus(ctx context.Context) WineStatus
- type NewsItem
- type RemoteListing
- type ServerInfo
- type SettingValue
- type Status
- type WineStatus
Constants ¶
const CustomVersion = "custom"
CustomVersion is the component "version" for the player's own files: a maphack build they're testing, say. The launcher doesn't install, update, repair or remove anything that component could hold. It isn't supported by the server; the launcher says so when it's chosen.
const LegacyServer = "slashdiablo"
LegacyServer is the server the old SlashDiablo launcher's settings belong to.
const MaxFavourites = 3
MaxFavourites is how many servers can be pinned to the rail.
Variables ¶
var D2GLResolutions = []string{
"800x600", "960x720", "1024x768", "1200x900", "1280x960", "1440x1080",
"1600x1200", "1920x1440", "2560x1920", "2732x2048",
"1068x600", "1280x720", "1600x900", "1920x1080", "2048x1152",
"2560x1440", "3200x1800", "3840x2160",
}
D2GLResolutions are the window sizes d2gl offers itself, from its own list, for per-box profiles. "" means leave the profile's size alone.
var ErrAlreadyListed = errors.New("this server is already listed; open it from All servers")
ErrAlreadyListed means a server added by URL is already in the listing.
var ErrBaseNotSaved = errors.New("Diablo II is installed, but the launcher couldn't save where")
ErrBaseNotSaved means the game was installed but the launcher couldn't save that it's now the Diablo II folder. Installing again won't help: the folder is no longer empty.
var ErrInstalling = errors.New("Diablo II is already being installed")
ErrInstalling means an install is already under way.
var ErrNotLoggedIn = errors.New("log in first")
ErrNotLoggedIn is Play on a server with its own login before the player has logged in.
var ErrTooManyFavourites = fmt.Errorf("you can pin up to %d servers; unpin one first", MaxFavourites)
ErrTooManyFavourites means the rail is full.
var ErrWineNotReady = errors.New("Wine needs setting up first")
ErrWineNotReady means Play needs Wine set up first, which the setup screen does.
Functions ¶
func BuildIndex ¶
BuildIndex checks every profile in a folder, including that each file is named after its server's id, and renders the index.
func LegacyConfigPath ¶
func LegacyConfigPath() string
LegacyConfigPath is where the old SlashDiablo launcher kept its settings.
Types ¶
type BaseInstaller ¶
type BaseInstaller struct {
basegame.Installer
// DefaultDir is where it suggests installing.
DefaultDir string
Unavailable string
}
BaseInstaller is how the launcher installs the base game itself.
type BaseSetup ¶
type BaseSetup struct {
// Available is whether the launcher can install the game; when it
// can't, Unavailable says why.
Available bool `json:"available"`
// DefaultDir is the suggested install folder.
DefaultDir string `json:"defaultDir"`
Versions []string `json:"versions"`
DefaultVersion string `json:"defaultVersion"`
// Owner is the name suggested to store beside the keys.
Owner string `json:"owner"`
// CacheBytes is the download cache left by an install.
CacheBytes int64 `json:"cacheBytes"`
}
BaseSetup is what the "Get Diablo II" step offers.
type Board ¶
type Board struct {
ID string `json:"id"`
Name string `json:"name"`
Entries []LadderEntry `json:"entries"`
}
Board is one ranked list.
type Choices ¶
type Choices struct {
Channel string `json:"channel"`
Components map[string]string `json:"components"`
Instances int `json:"instances"`
SplitD2GL bool `json:"splitD2gl"`
D2GLMainResolution string `json:"d2glMainResolution"`
D2GLLoaderResolution string `json:"d2glLoaderResolution"`
D2GLResolutions []string `json:"d2glResolutions"`
}
Choices is what the player has picked for a server.
type DEP ¶
type DEP struct {
Supported bool `json:"supported"`
// Off is set once DEP is off for the server's Game.exe. The launcher has
// no undo: the player removes it on the exe's Compatibility tab.
Off bool `json:"off"`
}
DEP is the DEP fix for a server's game: Windows only, where some old game code trips Data Execution Prevention and crashes on start.
type DirListing ¶
type DirListing string
DirListing reads profiles from a folder, like servers/ in the repo. Used for development and to build the index.
func (DirListing) Profiles ¶
func (d DirListing) Profiles(context.Context) ([]json.RawMessage, error)
Profiles returns every *.json file in the folder except the index.
type ErrNeedsCopy ¶
type ErrNeedsCopy struct {
Bytes int64
}
ErrNeedsCopy means the base archives can't be hard linked into the server folder and would need copying, which uses real disk space. The player is asked, and Update is called again with allowCopy.
func (ErrNeedsCopy) Error ¶
func (e ErrNeedsCopy) Error() string
type Index ¶
type Index struct {
Schema int `json:"schema"`
Servers []json.RawMessage `json:"servers"`
}
Index is servers/index.json: every listed profile in one file, so the launcher fetches the whole listing in one request. It is generated from servers/*.json by cmd/listing, and a test fails when it is out of date.
type Ladder ¶
type Ladder struct {
Boards []Board `json:"boards"`
}
Ladder is a server's ladder: one or more boards, such as softcore and hardcore. See docs/SPEC.md section 3.
type LadderEntry ¶
type LadderEntry struct {
Rank int `json:"rank"`
Name string `json:"name"`
Class string `json:"class"`
Level int `json:"level"`
Title string `json:"title,omitempty"`
Status string `json:"status,omitempty"`
}
LadderEntry is one character on a board.
type Listing ¶
type Listing interface {
Profiles(ctx context.Context) ([]json.RawMessage, error)
}
Listing supplies the listed servers' profiles. The listing is the trust decision: a server gets in by a reviewed pull request adding its profile to servers/, so anything in a listed profile has been approved.
type Login ¶
type Login struct {
// Needed is set for a server with its own login service.
Needed bool `json:"needed"`
// LoggedIn is set once the player has logged in.
LoggedIn bool `json:"loggedIn"`
// Name is who the player is logged in as: their Discord name, or the
// realm account when the service gave no name.
Name string `json:"name"`
}
Login is a server's login as the player sees it.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the launcher.
func New ¶
func New(st *store.Store, listing Listing, l *launch.Launcher, clientOpts ...fetch.Option) (*Manager, error)
New returns a manager. clientOpts are passed to every fetch client, which is how development builds trust the local test server.
func (*Manager) AddServer ¶
AddServer adds a server that isn't in the listing, from the URL of its profile. Such servers haven't been reviewed and show as not verified. For a server that is already listed it returns the profile with ErrAlreadyListed, so the caller can open that server instead.
func (*Manager) Asset ¶
Asset returns one of a server's branding images, cached after the first download and checked against its SHA-256 when the profile gives one.
func (*Manager) ClearBaseCache ¶
ClearBaseCache deletes the base game's download cache.
func (*Manager) DetectBase ¶
DetectBase fills in the Diablo II folder from where the game itself last recorded it, if the player hasn't chosen one.
func (*Manager) Favourites ¶
Favourites returns the pinned server ids in order.
func (*Manager) FinishWelcome ¶
FinishWelcome pins the servers picked on the welcome screen and records that the player has been through it, in one save, so a failure can't leave pins without the welcome or the other way round. On failure nothing changes.
func (*Manager) FirstRun ¶
FirstRun reports whether to show the welcome screen: the player hasn't been through it, and has no servers pinned, as anyone who has used the launcher, or the old SlashDiablo one, will have.
func (*Manager) ImportLegacy ¶
ImportLegacy brings a SlashDiablo player's old launcher settings across, once: their Diablo II folder, box count, flags, maphack, HD and D2GL versions, and launch delay. It only fills in what isn't set yet, and only choices the SlashDiablo profile actually offers. It reports whether anything was imported.
func (*Manager) InstallBase ¶
func (m *Manager) InstallBase(ctx context.Context, o basegame.Options, progress func(basegame.Progress)) (basegame.Result, error)
InstallBase installs the base game and, once it passes its check, makes it the Diablo II folder. Cancelling ctx stops it; installing again resumes.
func (*Manager) InstallRosetta ¶
InstallRosetta installs Rosetta 2, which macOS asks an administrator to agree to.
func (*Manager) LaunchDelay ¶
LaunchDelay is the wait between starting boxes, in milliseconds.
func (*Manager) LogIn ¶
LogIn opens the server's login page in the player's browser with open and waits for them to finish there.
func (*Manager) LoginStatus ¶
LoginStatus is the server's login.
func (*Manager) News ¶
News returns a server's latest posts, newest first. Only plain text is used: HTML from a feed is never rendered.
func (*Manager) PostReport ¶
func (m *Manager) PostReport(ctx context.Context, id, contentType string, body []byte) ([]byte, error)
PostReport sends a bug report to the server's report URL and returns its answer.
func (*Manager) RemoveServer ¶
RemoveServer forgets a server added by URL. Its folder under the Diablo II install is left alone.
func (*Manager) ServerFolder ¶
ServerFolder returns a server's folder under the Diablo II install, creating it if needed, so the player can open it and add their own files.
func (*Manager) Servers ¶
func (m *Manager) Servers(ctx context.Context) ([]ServerInfo, error)
Servers loads the listing and any servers the player added by URL. A server whose profile doesn't load is still returned, with the error, so the player sees why. If the listing itself can't be loaded, servers added by URL are still returned alongside the error.
func (*Manager) SetBaseInstaller ¶
func (m *Manager) SetBaseInstaller(b BaseInstaller)
SetBaseInstaller lets the manager install the base game.
func (*Manager) SetChannel ¶
SetChannel switches release channel.
func (*Manager) SetComponent ¶
SetComponent turns a component on at a version, on with the player's own files (CustomVersion), or off with "". Takes effect on the next update.
func (*Manager) SetD2GLResolutions ¶
SetD2GLResolutions sets the window size for the main box and the loader boxes when d2gl profiles are split.
func (*Manager) SetFavourite ¶
SetFavourite pins or unpins a server.
func (*Manager) SetFavouriteOrder ¶
SetFavouriteOrder reorders the pinned servers, as when the player drags them in the rail. ids must be exactly the pinned servers, in their new order.
func (*Manager) SetInstances ¶
SetInstances sets how many boxes to start.
func (*Manager) SetLaunchDelay ¶
SetLaunchDelay changes the wait between boxes.
func (*Manager) SetSetting ¶
SetSetting changes one setting. File settings are written straight to the file; flag settings are stored and passed at launch.
func (*Manager) SetWine ¶
SetWine has the game run under Wine, set up by h: on macOS and Linux. d2gl is then on by default, where the player hasn't chosen.
func (*Manager) Settings ¶
Settings returns every setting the server declares, with its value. File settings are read from the file itself, so changes made in game show up.
func (*Manager) SetupWine ¶
SetupWine downloads Wine and makes the prefix, as needed. Quick when it's already done.
func (*Manager) TurnOffDEP ¶
TurnOffDEP turns DEP off for a server's Game.exe, for this Windows account.
func (*Manager) Update ¶
func (m *Manager) Update(ctx context.Context, id string, allowCopy bool, progress func(sync.Progress)) error
Update brings a server's folder up to date.
func (*Manager) Verify ¶
Verify checks every file in a server's folder against its manifests, hashing each one again rather than trusting the remembered hashes, and reports what an update would repair. Files the player owns ("once" files and custom components) are left out, as they are for an update.
func (*Manager) WineStatus ¶
func (m *Manager) WineStatus(ctx context.Context) WineStatus
WineStatus checks Wine without setting anything up.
type NewsItem ¶
type NewsItem struct {
Title string `json:"title"`
URL string `json:"url"`
Summary string `json:"summary"`
Date time.Time `json:"date"`
}
NewsItem is one post from a server's JSON Feed.
type RemoteListing ¶
RemoteListing fetches the published index, falling back to the last copy when offline.
func (RemoteListing) Profiles ¶
func (r RemoteListing) Profiles(ctx context.Context) ([]json.RawMessage, error)
Profiles fetches the index.
type ServerInfo ¶
type ServerInfo struct {
ID string `json:"id"`
Verified bool `json:"verified"`
Favourite bool `json:"favourite"`
Profile *spec.Profile `json:"profile"`
Error string `json:"error"`
}
ServerInfo is a server as the catalog shows it.
type SettingValue ¶
type SettingValue struct {
Setting spec.Setting `json:"setting"`
Value interface{} `json:"value"`
Available bool `json:"available"`
Reason string `json:"reason"`
}
SettingValue is one declared setting with its current value.
type Status ¶
type Status struct {
Installed bool `json:"installed"`
UpToDate bool `json:"upToDate"`
UpdateFiles int `json:"updateFiles"`
UpdateBytes int64 `json:"updateBytes"`
Error string `json:"error"`
}
Status is whether a server is ready to play.
type WineStatus ¶
type WineStatus struct {
Needed bool `json:"needed"`
Ready bool `json:"ready"`
// NeedsRosetta asks the player to install Rosetta 2 first (Apple
// Silicon).
NeedsRosetta bool `json:"needsRosetta"`
}
WineStatus is whether the game needs Wine here, and whether it's ready.