diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-08 22:58:47 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-08 23:03:58 +0100 |
commit | 02b86e3aafa9a505863ad217fb7916d389f8a199 (patch) | |
tree | 8b33b2839e4295b83e38253855ec3f012d14a535 /chatcommands.go | |
parent | 59c37c9042c95f3c298065b8ba0fa6d45ef6676b (diff) |
add gserver command
Diffstat (limited to 'chatcommands.go')
-rw-r--r-- | chatcommands.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/chatcommands.go b/chatcommands.go index 6977846..04dd01f 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -341,6 +341,65 @@ func init() { }, }) proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "gserver", + Perm: "cmd_gserver", + Help: "Display the groups your current upstream server is in and all other configured groups. If a valid group name is specified, switch to a random server of that group.", + Usage: "gserver [group]", + Handler: func(cc *proxy.ClientConn, args ...string) string { + if len(args) != 1 { + if len(args) > 1 { + return "Usage: gserver [group]" + } + + conf := proxy.Conf() + + srv, ok := conf.Servers[cc.ServerName()] + if !ok { + return "Not connected to a server." + } + + groups := conf.ServerGroups() + srvGroups := strings.Join(srv.Groups, ", ") + + allGroups := make([]string, 0, len(groups)) + for group := range groups { + allGroups = append(allGroups, group) + } + + return fmt.Sprintf("Connected to: %s | Groups: %s", srvGroups, strings.Join(allGroups, ", ")) + } + + for i := 0; i < 5; i++ { + srv, ok := proxy.Conf().RandomGroupServer(args[0]) + if !ok { + return "Group does not exist." + } + + if srv == args[0] { + return "Group is also a server." + } + + if i == 4 && cc.ServerName() == srv { + return "Already connected to this server after 5 attempts." + } + + if err := cc.Hop(srv); err != nil { + cc.Log("<-", err) + + if errors.Is(err, proxy.ErrNoSuchServer) { + return "Server does not exist." + } else if errors.Is(err, proxy.ErrNewMediaPool) { + return "The new server belongs to a media pool that is not present on this client. Please reconnect to access it." + } + + return "" + } + } + + return "" + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ Name: "kick", Perm: "cmd_kick", Help: "Disconnect a player with an optional reason.", |