diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-10 15:52:48 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-10 15:52:48 +0200 |
commit | 38ee42cad0bf72664942ff1dd4432f3f4289c6b7 (patch) | |
tree | b946afdba22b9ab7a78c663300dfb030089964d5 /chatcommands.go | |
parent | dc6910fc14ecb2fdfcf36dd84857b6937f5e12bf (diff) |
Fix server command: check if server exists
Diffstat (limited to 'chatcommands.go')
-rw-r--r-- | chatcommands.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/chatcommands.go b/chatcommands.go index af1f5e3..e238f3a 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -272,7 +272,11 @@ func init() { Help: "Display your current upstream server and all other configured servers. If a valid server name is specified, switch to that server.", Usage: "server [server]", Handler: func(cc *proxy.ClientConn, args ...string) string { - if len(args) == 0 { + if len(args) != 1 { + if len(args) > 1 { + return "Usage: server [server]" + } + srvs := make([]string, len(proxy.Conf().Servers)) for i, srv := range proxy.Conf().Servers { srvs[i] = srv.Name @@ -281,12 +285,23 @@ func init() { return fmt.Sprintf("Connected to: %s | Servers: %s", cc.ServerName(), strings.Join(srvs, ", ")) } - srv := strings.Join(args, " ") - if cc.ServerName() == srv { + var found bool + for _, srv := range proxy.Conf().Servers { + if srv.Name == args[0] { + found = true + break + } + } + + if !found { + return "Server not existent." + } + + if cc.ServerName() == args[0] { return "Already connected to this server." } - if err := cc.Hop(srv); err != nil { + if err := cc.Hop(args[0]); err != nil { return "Could not switch servers. Reconnect if you encounter any problems. Error: " + err.Error() } |