aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go41
-rw-r--r--doc/config.md14
-rw-r--r--process.go4
3 files changed, 55 insertions, 4 deletions
diff --git a/config.go b/config.go
index 39f9cf2..246fd66 100644
--- a/config.go
+++ b/config.go
@@ -15,6 +15,7 @@ const (
defaultTelnetAddr = "[::1]:40010"
defaultBindAddr = ":40000"
defaultListInterval = 300
+ //defaultFallbackServers = [...]string{}
)
var config Config
@@ -33,10 +34,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 +78,39 @@ func Conf() Config {
return config
}
+// FallbackServer returns a array of server names that
+// a server can fall back to.
+func FallbackServers(server string) []string {
+ configMu.RLock()
+ defer configMu.RUnlock()
+
+ fallbacks := make([]string, 0)
+
+ // find server
+ found := false
+ for _, srv := range Conf().Servers {
+ if srv.Name == server {
+ found = true
+ fallbacks = append(fallbacks, srv.Fallbacks...)
+ break
+ }
+ }
+
+ // server dosn't exist
+ if !found {
+ return make([]string, 0)
+ }
+
+ // global fallbacks
+ if len(config.FallbackServers) == 0 {
+ return append(fallbacks, config.Servers[0].Name)
+ } else {
+ return append(fallbacks, config.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 +126,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
diff --git a/doc/config.md b/doc/config.md
index 36a5b4a..8989ec2 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -117,6 +117,13 @@ Default: ""
Description: The network address and port of an internal server.
```
+> `Server.Fallback`
+```
+Type: []string
+Default: []
+Description: Servers that clients get sent to when server stops or crashes (in order).
+```
+
> `ForceDefaultSrv`
```
Type: bool
@@ -181,6 +188,13 @@ Default: 0
Description: The maximum distance from which CSMs can read the map.
```
+> `FallbackServers`
+```
+Type: []string
+Default: []
+Description: General Fallback servers if server stopps and clients are connected.
+```
+
> `DropCSMRF`
```
Type: bool
diff --git a/process.go b/process.go
index ff7d49c..cc4a219 100644
--- a/process.go
+++ b/process.go
@@ -540,10 +540,10 @@ func (sc *ServerConn) process(pkt mt.Pkt) {
// if Shutdown
if cmd.Reason == 11 {
clt.SendChatMsg("[ERROR] ", cmd.String())
- clt.Hop(Conf().Servers[0].Name)
+ clt.Hop(FallbackServers(sc.name)[0])
return
}
-
+
sc.Log("<-", "deny access", cmd)
ack, _ := clt.SendCmd(cmd)