From f1cd413bc8b5e5a01dae436ddab5d743075ab99f Mon Sep 17 00:00:00 2001 From: Jordan Dalby Date: Thu, 16 Nov 2023 21:21:41 +0000 Subject: [PATCH] Add start with application option - This option enables servers to start when the application is launched which is useful if a host machine powers down (for any reason). --- frontend/src/pages/server/Administration.tsx | 6 ++++++ server/helpers.go | 11 +++++++---- server/server.go | 3 +++ server/server_controller.go | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index ab7c1b6..7ae1b8f 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -185,6 +185,12 @@ function ServerStartupCard({setServ, serv}: {setServ: React.Dispatch
{/* setServ((p) => ({ ...p, restartOnServerQuit: e.target.checked }))} />*/} + setServ((p) => ({ + ...p, + startWithApplication: e.target.checked, + convertValues: p.convertValues + }))}/>
Custom server "dash" arguments (only use args like: -EnableIdlePlayerKick -ForceAllowCaveFlyers) diff --git a/server/helpers.go b/server/helpers.go index ae7c6cc..64daf6f 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -2,15 +2,16 @@ package server import ( "fmt" - "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" - "github.com/go-ini/ini" - "github.com/sethvargo/go-password/password" - "github.com/wailsapp/wails/v2/pkg/runtime" "io" "net" "os" "path/filepath" "strconv" + + "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" + "github.com/go-ini/ini" + "github.com/sethvargo/go-password/password" + "github.com/wailsapp/wails/v2/pkg/runtime" ) var iniOpts = ini.LoadOptions{ @@ -77,6 +78,8 @@ func generateNewDefaultServer(id int) Server { ServerMap: "TheIsland_WP", MaxPlayers: 70, + + StartWithApplication: false, } } diff --git a/server/server.go b/server/server.go index 9dc5fac..33ed1bd 100644 --- a/server/server.go +++ b/server/server.go @@ -67,6 +67,8 @@ type Server struct { ServerMap string `json:"serverMap"` MaxPlayers int `json:"maxPlayers"` + + StartWithApplication bool `json:"startWithApplication"` } // UpdateConfig updates the configuration files for the server e.g.: GameUserSettings.ini @@ -96,6 +98,7 @@ func (s *Server) UpdateConfig() error { //TODO Add configuration parsing/loading/saving for server specific files //TODO Add startup arguments parsing +//TODO Add check for running application (ensures no accidental duplicated servers, especially with addition of start with application) func (s *Server) Start() error { diff --git a/server/server_controller.go b/server/server_controller.go index f90cff9..84ac37f 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -55,6 +55,25 @@ func (c *ServerController) Startup(ctx context.Context) { } c.serverDir = serverDir + + c.StartServersWithApplication() +} + +func (c *ServerController) StartServersWithApplication() { + servers, err := c.getAllServers() + if err != nil { + newErr := fmt.Errorf("Error getting all servers " + err.Error()) + runtime.LogErrorf(c.ctx, newErr.Error()) + return + } + + for id := range servers { + server := c.Servers[id] + runtime.LogInfof(c.ctx, "StartWithApplication: %t", server.StartWithApplication) + if server.StartWithApplication { + c.StartServer(server.Id) + } + } } //endregion