2023-11-01 21:51:14 +00:00
|
|
|
package aid
|
|
|
|
|
|
|
|
import (
|
2023-11-05 01:58:00 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2023-11-01 21:51:14 +00:00
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CS struct {
|
2024-02-03 02:09:09 +00:00
|
|
|
Accounts struct {
|
|
|
|
Gods []string
|
2024-02-10 00:33:10 +00:00
|
|
|
Owners []string
|
2024-02-03 02:09:09 +00:00
|
|
|
}
|
2023-11-01 21:51:14 +00:00
|
|
|
Database struct {
|
|
|
|
URI string
|
|
|
|
Type string
|
2023-11-02 17:50:52 +00:00
|
|
|
DropAllTables bool
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|
2023-12-09 15:35:33 +00:00
|
|
|
Discord struct {
|
|
|
|
ID string
|
|
|
|
Secret string
|
|
|
|
Token string
|
2023-12-13 22:52:16 +00:00
|
|
|
Guild string
|
2023-12-09 15:35:33 +00:00
|
|
|
}
|
2024-02-04 19:49:31 +00:00
|
|
|
Amazon struct {
|
|
|
|
Enabled bool
|
|
|
|
BucketURI string
|
|
|
|
AccessKeyID string
|
|
|
|
SecretAccessKey string
|
|
|
|
ClientSettingsBucket string
|
|
|
|
}
|
2023-11-01 21:51:14 +00:00
|
|
|
Output struct {
|
|
|
|
Level string
|
|
|
|
}
|
2023-11-03 23:48:50 +00:00
|
|
|
API struct {
|
|
|
|
Host string
|
|
|
|
Port string
|
2023-12-10 00:52:59 +00:00
|
|
|
FrontendPort string
|
2024-02-10 15:26:28 +00:00
|
|
|
Debug bool
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
|
|
|
JWT struct {
|
|
|
|
Secret string
|
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
Fortnite struct {
|
|
|
|
Season int
|
|
|
|
Build float64
|
2023-11-20 23:20:42 +00:00
|
|
|
Everything bool
|
2024-01-20 23:25:12 +00:00
|
|
|
Password bool
|
2024-01-28 19:40:45 +00:00
|
|
|
DisableClientCredentials bool
|
2023-11-05 01:58:00 +00:00
|
|
|
}
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
Config *CS
|
|
|
|
)
|
|
|
|
|
2023-12-09 14:32:53 +00:00
|
|
|
func LoadConfig(file []byte) {
|
2023-11-01 21:51:14 +00:00
|
|
|
Config = &CS{}
|
2023-12-09 14:32:53 +00:00
|
|
|
|
|
|
|
cfg, err := ini.Load(file)
|
2023-11-01 21:51:14 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2024-02-03 02:09:09 +00:00
|
|
|
Config.Accounts.Gods = cfg.Section("accounts").Key("gods").Strings(",")
|
2024-02-10 00:33:10 +00:00
|
|
|
Config.Accounts.Owners = cfg.Section("accounts").Key("owners").Strings(",")
|
2023-11-02 17:50:52 +00:00
|
|
|
Config.Database.DropAllTables = cfg.Section("database").Key("drop").MustBool(false)
|
2023-11-01 21:51:14 +00:00
|
|
|
Config.Database.URI = cfg.Section("database").Key("uri").String()
|
|
|
|
if Config.Database.URI == "" {
|
|
|
|
panic("Database URI is empty")
|
|
|
|
}
|
|
|
|
Config.Database.Type = cfg.Section("database").Key("type").String()
|
|
|
|
if Config.Database.Type == "" {
|
|
|
|
panic("Database Type is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Output.Level = cfg.Section("output").Key("level").String()
|
|
|
|
if Config.Output.Level == "" {
|
|
|
|
panic("Output Level is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if Config.Output.Level != "dev" && Config.Output.Level != "prod" && Config.Output.Level != "time" && Config.Output.Level != "info" {
|
|
|
|
panic("Output Level must be either dev or prod")
|
|
|
|
}
|
2023-11-03 23:48:50 +00:00
|
|
|
|
2023-12-09 15:35:33 +00:00
|
|
|
Config.Discord.ID = cfg.Section("discord").Key("id").String()
|
|
|
|
if Config.Discord.ID == "" {
|
|
|
|
panic("Discord Client ID is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Discord.Secret = cfg.Section("discord").Key("secret").String()
|
|
|
|
if Config.Discord.Secret == "" {
|
|
|
|
panic("Discord Client Secret is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Discord.Token = cfg.Section("discord").Key("token").String()
|
|
|
|
if Config.Discord.Token == "" {
|
|
|
|
panic("Discord Bot Token is empty")
|
|
|
|
}
|
|
|
|
|
2023-12-13 22:52:16 +00:00
|
|
|
Config.Discord.Guild = cfg.Section("discord").Key("guild").String()
|
|
|
|
if Config.Discord.Guild == "" {
|
|
|
|
panic("Discord Guild ID is empty")
|
|
|
|
}
|
|
|
|
|
2024-02-04 19:49:31 +00:00
|
|
|
Config.Amazon.Enabled = true
|
|
|
|
Config.Amazon.BucketURI = cfg.Section("amazon").Key("uri").String()
|
|
|
|
if Config.Amazon.BucketURI == "" {
|
|
|
|
Config.Amazon.Enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Amazon.AccessKeyID = cfg.Section("amazon").Key("id").String()
|
|
|
|
if Config.Amazon.AccessKeyID == "" {
|
|
|
|
Config.Amazon.Enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Amazon.SecretAccessKey = cfg.Section("amazon").Key("key").String()
|
|
|
|
if Config.Amazon.SecretAccessKey == "" {
|
|
|
|
Config.Amazon.Enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Amazon.ClientSettingsBucket = cfg.Section("amazon").Key("bucket").String()
|
|
|
|
if Config.Amazon.ClientSettingsBucket == "" {
|
|
|
|
Config.Amazon.Enabled = false
|
|
|
|
}
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
Config.API.Host = cfg.Section("api").Key("host").String()
|
|
|
|
if Config.API.Host == "" {
|
|
|
|
panic("API Host is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.API.Port = cfg.Section("api").Key("port").String()
|
|
|
|
if Config.API.Port == "" {
|
|
|
|
panic("API Port is empty")
|
|
|
|
}
|
|
|
|
|
2023-12-10 00:52:59 +00:00
|
|
|
Config.API.FrontendPort = cfg.Section("api").Key("frontend_port").String()
|
|
|
|
if Config.API.FrontendPort == "" {
|
|
|
|
Config.API.FrontendPort = Config.API.Port
|
|
|
|
}
|
|
|
|
|
2024-02-10 15:26:28 +00:00
|
|
|
Config.API.Debug = cfg.Section("api").Key("debug").MustBool(false)
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
Config.JWT.Secret = cfg.Section("jwt").Key("secret").String()
|
|
|
|
if Config.JWT.Secret == "" {
|
|
|
|
panic("JWT Secret is empty")
|
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
|
|
|
build, err := cfg.Section("fortnite").Key("build").Float64()
|
|
|
|
if err != nil {
|
|
|
|
panic("Fortnite Build is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Fortnite.Build = build
|
|
|
|
|
|
|
|
buildStr := strconv.FormatFloat(build, 'f', -1, 64)
|
|
|
|
if buildStr == "" {
|
|
|
|
panic("Fortnite Build is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
buildInfo := strings.Split(buildStr, ".")
|
|
|
|
if len(buildInfo) < 2 {
|
|
|
|
panic("Fortnite Build is invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedSeason, err := strconv.Atoi(buildInfo[0])
|
|
|
|
if err != nil {
|
|
|
|
panic("Fortnite Season is invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Fortnite.Season = parsedSeason
|
2023-11-20 23:20:42 +00:00
|
|
|
Config.Fortnite.Everything = cfg.Section("fortnite").Key("everything").MustBool(false)
|
2024-02-10 15:26:28 +00:00
|
|
|
Config.Fortnite.Password = !(cfg.Section("fortnite").Key("disable_password").MustBool(false))
|
2024-01-28 19:40:45 +00:00
|
|
|
Config.Fortnite.DisableClientCredentials = cfg.Section("fortnite").Key("disable_client_credentials").MustBool(false)
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|