fix(client): align development resources and improve update downloads
Use repository versions, fingerprints and game paths for development launches. Report server response details for failed downloads and compatibility requests. Publish flat launcher archives and require independently signed changelogs before announcements.
This commit is contained in:
1 parent
238609bdb2
commit
1239a8dadc
11 files changed
+128
-9
No files matched your search
+11
-2
@@ -79,7 +79,9 @@ func copyTree(source, destination string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func archiveDirectory(source, destination string) error {
|
||||
// archiveDirectory zips source. With flat, the archive holds source's
|
||||
// contents at its root; otherwise everything sits below source's own name.
|
||||
func archiveDirectory(source, destination string, flat bool) error {
|
||||
file, err := os.CreateTemp(filepath.Dir(destination), ".bd2-archive-*.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -102,10 +104,17 @@ func archiveDirectory(source, destination string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, err := filepath.Rel(filepath.Dir(source), path)
|
||||
base := filepath.Dir(source)
|
||||
if flat {
|
||||
base = source
|
||||
}
|
||||
rel, err := filepath.Rel(base, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rel == "." {
|
||||
return nil
|
||||
}
|
||||
header.Name = filepath.ToSlash(rel)
|
||||
if entry.IsDir() {
|
||||
header.Name += "/"
|
||||
|
||||
@@ -241,10 +241,11 @@ func (r *release) writePluginStore() error {
|
||||
}
|
||||
|
||||
func (r *release) archive() error {
|
||||
if err := archiveDirectory(r.server, r.serverZip); err != nil {
|
||||
if err := archiveDirectory(r.server, r.serverZip, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := archiveDirectory(r.client, r.clientZip); err != nil {
|
||||
// The launcher download unpacks straight into the folder the player chose.
|
||||
if err := archiveDirectory(r.client, r.clientZip, true); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Built server archive:", r.serverZip)
|
||||
|
||||
@@ -248,6 +248,15 @@ func (t task) releasePublish(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !opts.silent {
|
||||
signature, err := os.ReadFile(filepath.Join(t.root, releasepkg.ChangelogSignatureName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := releasepkg.VerifyChangelog(changelog, signature, releasepkg.BuiltinChannel().TrustedKeys); err != nil {
|
||||
return fmt.Errorf("release changelog must be signed independently before publication: %w", err)
|
||||
}
|
||||
}
|
||||
entries, err := releasepkg.ParseChangelog(changelog)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CHANGELOG.md: %w", err)
|
||||
@@ -350,6 +359,12 @@ func (t task) releasePublish(args []string) error {
|
||||
plugins.Files = append(plugins.Files, f)
|
||||
}
|
||||
|
||||
// The one-step launcher download is the flat client archive the build made.
|
||||
download := "bd2client-" + versions.ClientVersion + "-" + t.target.platform + "-" + t.target.architecture + ".zip"
|
||||
if err := copyFile(filepath.Join(t.root, ".build", download), filepath.Join(site, "downloads", download)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
schedules, err := t.stageSchedules(site, versions)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -115,6 +115,8 @@ func runClientDevelopmentCommand(args []string) (bool, error) {
|
||||
return err
|
||||
}
|
||||
gameDir = config.GameDirectory
|
||||
// Development launches the project's configured game, never a stale launcher preference.
|
||||
clientArgs = append(clientArgs, "--game-dir", gameDir)
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
|
||||
@@ -94,7 +94,7 @@ func NewStudio(options Options, host NativeHost) *Studio {
|
||||
|
||||
s.updates = clientupdate.New(clientupdate.Options{
|
||||
Versions: options.Versions, Directory: filepath.Dir(executable), Logger: options.Logger, Development: options.Development,
|
||||
DevelopmentPlugins: options.Plugins,
|
||||
DevelopmentPlugins: options.Plugins, ProjectDirectory: options.PackageDirectory,
|
||||
Games: func() string {
|
||||
preferences, err := clientconfig.LoadPreferences()
|
||||
if err != nil {
|
||||
|
||||
@@ -176,7 +176,7 @@ func (d *downloader) receiveOnce(ctx context.Context, item file, origin string)
|
||||
}
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("full GET requires HTTP 200, got %s", response.Status)
|
||||
return fmt.Errorf("download %s: %w", item.target, util.ResponseError(response))
|
||||
}
|
||||
temporary, err := os.CreateTemp(filepath.Dir(item.target), ".bd2-download-*.part")
|
||||
if err != nil {
|
||||
@@ -302,7 +302,7 @@ func (d *downloader) fastest(ctx context.Context, origins []string, relative, la
|
||||
}
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
results[i] = result{origin: origin, err: fmt.Errorf("HTTP %s", response.Status)}
|
||||
results[i] = result{origin: origin, err: util.ResponseError(response)}
|
||||
return
|
||||
}
|
||||
n, err := io.Copy(io.Discard, io.LimitReader(response.Body, 4<<20))
|
||||
|
||||
@@ -69,6 +69,9 @@ func (m *Manager) Versions(game string) versionconfig.Config {
|
||||
}
|
||||
|
||||
func (m *Manager) Runtime(game string) *clientconfig.Runtime {
|
||||
if m.options.Development {
|
||||
return m.developmentRuntime()
|
||||
}
|
||||
v := m.Versions(game)
|
||||
runtime := &clientconfig.Runtime{ClientVersion: v.ClientVersion, GameVersion: v.GameVersion, BundleVersion: v.BundleVersion, GameDataVersion: v.GameDataVersion}
|
||||
m.mu.Lock()
|
||||
@@ -93,7 +96,57 @@ func (m *Manager) configureGame(game string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// developmentRuntime describes the game prepared from the repository's own
|
||||
// versions.json and UPDATE_FINGERPRINT.json instead of a launcher receipt.
|
||||
func (m *Manager) developmentRuntime() *clientconfig.Runtime {
|
||||
v := m.options.Versions
|
||||
runtime := &clientconfig.Runtime{ClientVersion: v.ClientVersion, GameVersion: v.GameVersion, BundleVersion: v.BundleVersion, GameDataVersion: v.GameDataVersion}
|
||||
if m.project != nil {
|
||||
runtime.UpdateFingerprint, runtime.ResourceFingerprint = m.project.ID, m.project.GameFingerprint
|
||||
}
|
||||
return runtime
|
||||
}
|
||||
|
||||
// prepareDevelopmentGame never downloads: development games are prepared by the
|
||||
// project tools, so a mismatch is reported instead of reinstalled.
|
||||
func (m *Manager) prepareDevelopmentGame(game string) error {
|
||||
if m.projectErr != nil {
|
||||
return fmt.Errorf("project update fingerprint: %w", m.projectErr)
|
||||
}
|
||||
v := m.options.Versions
|
||||
if m.project != nil {
|
||||
if err := m.project.MatchesVersions(v); err != nil {
|
||||
return fmt.Errorf("project %s does not match versions.json: %w", release.FingerprintFileName, err)
|
||||
}
|
||||
}
|
||||
m.mu.Lock()
|
||||
server := m.fingerprint
|
||||
m.mu.Unlock()
|
||||
if server != nil && (m.project == nil || server.ID != m.project.ID) {
|
||||
return fmt.Errorf("server requires update %s for game %s; update the project's %s before launching", server.ID, gameVersion(server), release.FingerprintFileName)
|
||||
}
|
||||
if _, err := setup.Inspect(game, v); err != nil {
|
||||
return fmt.Errorf("development game does not match versions.json: %w", err)
|
||||
}
|
||||
settings, err := clientconfig.Load(game)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := setup.Patch(game); err != nil {
|
||||
return fmt.Errorf("apply development client patch: %w", err)
|
||||
}
|
||||
if settings.CDNMode == clientconfig.CDNLocal {
|
||||
if err := setup.InstallLocalCatalog(game, settings.LocalResourceDirectory, v.BundleVersion); err != nil {
|
||||
return fmt.Errorf("prepare development resource catalog: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) ensureGame(ctx context.Context, game string) error {
|
||||
if m.options.Development {
|
||||
return m.prepareDevelopmentGame(game)
|
||||
}
|
||||
m.mu.Lock()
|
||||
fp := m.fingerprint
|
||||
fingerprintErr := m.fingerprintErr
|
||||
@@ -314,7 +367,7 @@ func (m *Manager) fetchServerFingerprint(ctx context.Context, client *http.Clien
|
||||
}
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("server update fingerprint: HTTP %d", response.StatusCode)
|
||||
return fmt.Errorf("fetch server update fingerprint: %w", util.ResponseError(response))
|
||||
}
|
||||
raw, err := io.ReadAll(io.LimitReader(response.Body, (32<<20)+1))
|
||||
if err != nil {
|
||||
|
||||
@@ -10,8 +10,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
clientconfig "bd2server/internal/client/config"
|
||||
commonconfig "bd2server/internal/common/config"
|
||||
"bd2server/internal/common/release"
|
||||
"bd2server/internal/common/versionconfig"
|
||||
)
|
||||
|
||||
func TestGameReceiptRechecksContentWhenInstalledMetadataChanges(t *testing.T) {
|
||||
@@ -83,3 +85,23 @@ func TestServerOnlyFingerprintChangeReusesVerifiedGameResources(t *testing.T) {
|
||||
t.Fatalf("server-only update lost verified game state: %+v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDevelopmentGameUsesProjectFingerprintAndNeverInstallsServerRequirement(t *testing.T) {
|
||||
game := t.TempDir()
|
||||
versions := versionconfig.Config{ServerVersion: "2.37.13+server.0.2.0", ClientVersion: "2.37.13+client.0.2.7", GameVersion: "2.37.13", BundleVersion: "20261022174708", GameDataVersion: "20261021182514"}
|
||||
m := New(Options{Directory: t.TempDir(), Versions: versions, Development: true})
|
||||
m.project = &release.Fingerprint{ID: "project", ServerVersion: versions.ServerVersion, ClientVersion: versions.ClientVersion, GameFingerprint: "project-resources"}
|
||||
m.fingerprint = &release.Fingerprint{ID: "server", RequireGameUpdate: true}
|
||||
err := m.ensureGame(context.Background(), game)
|
||||
if err == nil || !strings.Contains(err.Error(), "update the project's") {
|
||||
t.Fatalf("development launch accepted a server requirement the project does not describe: %v", err)
|
||||
}
|
||||
if entries, err := os.ReadDir(game); err != nil || len(entries) != 0 {
|
||||
t.Fatalf("development preparation wrote into the game directory: %v %v", entries, err)
|
||||
}
|
||||
got := m.Runtime(game)
|
||||
want := clientconfig.Runtime{ClientVersion: versions.ClientVersion, GameVersion: versions.GameVersion, BundleVersion: versions.BundleVersion, GameDataVersion: versions.GameDataVersion, UpdateFingerprint: "project", ResourceFingerprint: "project-resources"}
|
||||
if *got != want {
|
||||
t.Fatalf("development runtime = %+v, want project configuration %+v", *got, want)
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,9 @@ type Options struct {
|
||||
Client *http.Client
|
||||
Development bool
|
||||
DevelopmentPlugins plugin.Set
|
||||
// ProjectDirectory is the development repository whose versions.json and
|
||||
// UPDATE_FINGERPRINT.json describe the prepared game; it is unused in releases.
|
||||
ProjectDirectory string
|
||||
// Games returns the main game directory the launcher manages.
|
||||
Games func() string
|
||||
}
|
||||
@@ -100,6 +103,8 @@ type Manager struct {
|
||||
manifest *release.Manifest
|
||||
fingerprint *release.Fingerprint
|
||||
fingerprintErr error
|
||||
project *release.Fingerprint
|
||||
projectErr error
|
||||
gamePending map[string]bool
|
||||
pending map[string]bool
|
||||
}
|
||||
@@ -112,6 +117,12 @@ func New(options Options) *Manager {
|
||||
m := &Manager{options: options, manifestURL: address, keys: release.BuiltinChannel().TrustedKeys, pending: map[string]bool{}, gamePending: map[string]bool{}, operation: make(chan struct{}, 1)}
|
||||
m.status.Enabled = address != "" && !options.Development
|
||||
m.loadPackagedFingerprint()
|
||||
if options.Development && options.ProjectDirectory != "" {
|
||||
m.project, m.projectErr = release.LoadFingerprint(filepath.Join(options.ProjectDirectory, release.FingerprintFileName), m.keys)
|
||||
if errors.Is(m.projectErr, os.ErrNotExist) {
|
||||
m.project, m.projectErr = nil, nil
|
||||
}
|
||||
}
|
||||
if result := TakeResult(options.Directory); result != nil {
|
||||
if result.OK {
|
||||
m.status.Message = message("update.launcher.switched", result.From, result.To)
|
||||
|
||||
@@ -265,6 +265,11 @@ func TestWithLaunchKeepsUpdatesExcludedThroughProcessStartAndReturnsLaunchError(
|
||||
game := filepath.Join(root, "game")
|
||||
writeFixture(t, filepath.Join(game, "BrownDust II.exe"), "fixture")
|
||||
writeFixture(t, filepath.Join(game, "BrownDust II_Data", "resources.assets"), "fixture")
|
||||
manifest, err := json.Marshal(map[string]any{"schema_version": 1, "id": filepath.Base(root)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFixture(t, filepath.Join(root, "instance.json"), string(manifest))
|
||||
file := releaseFile("BD2LoginUI.dll", "installed login")
|
||||
writeFixture(t, filepath.Join(root, "plugins", file.Name), "installed login")
|
||||
writeFixture(t, filepath.Join(game, "BepInEx", "plugins", file.Name), "installed login")
|
||||
|
||||
@@ -43,8 +43,9 @@ func get(ctx context.Context, client *http.Client, address string) (*http.Respon
|
||||
return nil, err
|
||||
}
|
||||
if response.StatusCode != http.StatusOK {
|
||||
err := fmt.Errorf("GET %s: %w", request.URL.Redacted(), util.ResponseError(response))
|
||||
_ = response.Body.Close()
|
||||
return nil, fmt.Errorf("GET %s: HTTP %d", request.URL.Redacted(), response.StatusCode)
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user