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

Commit

Permalink
refactored passing args to exec.Command (#73)
Browse files Browse the repository at this point in the history
this way each arg is their own string (this is how it should be)
  • Loading branch information
JensvandeWiel authored Nov 4, 2023
1 parent 0133225 commit a7549c6
Showing 1 changed file with 19 additions and 5 deletions.
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
}

0 comments on commit a7549c6

Please sign in to comment.