feat: add Wine Z: path prefix for Windows platform on Linux host
CI / build (push) Successful in 1m44s
CI / build (push) Successful in 1m44s
- Add winePath helper that prepends Z: when platform is windows on Linux - Thread platform through buildModPath, buildAutoArgs, and Start() - Apply Z: prefix to -config=, -mod=, -profiles=, and %command% binary paths - Add tests for winePath, buildAutoArgs, and buildModPath with platform param - Fix formatting across services package with gofmt - Include all prior bug fixes from this branch
This commit is contained in:
@@ -76,7 +76,7 @@ func (h *Handler) Health(c *gin.Context) {
|
||||
Running: h.steamcmd.IsRunning(),
|
||||
},
|
||||
Frontend: FrontendHealth{
|
||||
Served: true,
|
||||
Served: h.frontendServed,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -140,8 +140,6 @@ func findServerBinary(serverfileDir string) (string, bool) {
|
||||
candidates := []string{"arma3server_x64"}
|
||||
if runtime.GOOS == "windows" {
|
||||
candidates = append(candidates, "arma3server_x64.exe")
|
||||
} else {
|
||||
candidates = append(candidates, "arma3server_x64.exe")
|
||||
}
|
||||
for _, name := range candidates {
|
||||
p := filepath.Join(serverfileDir, name)
|
||||
|
||||
@@ -117,7 +117,9 @@ func (h *Handler) StreamRPTLogs(c *gin.Context) {
|
||||
if currentPath == "" {
|
||||
continue
|
||||
}
|
||||
conn.WriteMessage(websocket.TextMessage, []byte("--- tailing: "+filepath.Base(currentPath)+" ---"))
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte("--- tailing: "+filepath.Base(currentPath)+" ---")); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if currentPath == "" {
|
||||
continue
|
||||
|
||||
@@ -7,18 +7,19 @@ import (
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
settings *services.SettingsManager
|
||||
configs *services.ConfigManager
|
||||
modlists *services.ModlistManager
|
||||
process *services.ProcessManager
|
||||
steamcmd *services.SteamCmdManager
|
||||
scheduler *services.Scheduler
|
||||
streamer *services.LogStreamer
|
||||
dataDir string
|
||||
serverfileDir string
|
||||
modsDir string
|
||||
cfgDir string
|
||||
profilesDir string
|
||||
settings *services.SettingsManager
|
||||
configs *services.ConfigManager
|
||||
modlists *services.ModlistManager
|
||||
process *services.ProcessManager
|
||||
steamcmd *services.SteamCmdManager
|
||||
scheduler *services.Scheduler
|
||||
streamer *services.LogStreamer
|
||||
dataDir string
|
||||
serverfileDir string
|
||||
modsDir string
|
||||
cfgDir string
|
||||
profilesDir string
|
||||
frontendServed bool
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -30,20 +31,22 @@ func New(
|
||||
scheduler *services.Scheduler,
|
||||
streamer *services.LogStreamer,
|
||||
dataDir, serverfileDir, modsDir, cfgDir, profilesDir string,
|
||||
frontendServed bool,
|
||||
) *Handler {
|
||||
return &Handler{
|
||||
settings: settings,
|
||||
configs: configs,
|
||||
modlists: modlists,
|
||||
process: process,
|
||||
steamcmd: steamcmd,
|
||||
scheduler: scheduler,
|
||||
streamer: streamer,
|
||||
dataDir: dataDir,
|
||||
serverfileDir: serverfileDir,
|
||||
modsDir: modsDir,
|
||||
cfgDir: cfgDir,
|
||||
profilesDir: profilesDir,
|
||||
settings: settings,
|
||||
configs: configs,
|
||||
modlists: modlists,
|
||||
process: process,
|
||||
steamcmd: steamcmd,
|
||||
scheduler: scheduler,
|
||||
streamer: streamer,
|
||||
dataDir: dataDir,
|
||||
serverfileDir: serverfileDir,
|
||||
modsDir: modsDir,
|
||||
cfgDir: cfgDir,
|
||||
profilesDir: profilesDir,
|
||||
frontendServed: frontendServed,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ func NewConfigManager(cfgDir string) *ConfigManager {
|
||||
}
|
||||
|
||||
type ConfigInfo struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) List() ([]ConfigInfo, error) {
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type LogStreamer struct {
|
||||
mu sync.RWMutex
|
||||
subs map[string]map[string]chan string
|
||||
mu sync.RWMutex
|
||||
subs map[string]map[string]chan string
|
||||
}
|
||||
|
||||
func NewLogStreamer() *LogStreamer {
|
||||
|
||||
@@ -60,8 +60,8 @@ func ListLocalMods(modsDir string) []ModInfo {
|
||||
displayName = name[1:]
|
||||
}
|
||||
mods = append(mods, ModInfo{
|
||||
ID: displayName,
|
||||
Name: name,
|
||||
ID: displayName,
|
||||
Name: name,
|
||||
Source: "local",
|
||||
Path: p,
|
||||
Size: size,
|
||||
|
||||
@@ -63,7 +63,7 @@ func (s *Scheduler) runScheduledUpdate() {
|
||||
return
|
||||
}
|
||||
|
||||
if sett.SteamUser != "" && sett.SteamUser != "anonymous" {
|
||||
if sett.SteamUser != "" {
|
||||
log.Print("scheduler: running gameserver update")
|
||||
if err := s.steamcmd.UpdateGame(sett.SteamBranch, sett.SteamUser); err != nil {
|
||||
log.Printf("scheduler: game update failed: %v", err)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -14,6 +15,13 @@ import (
|
||||
"arma3-web-server/internal/models"
|
||||
)
|
||||
|
||||
func winePath(path, platform string) string {
|
||||
if platform == "windows" && runtime.GOOS != "windows" {
|
||||
return "Z:" + path
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
type procState int32
|
||||
|
||||
const (
|
||||
@@ -101,7 +109,7 @@ func (pm *ProcessManager) Start() error {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
var cmd *exec.Cmd
|
||||
if strings.Contains(s.ServerParameters, "%command%") {
|
||||
full := strings.ReplaceAll(s.ServerParameters, "%command%", binPath)
|
||||
full := strings.ReplaceAll(s.ServerParameters, "%command%", winePath(binPath, s.Platform))
|
||||
parts := splitArgs(full)
|
||||
if len(parts) == 0 {
|
||||
cancel()
|
||||
@@ -205,18 +213,18 @@ func (pm *ProcessManager) buildAutoArgs(s *models.ServerSettings) []string {
|
||||
|
||||
if s.ActiveConfig != "" {
|
||||
cfgPath := filepath.Join(pm.cfgDir, s.ActiveConfig+".cfg")
|
||||
args = append(args, "-config="+cfgPath)
|
||||
args = append(args, "-config="+winePath(cfgPath, s.Platform))
|
||||
}
|
||||
|
||||
if s.ActiveModlist != "" {
|
||||
modPath := pm.buildModPath(s.ActiveModlist)
|
||||
modPath := pm.buildModPath(s.ActiveModlist, s.Platform)
|
||||
if modPath != "" {
|
||||
args = append(args, modPath)
|
||||
}
|
||||
}
|
||||
|
||||
if pm.profilesDir != "" && !hasArgPrefix(args, "-profiles=") {
|
||||
args = append(args, "-profiles="+pm.profilesDir)
|
||||
args = append(args, "-profiles="+winePath(pm.profilesDir, s.Platform))
|
||||
}
|
||||
|
||||
if s.IPPort != "" && !hasArgPrefix(args, "-port=") {
|
||||
@@ -245,7 +253,7 @@ func hasArgPrefix(args []string, prefix string) bool {
|
||||
|
||||
const workshopAppID = "107410"
|
||||
|
||||
func (pm *ProcessManager) buildModPath(modlistID string) string {
|
||||
func (pm *ProcessManager) buildModPath(modlistID string, platform string) string {
|
||||
ml, err := pm.modlists.Get(modlistID)
|
||||
if err != nil {
|
||||
return ""
|
||||
@@ -256,7 +264,7 @@ func (pm *ProcessManager) buildModPath(modlistID string) string {
|
||||
if !mod.Enabled {
|
||||
continue
|
||||
}
|
||||
parts = append(parts, pm.resolveModPath(mod))
|
||||
parts = append(parts, winePath(pm.resolveModPath(mod), platform))
|
||||
}
|
||||
|
||||
if len(parts) == 0 {
|
||||
|
||||
@@ -294,7 +294,7 @@ func TestBuildModPath_MultipleMods(t *testing.T) {
|
||||
{Name: "DisabledMod", Enabled: false},
|
||||
})
|
||||
|
||||
got := pm.buildModPath(ml.ID)
|
||||
got := pm.buildModPath(ml.ID, "")
|
||||
if !strings.HasPrefix(got, "-mod=") {
|
||||
t.Errorf("expected -mod= prefix, got %q", got)
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func TestBuildModPath_EmptyModlist(t *testing.T) {
|
||||
|
||||
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
|
||||
|
||||
got := pm.buildModPath("nonexistent-id")
|
||||
got := pm.buildModPath("nonexistent-id", "")
|
||||
if got != "" {
|
||||
t.Errorf("buildModPath(nonexistent) = %q, want empty", got)
|
||||
}
|
||||
@@ -338,8 +338,8 @@ func TestWriteUserconfigFiles(t *testing.T) {
|
||||
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
|
||||
|
||||
s := &models.ServerSettings{
|
||||
CBASettings: "force = 1",
|
||||
AILevelPresets: "preset1",
|
||||
CBASettings: "force = 1",
|
||||
AILevelPresets: "preset1",
|
||||
DifficultyPresets: "difficulty_normal",
|
||||
}
|
||||
|
||||
@@ -396,6 +396,142 @@ func TestWriteUserconfigFiles_EmptyContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWinePath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
platform string
|
||||
want string
|
||||
}{
|
||||
{"linux platform returns as-is", "/server/cfg/test.cfg", "linux", "/server/cfg/test.cfg"},
|
||||
{"empty platform returns as-is", "/server/cfg/test.cfg", "", "/server/cfg/test.cfg"},
|
||||
{"windows platform on linux adds prefix", "/server/cfg/test.cfg", "windows", "Z:/server/cfg/test.cfg"},
|
||||
{"empty path linux", "", "linux", ""},
|
||||
{"empty path windows", "", "windows", "Z:"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := winePath(tt.path, tt.platform)
|
||||
if got != tt.want {
|
||||
t.Errorf("winePath(%q, %q) = %q, want %q", tt.path, tt.platform, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAutoArgs_WindowsPlatform(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfgDir := filepath.Join(dir, "cfg")
|
||||
profilesDir := filepath.Join(dir, "profiles")
|
||||
modsDir := filepath.Join(dir, "mods")
|
||||
|
||||
sm := NewSettingsManager(dir)
|
||||
mm := NewModlistManager(filepath.Join(dir, "modlists"))
|
||||
cm := NewConfigManager(cfgDir)
|
||||
streamer := NewLogStreamer()
|
||||
|
||||
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
|
||||
|
||||
s := &models.ServerSettings{
|
||||
Platform: "windows",
|
||||
ActiveConfig: "server_config",
|
||||
IPPort: "0.0.0.0:2302",
|
||||
}
|
||||
|
||||
args := pm.buildAutoArgs(s)
|
||||
|
||||
foundConfig := false
|
||||
foundProfiles := false
|
||||
for _, a := range args {
|
||||
if strings.HasPrefix(a, "-config=Z:") && strings.HasSuffix(a, "server_config.cfg") {
|
||||
foundConfig = true
|
||||
}
|
||||
if strings.HasPrefix(a, "-profiles=Z:") {
|
||||
foundProfiles = true
|
||||
}
|
||||
}
|
||||
if !foundConfig {
|
||||
t.Errorf("expected -config=Z:...server_config.cfg in args, got %v", args)
|
||||
}
|
||||
if !foundProfiles {
|
||||
t.Errorf("expected -profiles=Z:... in args, got %v", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAutoArgs_LinuxPlatform(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfgDir := filepath.Join(dir, "cfg")
|
||||
profilesDir := filepath.Join(dir, "profiles")
|
||||
modsDir := filepath.Join(dir, "mods")
|
||||
|
||||
sm := NewSettingsManager(dir)
|
||||
mm := NewModlistManager(filepath.Join(dir, "modlists"))
|
||||
cm := NewConfigManager(cfgDir)
|
||||
streamer := NewLogStreamer()
|
||||
|
||||
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
|
||||
|
||||
s := &models.ServerSettings{
|
||||
Platform: "linux",
|
||||
ActiveConfig: "server_config",
|
||||
IPPort: "0.0.0.0:2302",
|
||||
}
|
||||
|
||||
args := pm.buildAutoArgs(s)
|
||||
|
||||
for _, a := range args {
|
||||
if strings.HasPrefix(a, "-config=Z:") {
|
||||
t.Errorf("unexpected Z: prefix in args: %v", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildModPath_WindowsPlatform(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
modsDir := filepath.Join(dir, "mods")
|
||||
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
|
||||
|
||||
sm := NewSettingsManager(dir)
|
||||
mm := NewModlistManager(filepath.Join(dir, "modlists"))
|
||||
cm := NewConfigManager(filepath.Join(dir, "cfg"))
|
||||
streamer := NewLogStreamer()
|
||||
|
||||
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
|
||||
|
||||
ml, _ := mm.Create("Test List")
|
||||
mm.Update(ml.ID, "Test List", []models.ModEntry{
|
||||
{Name: "CBA_A3", Enabled: true},
|
||||
})
|
||||
|
||||
got := pm.buildModPath(ml.ID, "windows")
|
||||
if !strings.HasPrefix(got, "-mod=Z:") {
|
||||
t.Errorf("expected -mod=Z: prefix, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildModPath_LinuxPlatform(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
modsDir := filepath.Join(dir, "mods")
|
||||
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
|
||||
|
||||
sm := NewSettingsManager(dir)
|
||||
mm := NewModlistManager(filepath.Join(dir, "modlists"))
|
||||
cm := NewConfigManager(filepath.Join(dir, "cfg"))
|
||||
streamer := NewLogStreamer()
|
||||
|
||||
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
|
||||
|
||||
ml, _ := mm.Create("Test List")
|
||||
mm.Update(ml.ID, "Test List", []models.ModEntry{
|
||||
{Name: "CBA_A3", Enabled: true},
|
||||
})
|
||||
|
||||
got := pm.buildModPath(ml.ID, "linux")
|
||||
if strings.Contains(got, "Z:") {
|
||||
t.Errorf("unexpected Z: prefix in args: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartAndStopWithStub(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
serverfileDir := filepath.Join(dir, "server")
|
||||
|
||||
@@ -54,18 +54,18 @@ func (sm *SettingsManager) Save(s *models.ServerSettings) error {
|
||||
|
||||
func (sm *SettingsManager) defaults() *models.ServerSettings {
|
||||
return &models.ServerSettings{
|
||||
IPPort: "0.0.0.0:2302",
|
||||
ServerParameters: "-server -world=empty -loadMissionToMemory -noPause",
|
||||
SteamBranch: "stable",
|
||||
SteamUser: "anonymous",
|
||||
Platform: "linux",
|
||||
ActiveConfig: "",
|
||||
ActiveModlist: "",
|
||||
AutoUpdateOnStartup: false,
|
||||
AutoStartOnStartup: false,
|
||||
IPPort: "0.0.0.0:2302",
|
||||
ServerParameters: "-server -world=empty -loadMissionToMemory -noPause",
|
||||
SteamBranch: "stable",
|
||||
SteamUser: "anonymous",
|
||||
Platform: "linux",
|
||||
ActiveConfig: "",
|
||||
ActiveModlist: "",
|
||||
AutoUpdateOnStartup: false,
|
||||
AutoStartOnStartup: false,
|
||||
AutoUpdateModsOnStartup: false,
|
||||
WasRunning: false,
|
||||
ScheduledUpdate: "",
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
WasRunning: false,
|
||||
ScheduledUpdate: "",
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user