Documentation
¶
Overview ¶
Package session runs a play session: modlock-host with the mods, a Deadlock client that joins it, and the control link that reports the mods' progress and reloads them.
Index ¶
- Constants
- Variables
- func Changes(from, to *ui.Screen) map[string]*ui.Change
- func DownloadHost(ctx context.Context, version string) (string, error)
- func FindHost(ctx context.Context, version string) (string, error)
- func Loopback(request *http.Request) bool
- func ReadContent(mods []string) (fstest.MapFS, error)
- func SameOrigin(request *http.Request) bool
- func StartInterface(config Interface) (stop func())
- func WindowsPath(path string) string
- type Chat
- type Config
- type Control
- type Host
- type HostConfig
- type Interface
- type Mirror
- type Proton
- type Relay
- type Renderer
- type ScreenSource
- type Screens
- type Session
- type Steam
Constants ¶
const BridgePath = "/app/relay/bridge.html"
BridgePath is the relay page's path under its origin. The page reads the screen from the loopback port its query names as port, or from DefaultInterfacePort.
const DeadlockAppID = "1422450"
DeadlockAppID is Deadlock's Steam application ID.
const DefaultInterfacePort = 4320
DefaultInterfacePort is the loopback port the relay page reads the mods' interfaces from when its URL names none.
const DefaultPort = 27067
DefaultPort is the server's default UDP port.
const DefaultRelay = "https://hyperline.gg"
DefaultRelay hosts the relay page the game reads the mods' interfaces through.
const FrameGap = 50 * time.Millisecond
FrameGap is the least time between two frames on one stream. The relay page acknowledges each frame before it reads the next, so a mod that changes its interface every server frame would otherwise queue frames in the socket faster than the game draws them; the stream sends the newest screen instead.
const HostArchive = "modlock-host-windows-x64.zip"
HostArchive is the release asset that holds the Windows host.
const RelayAgent = "Source2 HTML"
RelayAgent marks the game's own HTML panels in their User-Agent. Requiring it keeps the relay page, opened in an ordinary browser, from reading the player's screen. A Steam beta client names its branch after the marker, as "Source2 HTML [Steam Beta Update]/".
Variables ¶
var ErrNoGame = errors.New("this computer cannot run Deadlock")
ErrNoGame marks the errors that mean this computer cannot run a Deadlock server: the system is not Windows or Linux, or Steam or the game is missing.
Functions ¶
func Changes ¶ added in v0.1.13
Changes returns each mod's change that turns the screen from into to: the nodes set or removed in a tree both hold, a whole new tree as a reset, and a reset with no nodes for a tree that is gone. It returns nothing when the screens match.
func DownloadHost ¶
DownloadHost returns modlock-host.exe from the release tagged version, downloading and extracting it into the user cache the first time.
func FindHost ¶
FindHost returns modlock-host.exe: MODLOCK_HOST when set, else the release matching version, downloaded once into the user cache.
func Loopback ¶ added in v0.1.8
Loopback reports whether request names a loopback host, which keeps DNS rebinding from reaching a server that listens on loopback.
func ReadContent ¶ added in v0.1.19
ReadContent returns the content addons of the mods built at mods: their compiled Panorama content and assets, each already under its addon's name, and the archive of each map a mod ships, as maps/<map>.vpk.
func SameOrigin ¶ added in v0.1.8
SameOrigin reports whether request comes from a page this server served, or from no page at all.
func StartInterface ¶ added in v0.1.13
func StartInterface(config Interface) (stop func())
StartInterface mounts the renderer and the mods' content in the game and serves the screen to the relay page, and returns the call that stops both. Each part is optional: a game that cannot take the package or another program on the address reports a failure and leaves the session running. Start it before the server and the game, which load the package only when they start.
func WindowsPath ¶
WindowsPath names an absolute Linux path as Wine's Z: drive sees it.
Types ¶
type Chat ¶ added in v0.1.13
type Chat struct {
// contains filtered or unexported fields
}
Chat keeps the newest lines said on a server, numbered in order, for streams that send each line once. A stream that falls more than chatKept lines behind skips the oldest.
func (*Chat) Add ¶ added in v0.1.13
func (c *Chat) Add(line *control.PlayerChat)
Add records a line and wakes every stream.
func (*Chat) Since ¶ added in v0.1.13
func (c *Chat) Since(from uint64) ([]*control.PlayerChat, uint64, <-chan struct{})
Since returns the lines kept from number from on, the number of the next line, and a channel that closes when another line is said. A stream that starts at the next line passes the largest number.
type Config ¶
type Config struct {
// Version is the command line's release, whose host the session runs
// unless MODLOCK_HOST names one.
Version string
// Mods lists the built mods to load.
Mods []string
// Port is the server's UDP port.
Port uint16
// Map is the map the server starts, or empty for the default.
Map string
// Args are passed to each mod's start handlers.
Args []string
// Settings is the file that keeps players' settings, or empty to keep
// them for the session only.
Settings string
// Files is the directory that keeps the files mods write, or empty to
// refuse their writes.
Files string
// Launch starts the Deadlock client once the server is ready.
Launch bool
// HostOutput receives the host's console output.
HostOutput io.Writer
// Interface is the loopback address the player's game reads the mods'
// interfaces from, or empty to serve none.
Interface string
// Relay is the origin of the https page the game reads them through.
Relay string
// Renderer is the built renderer, which the session mounts in the game so
// it draws the interfaces, or nil to leave the game unchanged.
Renderer *Renderer
// Events receives each host event, on one goroutine.
Events func(*control.HostEvent)
}
Config describes a play session.
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Control is the controller's end of the control link. It listens on a loopback port and modlock-host dials it with --control; then the host streams its events and takes reloads and the players' roles, each message framed by its length as control.proto describes.
func (*Control) Reload ¶
Reload asks the host to replace the running mod named by the build at path. Requests made before the host connects wait for it.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is a running modlock-host process.
func StartHost ¶
func StartHost(ctx context.Context, config HostConfig) (*Host, error)
StartHost starts modlock-host as a listen server with the mods. On Windows the host runs directly; on Linux it runs through Steam's Proton in a prefix of its own.
type HostConfig ¶
type HostConfig struct {
// Executable is modlock-host.exe, beside its libraries.
Executable string
// GameDir is the Deadlock installation directory.
GameDir string
// Mods lists the built mods to load, as directories with mod.json.
Mods []string
// Control is the address of the controller's Control link.
Control string
// Port is the server's UDP port.
Port uint16
// Map is the map the server starts, or empty for the host's default.
Map string
// Args are passed to each mod's start handlers.
Args []string
// Settings is the file that keeps players' settings, or empty to keep
// them for the run only.
Settings string
// Files is the directory that keeps the files mods write, or empty to
// refuse their writes.
Files string
// Steam is the Steam installation; on Linux its Proton runs the host.
Steam *Steam
// Output receives the host's console output.
Output io.Writer
}
HostConfig describes one modlock-host run.
type Interface ¶ added in v0.1.13
type Interface struct {
// Address is the loopback address the relay page reads from, or empty to
// serve no interfaces.
Address string
// Relay is the relay page's origin.
Relay string
// Renderer is the built renderer; nil leaves the game without it, so the
// interfaces show only in the browser preview.
Renderer *Renderer
// Content is the mods' content addons the game loads, as ReadContent
// returns them.
Content fstest.MapFS
// GameDir is the Deadlock installation the renderer mounts in.
GameDir string
// Screen is the player's screen.
Screen ScreenSource
// Events receives a failure that turns part of the interfaces off.
Events func(*control.HostEvent)
}
Interface configures serving a player's mod interfaces and content to their game.
type Mirror ¶ added in v0.1.13
type Mirror struct {
// contains filtered or unexported fields
}
Mirror keeps a copy of one player's screen that another PC sends as changes, for a Relay on the player's own PC.
type Proton ¶
type Proton struct {
// Dir is the Proton installation directory.
Dir string
// Prefix is the compatibility data directory of the host's prefix.
Prefix string
// Runtime is the run script of the Steam Linux Runtime the Proton
// requires, or empty for a Proton that runs on the host.
Runtime string
// contains filtered or unexported fields
}
Proton is one Steam Proton installation with the prefix modlock-host runs in. The prefix is the command line's own: the host must not share the game's prefix, because Steam runs the client under its own Proton, whose wineserver would wait for this one to exit.
func FindProton ¶
FindProton returns MODLOCK_PROTON when set, else the newest numbered Proton in the Steam libraries, else Proton Experimental.
type Relay ¶ added in v0.1.13
type Relay struct {
// contains filtered or unexported fields
}
Relay serves one player's screen to their game on loopback. Deadlock loads only https pages into its HTML panels, so the game's renderer reads through a relay page from another origin: the page streams the screen from GET /panorama/stream, one binary ui.Screen per line, packed by panorama.AppendPackedLine. The game presses buttons with a console command to the server, not through this page.
func NewRelay ¶ added in v0.1.13
func NewRelay(origin string, screen ScreenSource) *Relay
NewRelay returns a Relay serving screen to the relay page at origin.
type Renderer ¶ added in v0.1.14
type Renderer struct {
// Script draws each mod's tree; it installs as scripts/modlock/ui.js.
Script []byte
// Layout is the library a mod's layout includes to read its data and
// routes; it installs as scripts/modlock/layout.js.
Layout []byte
}
Renderer is the built scripts that draw the mods' interfaces in the game.
type ScreenSource ¶ added in v0.1.13
ScreenSource returns a player's screen and a channel that closes when it may have changed.
type Screens ¶
type Screens struct {
// contains filtered or unexported fields
}
Screens keeps what the mods show each player on a server, following the host's events. It serves the local player's screen to a Relay, and any player's screen to a host that streams it to a guest.
func NewScreens ¶
NewScreens returns screens whose local player has the Steam ID account.
func (*Screens) Handle ¶
Handle follows one host event: a join that binds a person's slot, a leave that frees it, or a mod's change to a player's interface.
func (*Screens) Player ¶ added in v0.1.13
Player returns the screen of the person with the Steam ID account, empty while they are not in the server, and a channel that closes when it may have changed.
type Session ¶
type Session struct {
// Executable is the modlock-host.exe the session runs: MODLOCK_HOST, or
// the downloaded release.
Executable string
// contains filtered or unexported fields
}
Session is a running play session: the host with the mods and, once the server is ready, the Deadlock client joined to it.
func Start ¶
Start starts the host with the mods and serves its control link. It returns an error marked ErrNoGame when this computer cannot run the game.
type Steam ¶
type Steam struct {
// Root is the Steam installation directory.
Root string
// Libraries lists every library directory, Root first.
Libraries []string
}
Steam is the local Steam installation: the client that launches games and the libraries they are installed in.
func (*Steam) Account ¶
Account returns the Steam ID of the account signed in to Steam last, or zero when Steam names none.
func (*Steam) App ¶
App returns the installation directory of the app installed as name, such as "Deadlock", in the first library that has it.