Skip to content

Commit

Permalink
[Release] 4.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jun 1, 2024
1 parent a8cc20e commit 1546119
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [4.5.0] 6/1/2024

**Spire Auto Updates** Add ability to disable auto updates on bootup via **eqemu_config.json** option **spire.disable_auto_updates** if set.

## [4.4.0] 6/1/2024

**Zone Log Streaming** Fix minor issue where unauthenticated users could not stream zone logs.
Expand Down
45 changes: 41 additions & 4 deletions internal/eqemuserverconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ type EQEmuConfigJson struct {
ServerCodePath string `json:"serverCodePath,omitempty"`
} `json:"web-admin,omitempty"`
Spire struct {
EncryptionKey string `json:"encryption_key,omitempty"`
HttpPort int `json:"http_port,omitempty"`
LauncherStart bool `json:"launcher_start"` // starts server launcher
EncryptionKey string `json:"encryption_key,omitempty"`
HttpPort int `json:"http_port,omitempty"`
LauncherStart bool `json:"launcher_start"` // starts server launcher
DisableAutoUpdates bool `json:"disable_auto_updates,omitempty"` // disable auto updates
} `json:"spire,omitempty"`
}

Expand All @@ -165,8 +166,12 @@ var lock = &sync.Mutex{}
// We utilize a cache to prevent reading the file on every call
func (e *Config) Get() EQEmuConfigJson {
configFile := e.pathmgmt.GetEQEmuServerConfigFilePath()
stat, err := os.Stat(configFile)
if err != nil {
return EQEmuConfigJson{}
}

if len(configFile) > 0 {
stat, _ := os.Stat(configFile)
if stat.ModTime().After(lastModifiedTime) || lastModifiedTime.IsZero() {
e.logger.Debug().Any("path", configFile).Msg("Reading eqemu config file")
body, err := os.ReadFile(e.pathmgmt.GetEQEmuServerConfigFilePath())
Expand Down Expand Up @@ -194,6 +199,38 @@ func (e *Config) Get() EQEmuConfigJson {
return EQEmuConfigJson{}
}

// GetIfExists returns the eqemu config json if the file exists
// This function shouldn't really exist and the original getter should have bubbled errors up
// Clean all of this up another time
func (e *Config) GetIfExists() (EQEmuConfigJson, bool) {
configFile := e.pathmgmt.GetEQEmuServerConfigFilePath()
stat, err := os.Stat(configFile)
if err != nil {
return EQEmuConfigJson{}, false
}

if len(configFile) > 0 {
if err == nil && stat.ModTime().After(lastModifiedTime) || lastModifiedTime.IsZero() {
e.logger.Debug().Any("path", configFile).Msg("Reading eqemu config file")
body, _ := os.ReadFile(e.pathmgmt.GetEQEmuServerConfigFilePath())

config := EQEmuConfigJson{}
_ = json.Unmarshal(body, &config)

lastModifiedTime = stat.ModTime()
lock.Lock()
cachedConfig = &config
lock.Unlock()

return config, true
} else if cachedConfig != nil {
return *cachedConfig, true
}
}

return EQEmuConfigJson{}, false
}

// Exists will return true if the eqemu_config.json file exists
func (e *Config) Exists() bool {
return len(e.pathmgmt.GetEQEmuServerConfigFilePath()) > 0
Expand Down
20 changes: 17 additions & 3 deletions internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"github.com/Akkadius/spire/internal/download"
"github.com/Akkadius/spire/internal/env"
"github.com/Akkadius/spire/internal/eqemuserverconfig"
"github.com/Akkadius/spire/internal/logger"
"github.com/Akkadius/spire/internal/pathmgmt"
"github.com/Akkadius/spire/internal/unzip"
"github.com/google/go-github/v41/github"
"github.com/mattn/go-isatty"
Expand All @@ -23,15 +25,22 @@ import (
// Updater is a service that checks for updates to the app
type Updater struct {
// this is the package.json embedded in the binary which contains the app version
packageJson []byte
logger *logger.AppLogger
packageJson []byte
logger *logger.AppLogger
serverconfig *eqemuserverconfig.Config
}

// NewUpdater creates a new updater service
func NewUpdater(packageJson []byte) *Updater {
appLogger := logger.ProvideAppLogger()
pathmgr := pathmgmt.NewPathManagement(appLogger)
return &Updater{
packageJson: packageJson,
logger: logger.ProvideAppLogger(),
logger: appLogger,
serverconfig: eqemuserverconfig.NewConfig(
appLogger,
pathmgr,
),
}
}

Expand Down Expand Up @@ -67,6 +76,11 @@ func (s *Updater) getAppVersion() (error, EnvResponse) {

// CheckForUpdates checks for updates to the app
func (s *Updater) CheckForUpdates(interactive bool) bool {
config, exists := s.serverconfig.GetIfExists()
if exists && config.Spire.DisableAutoUpdates {
s.logger.Info().Any("spire.disable_auto_updates", config.Spire.DisableAutoUpdates).Msg("Auto updates are disabled via config")
return false
}

// get executable name and path
executableName := filepath.Base(os.Args[0])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "4.4.0",
"version": "4.5.0",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
Expand Down

0 comments on commit 1546119

Please sign in to comment.