Files
bd2/go/build/client_instance.go
T
Flechazo 6da2d9b89c feat(all): add server gameplay systems, one-step launcher installation, clearer update logs and shared file utilities
Server:
- Add castle and total war battles, IB battles, roguelike runs with castle and roguelike rankings, cafeteria and dating, life content, spine interactions and recordings, popularity rankings, gacha history and selection draws, map exploration, quest previews and completion, passes, rhythm events, quick battles, achievement progress, resource items, prestige illustrations and community notices.
- Report structured request errors from the gateway, validate avatars, and extend settlement evidence and existing domain handlers.
- Let bd2-host.sh deploy from a source directory or a prebuilt image and update the deployment docs and Docker ignore list.

Launcher:
- Prepare a new installation directly from the launcher (download, BepInEx, catalog, patch, plugins) through a shared preparation package also used by bd2client prepare.
- Launching and preparing now wait for a running background update instead of failing with "Another update operation is in progress"; manual update checks wait as well, and launch downloads no longer use the 12-second resource-policy timeout.
- Log what each update check found, every downloaded file, the server requirement, the game resource decision and installed plugins; skip warnings caused by closing the launcher.

Shared:
- Move file hashing and atomic replacement into common/util and use it from the build, release, launcher and server code.
2026-10-19 00:04:02 +08:00

112 lines
3.8 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
clientconfig "bd2server/internal/client/config"
clientinstance "bd2server/internal/client/instance"
clientplugin "bd2server/internal/client/plugin"
clientsetup "bd2server/internal/client/setup"
"bd2server/internal/common/taskgraph"
"bd2server/internal/common/versionconfig"
)
func (t task) runClient2(args []string) error {
fs := flag.NewFlagSet("runClient2", flag.ContinueOnError)
name := fs.String("instance", "player2", "independent local game instance name")
gameDir := fs.String("game-dir", "", "original game installation; defaults to go/config.json")
if err := fs.Parse(args); err != nil {
return err
}
if fs.NArg() != 0 {
return fmt.Errorf("unexpected argument %q", fs.Arg(0))
}
var game, launcher string
var versions versionconfig.Config
var settings clientconfig.Settings
var instance clientinstance.Instance
return t.execute("runClient2",
taskgraph.Task{Name: "instance:configuration", Run: func(context.Context) error {
var err error
game, _, _, err = t.gameDirectory(*gameDir)
if err != nil {
return err
}
versions, err = versionconfig.Load(filepath.Join(t.root, "versions.json"))
if err != nil {
return err
}
if _, err := clientsetup.Inspect(game, versions); err != nil {
return err
}
settings, err = clientconfig.Load(game)
if err != nil {
return fmt.Errorf("save the original client's connection settings first: %w", err)
}
settings.ProxyURL = ""
return nil
}},
taskgraph.Task{Name: "instance:prepare", DependsOn: []string{"instance:configuration"}, Run: func(context.Context) error {
var err error
instance, err = clientinstance.Prepare(*name, game, versions.GameVersion)
if err != nil {
return err
}
if !instance.Created {
settings, err = clientconfig.Load(instance.GameDirectory)
if err != nil {
return fmt.Errorf("load second client's connection settings: %w", err)
}
}
if _, err := clientsetup.SaveSettings(instance.GameDirectory, settings); err != nil {
return fmt.Errorf("prepare second client's resources: %w", err)
}
if settings.CDNMode == clientconfig.CDNLocal {
if err := clientsetup.InstallLocalCatalog(instance.GameDirectory, settings.LocalResourceDirectory, versions.BundleVersion); err != nil {
return fmt.Errorf("prepare second client's catalog: %w", err)
}
}
return nil
}},
taskgraph.Task{Name: "instance:plugins", DependsOn: []string{"instance:prepare"}, Run: func(ctx context.Context) error {
if !instance.Created {
return nil
}
if err := clientplugin.BuildDevelopment(ctx, t.root, game, os.Stdout); err != nil {
return err
}
plugins := func(name string) string {
return filepath.Join(t.root, "plugins", name, "bin", "Release", "netstandard2.1", "BD2"+name+".dll")
}
_, err := clientsetup.InstallPlugins(instance.GameDirectory, plugins("LocalIdentity"), plugins("LoginUI"), plugins("CashShop"), plugins("FChat"))
return err
}},
taskgraph.Task{Name: "instance:launcher", DependsOn: []string{"instance:plugins"}, Run: func(context.Context) error {
var err error
launcher, err = instance.WriteLauncher()
if err != nil {
return err
}
fmt.Println("Second client ready:", launcher)
fmt.Println("Unity log:", filepath.Join(instance.Root, "logs", "Player.log"))
fmt.Println("BepInEx log:", filepath.Join(instance.GameDirectory, "BepInEx", "LogOutput.log"))
return nil
}},
taskgraph.Task{Name: "runClient2", DependsOn: []string{"instance:launcher"}, Run: func(context.Context) error {
if t.target.goos == "windows" {
return exec.CommandContext(t.ctx, "wscript.exe", "//nologo", launcher).Run()
}
command := exec.Command("/bin/sh", launcher)
if err := command.Start(); err != nil {
return err
}
return command.Process.Release()
}},
)
}