Skip to content

Commit

Permalink
Add support for TShock versions prior to 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
btvoidx committed Aug 20, 2021
1 parent 655bd66 commit af3ea23
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TShockConfig struct {
Settings struct {
ApplicationRestTokens map[string](map[string]int)
}
ApplicationRestTokens map[string](map[string]int)
}

func MakeDefaultConfig() Config {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit af3ea23

Please sign in to comment.