From 6ffe0b1cddc1dd3ec23b9695e067828519d5442b Mon Sep 17 00:00:00 2001 From: Sivert Date: Wed, 18 Nov 2026 22:40:12 +0100 Subject: [PATCH] fix(host): read the game files servers run now, not master-install On an instance host the current CS2 lives in games/current and master-install stays at the build it was set up with, so radars, pictures and catalogs came from that old build (no Cobblestone). The agent now asks for the current game folder each time, the way the inventory already does. Co-Authored-By: Claude Opus 5.5 --- src/cmd/cs2-tui/host_cmd.go | 2 +- src/internal/csm/catalog.go | 13 ++++++++++++- src/internal/hostagent/agent.go | 13 ++++++++++--- src/internal/hostagent/assets.go | 5 +++-- src/internal/hostagent/assets_test.go | 5 +++-- src/internal/hostagent/radars.go | 4 ++-- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/cmd/cs2-tui/host_cmd.go b/src/cmd/cs2-tui/host_cmd.go index b399b4bf..10f91267 100644 --- a/src/cmd/cs2-tui/host_cmd.go +++ b/src/cmd/cs2-tui/host_cmd.go @@ -359,7 +359,7 @@ func runAgent() error { OS: csm.HostOSDescription(), Hostname: hostname, Fetcher: &hostagent.Fetcher{Defaults: csm.HostReadyUpDefaults}, - CS2Dir: filepath.Join("/home", csm.ConfiguredCS2User(), "master-install", "game", "csgo"), + CS2Dir: func() string { return filepath.Join(csm.CurrentGameDir(), "game", "csgo") }, Catalog: csm.Catalog, Logf: func(format string, args ...any) { line := prefix + fmt.Sprintf(format, args...) diff --git a/src/internal/csm/catalog.go b/src/internal/csm/catalog.go index 30c8014f..e491630b 100644 --- a/src/internal/csm/catalog.go +++ b/src/internal/csm/catalog.go @@ -26,6 +26,17 @@ var Catalogs = map[string]func(csgoDir, masterDir string, v *gamefiles.VPK) ([]b var catalogMu sync.Mutex +// CurrentGameDir is the CS2 install servers run now: on an instance host the +// current game version (games/current), which master-install lags behind; else master-install. +func CurrentGameDir() string { + if InstancesExist() { + if m, err := NewInstanceManager(); err == nil { + return m.CurrentGame() + } + } + return filepath.Join("/home", ConfiguredCS2User(), "master-install") +} + // Catalog returns maps.json or skins.json for the master install, rebuilt // only when pak01 changed (a CS2 update) and otherwise read from the cache. func Catalog(name string) ([]byte, error) { @@ -33,7 +44,7 @@ func Catalog(name string) ([]byte, error) { if !ok { return nil, fmt.Errorf("no catalog %q", name) } - masterDir := filepath.Join("/home", ConfiguredCS2User(), "master-install") + masterDir := CurrentGameDir() csgoDir := filepath.Join(masterDir, "game", "csgo") pak := filepath.Join(csgoDir, "pak01_dir.vpk") fi, err := os.Stat(pak) diff --git a/src/internal/hostagent/agent.go b/src/internal/hostagent/agent.go index 011df02f..3596208b 100644 --- a/src/internal/hostagent/agent.go +++ b/src/internal/hostagent/agent.go @@ -25,9 +25,9 @@ type Options struct { // Logf receives the agent's log lines; they are redacted first. Logf func(format string, args ...any) - // CS2Dir is the master install's game/csgo; its map radars go to the - // platform for the 2D replay (empty = none). - CS2Dir string + // CS2Dir is the game/csgo servers run now, asked each time: a CS2 update + // moves it (nil or "" = none). Its radars, pictures and catalogs go to the platform. + CS2Dir func() string // Catalog builds maps.json or skins.json from the install (host.asset set "catalog"; nil = none). Catalog func(name string) ([]byte, error) @@ -51,6 +51,13 @@ type Options struct { NotLinkedWait time.Duration } +func (o *Options) csgoDir() string { + if o.CS2Dir == nil { + return "" + } + return o.CS2Dir() +} + func (o *Options) defaults() { if o.InventoryEvery <= 0 { o.InventoryEvery = 60 * time.Second diff --git a/src/internal/hostagent/assets.go b/src/internal/hostagent/assets.go index 8dee5a2e..d8ae59dc 100644 --- a/src/internal/hostagent/assets.go +++ b/src/internal/hostagent/assets.go @@ -15,7 +15,8 @@ import ( // handleAsset reads the picture from the master install and uploads it; the // platform serves and caches it, so nothing of Valve's is kept anywhere else. func (a *Agent) handleAsset(ctx context.Context, ref string, c *AssetCmd) ResultPayload { - if a.opts.CS2Dir == "" { + dir := a.opts.csgoDir() + if dir == "" { return rejected(CodeUnsupported, "this csm has no CS2 install to read pictures from") } var data []byte @@ -28,7 +29,7 @@ func (a *Agent) handleAsset(ctx context.Context, ref string, c *AssetCmd) Result data, err = a.opts.Catalog(c.File) typ = "application/json" } else { - data, typ, err = gamefiles.Asset(a.opts.CS2Dir, c.Set, c.File) + data, typ, err = gamefiles.Asset(dir, c.Set, c.File) } if errors.Is(err, gamefiles.ErrNoAsset) { return failed(CodeNotFound, c.Set+"/"+c.File+" is not in this install", "") diff --git a/src/internal/hostagent/assets_test.go b/src/internal/hostagent/assets_test.go index d96401f5..294de02e 100644 --- a/src/internal/hostagent/assets_test.go +++ b/src/internal/hostagent/assets_test.go @@ -27,7 +27,7 @@ func TestAssetRoundTrip(t *testing.T) { if dir == "" { t.Skip("CS2_DIR not set") } - ta := startAgent(t, 1, "", func(o *Options) { o.CS2Dir = dir }) + ta := startAgent(t, 1, "", func(o *Options) { o.CS2Dir = func() string { return dir } }) ta.p.wait("hello", isType(TypeHello)) for _, c := range [][3]string{ {"skins-256", "weapon_ak47_cu_ak-47_phantom_disruptor.webp", "image/png"}, @@ -53,7 +53,8 @@ func TestAssetRoundTrip(t *testing.T) { func TestCatalogRoundTrip(t *testing.T) { ta := startAgent(t, 1, "", func(o *Options) { - o.CS2Dir = t.TempDir() + tmp := t.TempDir() + o.CS2Dir = func() string { return tmp } o.Catalog = func(name string) ([]byte, error) { return []byte(`{"skins":[]}`), nil } }) ta.p.wait("hello", isType(TypeHello)) diff --git a/src/internal/hostagent/radars.go b/src/internal/hostagent/radars.go index dc814b34..db8c8394 100644 --- a/src/internal/hostagent/radars.go +++ b/src/internal/hostagent/radars.go @@ -11,7 +11,7 @@ import ( // syncRadars sends the install's map radars at start and every 6 hours, once // the host is linked. Only changed textures go up (radars.Sync). func (a *Agent) syncRadars(ctx context.Context) { - if a.opts.CS2Dir == "" { + if a.opts.CS2Dir == nil { return } hc := a.opts.HTTPClient @@ -22,7 +22,7 @@ func (a *Agent) syncRadars(ctx context.Context) { wait := 6 * time.Hour if c, err := LoadCredentials(a.opts.Paths); err != nil { wait = a.opts.NotLinkedWait - } else if err := radars.Sync(ctx, hc, c.PlatformURL, c.Token, a.opts.CS2Dir, a.logf); err != nil { + } else if err := radars.Sync(ctx, hc, c.PlatformURL, c.Token, a.opts.csgoDir(), a.logf); err != nil { a.logf("radars: %v", err) } if !sleepCtx(ctx, wait) {