From af3ea23fafa6e663256d91a2d92c075341b41fad Mon Sep 17 00:00:00 2001 From: btvoidx Date: Fri, 20 Aug 2021 17:39:08 +0400 Subject: [PATCH] Add support for TShock versions prior to 4.5 --- config.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 7cb8712..7b69ef6 100644 --- a/config.go +++ b/config.go @@ -24,6 +24,7 @@ type TShockConfig struct { Settings struct { ApplicationRestTokens map[string](map[string]int) } + ApplicationRestTokens map[string](map[string]int) } func MakeDefaultConfig() Config { @@ -56,9 +57,15 @@ func LoadConfig() Config { jsondata, _ := ioutil.ReadAll(file) json.Unmarshal(jsondata, &config) - if config.TShockConfig == "" { + if config.RestUrl == "" { + fmt.Println("RestUrl is not set") + os.Exit(2) + } else if config.TShockConfig == "" { fmt.Println("TShockConfig is not set") os.Exit(2) + } else if config.VKToken == "" { + fmt.Println("VKToken is not set") + os.Exit(2) } LoadTShockTokens(config.TShockConfig, &config) @@ -82,7 +89,15 @@ func LoadTShockTokens(path string, config *Config) { var tshockConfig TShockConfig json.Unmarshal(data, &tshockConfig) - for k, v := range tshockConfig.Settings.ApplicationRestTokens { + // TShock changed config format in 4.5, so script needs to check both prior and newer config paths + var tokens map[string](map[string]int) + if len(tshockConfig.Settings.ApplicationRestTokens) != 0 { + tokens = tshockConfig.Settings.ApplicationRestTokens + } else { + tokens = tshockConfig.ApplicationRestTokens + } + + for k, v := range tokens { userId := v["VKId"] if userId == 0 {