diff --git a/server/server_controller.go b/server/server_controller.go index f6ad9ec..1e0545d 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -60,7 +60,7 @@ func (c *ServerController) Startup(ctx context.Context) { c.serverDir = serverDir c.StartServersWithApplication() - c.RunAutoSaveTimers() + c.RunAutoSaveTimer() } // endregion @@ -87,18 +87,25 @@ func (c *ServerController) StartServersWithApplication() { // having one timer that manages all servers is advantageous: // - catches conditions where a user enables auto-save after the timer has started // - catches interval changes made after the timer has started -func (c *ServerController) RunAutoSaveTimers() { +func (c *ServerController) RunAutoSaveTimer() { c.autoSaveIterations = 0 autoSave := time.NewTicker(time.Minute) - for { - select { - case <-autoSave.C: - c.AutoSaveServers() - default: - continue + done := make(chan bool) + go func() { + for { + select { + case <-done: + return + case <-autoSave.C: + c.AutoSaveServers() + } } - } + }() + + autoSave.Stop() + done <- true + runtime.LogInfof(c.ctx, "Auto-Save Stopped") } func (c *ServerController) AutoSaveServers() { @@ -122,16 +129,16 @@ func (c *ServerController) AutoSaveServers() { if server.AutoSaveEnabled { // if interval is multiple of iterations if server.AutoSaveInterval <= 0 { - runtime.LogError(c.ctx, "Server auto-save interval set 0 or below") + //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) + //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()) + //newErr := fmt.Errorf("Server auto-save created an error: " + err.Error()) + //runtime.LogErrorf(c.ctx, newErr.Error()) } } }