Skip to content

Commit

Permalink
fix default server randomness, introducing group support (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
HimbeerserverDE committed Dec 8, 2023
1 parent 0c19615 commit 3e1317b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Config struct {
NoTelnet bool
TelnetAddr string
BindAddr string
DefaultSrv string
Servers map[string]Server
ForceDefaultSrv bool
KickOnNewPool bool
Expand Down Expand Up @@ -200,12 +201,17 @@ func copyMapSlice[K comparable, V any](in map[K][]V) map[K][]V {
// and information about it. The return values are uninitialized
// if no servers exist.
func (cnf Config) DefaultServerInfo() (string, Server) {
for name, srv := range Conf().Servers {
return name, srv
name, ok := cnf.RandomGroupServer(cnf.DefaultSrv)
if !ok {
return "", Server{}
}

srv, ok := cnf.Servers[name]
if !ok {
return "", Server{}
}

// No servers are configured.
return "", Server{}
return name, srv
}

// DefaultServerName returns the name of the default server.
Expand Down
7 changes: 7 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ Default: ":40000"
Description: The proxy will listen for new clients on this address.
```

> `DefaultSrv`
```
Type: string
Default: ""
Description: The default server to connect new clients to. May be a group.
```

> `Servers`
```
Type: map[string]Server
Expand Down
5 changes: 5 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func runFunc() {
cc.Kick("No servers are configured.")
return
}
if _, ok := conf.Servers[""]; !ok && conf.DefaultServerName() == "" {
cc.Log("<-", "no default server")
cc.Kick("No valid default server is configured.")
return
}

srvName, srv := conf.DefaultServerInfo()
lastSrv, err := authIface.LastSrv(cc.Name())
Expand Down

0 comments on commit 3e1317b

Please sign in to comment.