From cdbc11c4b2034cfe2d9d498c1ad09888c3ba7ed4 Mon Sep 17 00:00:00 2001 From: wish Date: Thu, 4 Aug 2022 23:11:19 +1000 Subject: [PATCH] add option to disable soft-crashing --- config.json | 1 + config/config.go | 7 ++++--- main.go | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 2fc4ffc9d..c5bf94ca3 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,7 @@ { "host_ip": "127.0.0.1", "bin_path": "bin", + "DisableSoftCrash": false, "devmode": true, "devmodeoptions": { "serverName" : "", diff --git a/config/config.go b/config/config.go index 7b353c811..1f9587a50 100644 --- a/config/config.go +++ b/config/config.go @@ -9,9 +9,10 @@ import ( // Config holds the global server-wide config. type Config struct { - HostIP string `mapstructure:"host_ip"` - BinPath string `mapstructure:"bin_path"` - DevMode bool + HostIP string `mapstructure:"host_ip"` + BinPath string `mapstructure:"bin_path"` + DisableSoftCrash bool + DevMode bool DevModeOptions DevModeOptions Discord Discord diff --git a/main.go b/main.go index d39f284ea..c950d3bef 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,8 @@ import ( "go.uber.org/zap" ) +var erupeConfig *config.Config + // Temporary DB auto clean on startup for quick development & testing. func cleanDB(db *sqlx.DB) { _ = db.MustExec("DELETE FROM guild_characters") @@ -29,6 +31,7 @@ func cleanDB(db *sqlx.DB) { } func main() { + var err error zapLogger, _ := zap.NewDevelopment() defer zapLogger.Sync() logger := zapLogger.Named("main") @@ -36,7 +39,7 @@ func main() { logger.Info("Starting Erupe") // Load the configuration. - erupeConfig, err := config.LoadConfig() + erupeConfig, err = config.LoadConfig() if err != nil { preventClose(fmt.Sprintf("Failed to load config: %s", err.Error())) } @@ -209,6 +212,9 @@ func wait() { } func preventClose(text string) { + if erupeConfig.DisableSoftCrash { + os.Exit(0) + } fmt.Println("\nFailed to start Erupe:\n" + text) go wait() fmt.Println("\nPress Enter/Return to exit...")