Documentation
¶
Overview ¶
Package dlc is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package dlc builds and verifies deterministic downloadable-content packs.
Index ¶
Examples ¶
Constants ¶
const CurrentDefinitionVersion = 1
CurrentDefinitionVersion is the supported pack definition schema version.
Variables ¶
This section is empty.
Functions ¶
func EncodeDefinition ¶
func EncodeDefinition(d *Definition) ([]byte, error)
EncodeDefinition writes a canonical YAML definition.
func Verify ¶
Verify checks a catalog.json or manifest.json file and every archive it lists. When publicKey is non-empty, Verify checks the catalog's Ed25519 signature (for catalogs) and per-pack signatures (for manifests, and for catalog entries that include one). publicKey may be nil to skip signature verification.
Types ¶
type BuildOptions ¶
type BuildOptions struct {
Root string
OutputDir string
BaseURL string
PrivateKey ed25519.PrivateKey
// Serial sets the monotonic serial written to catalog.json. When zero,
// Build increments the existing catalog.json serial in OutputDir (starting
// at 1).
Serial uint64
}
BuildOptions controls Build. Root contains the already-built asset files.
type BuildResult ¶
type BuildResult struct {
PackPath string
ManifestPath string
CatalogPath string
Spec remote.PackSpec
Catalog *remote.Catalog
}
BuildResult describes the generated archive, manifest entry, and catalog.
func Build ¶
func Build(d *Definition, opts BuildOptions) (BuildResult, error)
Build creates a deterministic ZIP, merges its entry into manifest.json, and writes (and signs when PrivateKey is set) catalog.json in OutputDir.
Example ¶
Build packs the files a definition includes into a deterministic ZIP, signs its manifest entry and lets Verify check the archive before a game mounts it.
package main
import (
"crypto/ed25519"
"fmt"
"os"
"path/filepath"
"github.com/nsgo-dev/game/pkg/tooling/dlc"
)
func main() {
root, err := os.MkdirTemp("", "dlc-root")
if err != nil {
fmt.Println(err)
return
}
defer os.RemoveAll(root)
if err := os.MkdirAll(filepath.Join(root, "levels"), 0o755); err != nil {
fmt.Println(err)
return
}
if err := os.WriteFile(filepath.Join(root, "levels", "map.txt"), []byte("map"), 0o644); err != nil {
fmt.Println(err)
return
}
out, err := os.MkdirTemp("", "dlc-packs")
if err != nil {
fmt.Println(err)
return
}
defer os.RemoveAll(out)
_, private, err := ed25519.GenerateKey(nil)
if err != nil {
fmt.Println(err)
return
}
definition := &dlc.Definition{Version: 1, ID: "forest", PackVersion: "1.2.0", Include: []string{"levels/**"}}
result, err := dlc.Build(definition, dlc.BuildOptions{
Root: root,
OutputDir: out,
BaseURL: "https://cdn.example.com/packs",
PrivateKey: private,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(filepath.Base(result.PackPath), dlc.Verify(result.ManifestPath, private.Public().(ed25519.PublicKey)))
}
Output: forest-1.2.0.zip <nil>
type Definition ¶
type Definition struct {
Version int `yaml:"version"`
ID string `yaml:"id"`
Group string `yaml:"group,omitempty"`
PackVersion string `yaml:"packVersion"`
MinBuild int `yaml:"minBuild,omitempty"`
MaxBuild int `yaml:"maxBuild,omitempty"`
Include []string `yaml:"include,omitempty,flow"`
Exclude []string `yaml:"exclude,omitempty,flow"`
}
Definition is the versioned YAML input for a DLC pack.
func ParseDefinition ¶
func ParseDefinition(data []byte) (*Definition, error)
ParseDefinition parses one strict, versioned YAML pack definition, refusing unknown fields and a second document. An empty include list selects every file ("**"). Its errors are *loaderr.Error values with the line and field at fault.