Merge pull request #82 from ev2-1/main

Issue #4
master
HimbeerserverDE 2022-04-21 13:03:34 +02:00 committed by GitHub
commit 0901f91b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 2 deletions

4
cmd/mt-multiserver-proxy/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
config.json
cache/
*.log
auth/

View File

@ -0,0 +1,4 @@
cd ../..
go build
cd cmd/mt-multiserver-proxy
go build

View File

@ -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

View File

@ -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

View File

@ -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 {