From e8f3aa60c12e8f0ede925cef5cbccaed918efea0 Mon Sep 17 00:00:00 2001 From: Jordan Dalby <49979347+jordan-dalby@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:23:47 +0000 Subject: [PATCH] Remove auto-save ticker (#129) Co-authored-by: Jordan Dalby --- frontend/src/pages/server/Administration.tsx | 53 ------------- server/helpers.go | 16 ++-- server/server.go | 3 - server/server_controller.go | 82 +------------------- 4 files changed, 9 insertions(+), 145 deletions(-) diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index 076f789..2b1ad83 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -213,58 +213,6 @@ function ServerStartupCard({setServ, serv}: {setServ: React.Dispatch>, serv: server.Server}) { - const {addAlert} = useAlert(); - - const handleAutoSaveIntervalChange = (e: React.ChangeEvent) => { - const newAutoSaveInterval = parseInt(e.target.value, 10); - - if (newAutoSaveInterval > 0) { - setServ((prev) => ({ - ...prev, - autoSaveInterval: newAutoSaveInterval, - convertValues: prev.convertValues, - })); - } else { - addAlert("'Auto-Save Interval' must be greater than 0", "danger") - } - }; - return ( - - - Auto-Save Settings - - - -
-
- setServ((p) => ({ - ...p, - autoSaveEnabled: e.target.checked, - convertValues: p.convertValues - }))}/>
- - Auto-Save Interval (minutes) - { - if (parseInt(e.target.value) < 1) { - e.target.value = "1" - return - } - setServ((p) => ({ - ...p, - autoSaveInterval: parseInt(e.target.value), - convertValues: p.convertValues - })) - }}> - -
-
-
- ) -} - function ExtraSettingsCard({setServ, serv}: {setServ: React.Dispatch>, serv: server.Server}) { return ( @@ -315,7 +263,6 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) { - ); diff --git a/server/helpers.go b/server/helpers.go index 3faaf0f..0812776 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -2,10 +2,6 @@ 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" "io/ioutil" "net" @@ -13,6 +9,11 @@ import ( "path/filepath" "strconv" "strings" + + "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{ @@ -103,9 +104,6 @@ func generateNewDefaultServer(id int) Server { MaxPlayers: 70, StartWithApplication: false, - - AutoSaveEnabled: true, - AutoSaveInterval: 15, } } @@ -164,10 +162,6 @@ func CheckIfServerCorrect(server *Server) error { return fmt.Errorf("server.serverMap is empty") } - if server.AutoSaveInterval <= 0 { - return fmt.Errorf("server.AutoSaveInterval is negative or zero, it must be higher than zero") - } - return nil } diff --git a/server/server.go b/server/server.go index dcfc004..cb2f31d 100644 --- a/server/server.go +++ b/server/server.go @@ -71,9 +71,6 @@ type Server struct { MaxPlayers int `json:"maxPlayers"` StartWithApplication bool `json:"startWithApplication"` - - AutoSaveEnabled bool `json:"autoSaveEnabled"` - AutoSaveInterval int `json:"autoSaveInterval"` } // UpdateConfig updates the configuration files for the server e.g.: GameUserSettings.ini diff --git a/server/server_controller.go b/server/server_controller.go index 7c54a06..a5a6316 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -18,7 +18,6 @@ import ( "os" "path" "strconv" - "time" "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" "github.com/adrg/xdg" @@ -31,11 +30,10 @@ const ( // ServerController struct type ServerController struct { - ctx context.Context - Servers map[int]*Server - helpers *helpers.HelpersController - autoSaveIterations int - serverDir string + ctx context.Context + Servers map[int]*Server + helpers *helpers.HelpersController + serverDir string } //region Struct Initialization and Creation @@ -82,67 +80,6 @@ func (c *ServerController) StartServersWithApplication() { } } -// TODO Remove auto-save feature, it's built into ARK -func (c *ServerController) RunAutoSaveTimer() { - c.autoSaveIterations = 0 - - autoSave := time.NewTicker(time.Minute) - done := make(chan bool) - - runtime.LogInfof(c.ctx, "Server Auto-Save Started") - - go func() { - for { - select { - case <-c.ctx.Done(): // Check if the context is canceled - return - case <-done: - return - case <-autoSave.C: - c.AutoSaveServers() - } - } - }() -} - -func (c *ServerController) AutoSaveServers() { - servers, err := c.getAllServers() - if err != nil { - newErr := fmt.Errorf("Error getting all servers " + err.Error()) - runtime.LogErrorf(c.ctx, newErr.Error()) - return - } - - c.autoSaveIterations += 1 - // seconds in a minute * hours in a day * days, increase days if more days are required - // d - if c.autoSaveIterations == (60 * 24 * 7) { // one week in seconds - // very early max int catch (definitely extendable in the future if necessary) - c.autoSaveIterations = 0 - } - - for id := range servers { - server := c.Servers[id] - if !server.IsServerRunning() || !server.AutoSaveEnabled { - continue - } - - // if interval is multiple of iterations - if server.AutoSaveInterval <= 0 { - runtime.LogError(c.ctx, "Server auto-save interval set 0 or below") - continue - } - if c.autoSaveIterations%server.AutoSaveInterval == 0 { - runtime.LogInfo(c.ctx, "Running autosave for "+server.ServerName) - err = server.SaveWorld() - if err != nil { - newErr := fmt.Errorf("Server auto-save created an error: " + err.Error()) - runtime.LogErrorf(c.ctx, newErr.Error()) - } - } - } -} - //endregion //region Frontend functions @@ -299,10 +236,6 @@ func (c *ServerController) getServerFromDir(id int, shouldReturnNew bool) (Serve return Server{}, fmt.Errorf("Error unmarshalling server config file: " + err.Error()) } - if serv.AutoSaveInterval <= 0 { - serv.AutoSaveInterval = 15 - } - // Check if server is correct. if err := CheckIfServerCorrect(&serv); err != nil { return Server{}, fmt.Errorf("Parsing server instance failed: " + err.Error()) @@ -351,10 +284,6 @@ func (c *ServerController) getServer(id int, addToMap bool) (*Server, error) { return nil, fmt.Errorf("Error getting server instance: %s", err.Error()) } - if s.AutoSaveInterval <= 0 { - s.AutoSaveInterval = 15 - } - if addToMap { c.Servers[id] = &s } @@ -364,9 +293,6 @@ func (c *ServerController) getServer(id int, addToMap bool) (*Server, error) { return &s, nil } else { runtime.EventsEmit(c.ctx, "gotServer", server.Id) - if server.AutoSaveInterval <= 0 { - server.AutoSaveInterval = 15 - } server.ctx = c.ctx return server, nil }