From 3c5d2f95e6a0674cad83d3aa05af650f08d46e1d Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sun, 13 Mar 2022 11:19:02 +0100 Subject: Make send command fully telnet compatible This fixes #3. --- chatcommands.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'chatcommands.go') diff --git a/chatcommands.go b/chatcommands.go index 56a9339..ec62923 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -86,13 +86,22 @@ func init() { }, }) proxy.RegisterChatCmd(proxy.ChatCmd{ - Name: "send", - Perm: "cmd_send", - Help: "Send player(s) to a new server. player causes a single player to be redirected, current affects all players that are on your current server and all affects everyone.", - Usage: "send | current | all >", + Name: "send", + Perm: "cmd_send", + Help: "Send player(s) to a new server. player causes a single player to be redirected, current affects all players that are on your current server and all affects everyone.", + Usage: "send | current | all >", + TelnetUsage: "send | all >", Handler: func(cc *proxy.ClientConn, w io.Writer, args ...string) string { + usage := func() string { + if cc != nil { + return "Usage: send | current | all >" + } else { + return "Usage: send | all >" + } + } + if len(args) < 2 { - return "Usage: send | current | all >" + return usage() } var found bool @@ -110,11 +119,7 @@ func init() { switch args[0] { case "player": if len(args) != 3 { - return "Usage: send | current | all >" - } - - if args[1] == cc.ServerName() { - return "Player is already connected to this server." + return usage() } clt := proxy.Find(args[2]) @@ -122,12 +127,20 @@ func init() { return "Player is not connected." } + if args[1] == clt.ServerName() { + return "Player is already connected to this server." + } + if err := clt.Hop(args[1]); err != nil { clt.SendChatMsg("Could not switch servers. Reconnect if you encounter any problems. Error:", err.Error()) } case "current": + if cc == nil { + return usage() + } + if len(args) != 2 { - return "Usage: send | current | all >" + return usage() } if args[1] == cc.ServerName() { @@ -143,7 +156,7 @@ func init() { } case "all": if len(args) != 2 { - return "Usage: send | current | all >" + return usage() } for clt := range proxy.Clts() { @@ -154,7 +167,7 @@ func init() { } } default: - return "Usage: send | current | all >" + return usage() } return "" -- cgit v1.2.3