aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorHimbeerserverDE <52707839+HimbeerserverDE@users.noreply.github.com>2022-04-21 13:03:34 +0200
committerGitHub <noreply@github.com>2022-04-21 13:03:34 +0200
commit0901f91b42fb275d4b9f5b941e36240b83b4ea6f (patch)
treea31f108ff9617f83e39c0b7f0de4d56a1b79600f /config.go
parentf1e68fd27e5441d04be7110d618ea07f02bffe00 (diff)
parentd294489eb5588b4b8f77a4795a476ba98fdcecf8 (diff)
Merge pull request #82 from ev2-1/main
Issue #4
Diffstat (limited to 'config.go')
-rw-r--r--config.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/config.go b/config.go
index 39f9cf2..f19e35b 100644
--- a/config.go
+++ b/config.go
@@ -33,10 +33,12 @@ type Config struct {
TelnetAddr string
BindAddr string
Servers []struct {
- Name string
- Addr string
+ Name string
+ Addr string
+ Fallbacks []string
}
ForceDefaultSrv bool
+ FallbackServers []string
CSMRF struct {
NoCSMs bool
ChatMsgs bool
@@ -75,6 +77,38 @@ func Conf() Config {
return config
}
+// FallbackServers returns a slice of server names that
+// a server can fall back to.
+func FallbackServers(server string) []string {
+ configMu.RLock()
+ defer configMu.RUnlock()
+
+ fallbacks := make([]string, 0)
+
+ conf := Conf()
+
+ // find server
+ for _, srv := range conf.Servers {
+ if srv.Name == server {
+ fallbacks = append(fallbacks, srv.Fallbacks...)
+ break
+ }
+ }
+
+ // global fallbacks
+ if len(conf.FallbackServers) == 0 {
+ if len(conf.Servers) == 0 {
+ return fallbacks
+ }
+
+ return append(fallbacks, conf.Servers[0].Name)
+ } else {
+ return append(fallbacks, conf.FallbackServers...)
+ }
+
+ return fallbacks
+}
+
// LoadConfig attempts to parse the configuration file.
// It leaves the config unchanged if there is an error
// and returns the error.
@@ -90,6 +124,7 @@ func LoadConfig() error {
config.AuthBackend = defaultAuthBackend
config.TelnetAddr = defaultTelnetAddr
config.BindAddr = defaultBindAddr
+ config.FallbackServers = make([]string, 0)
config.Groups = make(map[string][]string)
config.UserGroups = make(map[string]string)
config.List.Interval = defaultListInterval