Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Refactored passing args to exec.Command #73

Merged
merged 1 commit into from
Nov 4, 2023
Merged
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
24 changes: 19 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path"
"strconv"
"strings"
)

// Server contains the server "stuff"
Expand Down Expand Up @@ -78,7 +79,12 @@ func (s *Server) Start() error {
if s.IsServerRunning() {
return fmt.Errorf("error starting server: server is already running")
} else {
s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), s.CreateArguments())

qargs, dargs := s.CreateArguments()

args := append([]string{qargs}, dargs...)

s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), args...)
err = s.Command.Start()
if err != nil {
return fmt.Errorf("error starting server: %v", err)
Expand Down Expand Up @@ -162,7 +168,8 @@ func (s *Server) IsServerRunning() bool {
}
}

func (s *Server) CreateArguments() string {
// returns questionamrk arguments for the server and dash arguments for the server
func (s *Server) CreateArguments() (string, []string) {
basePrompt := s.ServerMap + "?listen"
basePrompt += "?MultiHome=" + s.IpAddress
basePrompt += "?SessionName=" + s.ServerName
Expand All @@ -174,10 +181,17 @@ func (s *Server) CreateArguments() string {
//TODO move AdminPassword to ini
basePrompt += "?ServerAdminPassword=" + s.AdminPassword + "?"

var dashArgs []string = []string{}

if s.Mods != "" {
basePrompt += " -mods=" + s.Mods
dashArgs = append(dashArgs, "-mods="+s.Mods)
}

extraArgs := strings.Split(s.ExtraDashArgs, " ")

for _, arg := range extraArgs {
dashArgs = append(dashArgs, arg)
}
basePrompt += " " + s.ExtraDashArgs

return basePrompt
return basePrompt, dashArgs
}
Loading