aboutsummaryrefslogtreecommitdiff
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
parentf1e68fd27e5441d04be7110d618ea07f02bffe00 (diff)
parentd294489eb5588b4b8f77a4795a476ba98fdcecf8 (diff)
Merge pull request #82 from ev2-1/main
Issue #4
-rw-r--r--cmd/mt-multiserver-proxy/.gitignore4
-rwxr-xr-xcmd/mt-multiserver-proxy/build.sh4
-rw-r--r--config.go39
-rw-r--r--doc/config.md14
-rw-r--r--process.go13
5 files changed, 72 insertions, 2 deletions
diff --git a/cmd/mt-multiserver-proxy/.gitignore b/cmd/mt-multiserver-proxy/.gitignore
new file mode 100644
index 0000000..ef1a813
--- /dev/null
+++ b/cmd/mt-multiserver-proxy/.gitignore
@@ -0,0 +1,4 @@
+config.json
+cache/
+*.log
+auth/
diff --git a/cmd/mt-multiserver-proxy/build.sh b/cmd/mt-multiserver-proxy/build.sh
new file mode 100755
index 0000000..dd49510
--- /dev/null
+++ b/cmd/mt-multiserver-proxy/build.sh
@@ -0,0 +1,4 @@
+cd ../..
+go build
+cd cmd/mt-multiserver-proxy
+go build
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
diff --git a/doc/config.md b/doc/config.md
index 36a5b4a..a7d9ba3 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: []string{}
+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: []string{}
+Description: General Fallback servers if server stopps and clients are connected.
+```
+
> `DropCSMRF`
```
Type: bool
diff --git a/process.go b/process.go
index f60b35d..84a1622 100644
--- a/process.go
+++ b/process.go
@@ -538,6 +538,19 @@ func (sc *ServerConn) process(pkt mt.Pkt) {
return
case *mt.ToCltKick:
sc.Log("<-", "deny access", cmd)
+
+ if cmd.Reason == mt.Shutdown || cmd.Reason == mt.Crash || cmd.Reason == mt.SrvErr || cmd.Reason == cmd.TooManyClts || cmd.Reason == cmd.UnsupportedVer {
+ clt.SendChatMsg(cmd.String())
+ for _, srvName := range FallbackServers(sc.name) {
+ if err := clt.Hop(); err != nil {
+ clt.Log("<-", err)
+ break
+ }
+ }
+
+ return
+ }
+
ack, _ := clt.SendCmd(cmd)
select {