Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/cs2-tui/host_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
13 changes: 12 additions & 1 deletion src/internal/csm/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ 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) {
build, ok := Catalogs[name]
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)
Expand Down
13 changes: 10 additions & 3 deletions src/internal/hostagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/internal/hostagent/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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", "")
Expand Down
5 changes: 3 additions & 2 deletions src/internal/hostagent/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/internal/hostagent/radars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Loading