diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-03-13 11:19:02 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-03-13 11:19:02 +0100 |
commit | 3c5d2f95e6a0674cad83d3aa05af650f08d46e1d (patch) | |
tree | 7dc8a884de0b4d506904988e307f8c4df52dbd3d /chatcommands.go | |
parent | 618dd08d1631f1f9976cf14790350672903756e0 (diff) |
Make send command fully telnet compatible
This fixes #3.
Diffstat (limited to 'chatcommands.go')
-rw-r--r-- | chatcommands.go | 39 |
1 files changed, 26 insertions, 13 deletions
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 <player <server> <name> | current <server> | all <server>>", + 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 <player <server> <name> | current <server> | all <server>>", + TelnetUsage: "send <player <server> <name> | all <server>>", Handler: func(cc *proxy.ClientConn, w io.Writer, args ...string) string { + usage := func() string { + if cc != nil { + return "Usage: send <player <server> <name> | current <server> | all <server>>" + } else { + return "Usage: send <player <server> <name> | all <server>>" + } + } + if len(args) < 2 { - return "Usage: send <player <server> <name> | current <server> | all <server>>" + return usage() } var found bool @@ -110,11 +119,7 @@ func init() { switch args[0] { case "player": if len(args) != 3 { - return "Usage: send <player <server> <name> | current <server> | all <server>>" - } - - 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 <player <server> <name> | current <server> | all <server>>" + return usage() } if args[1] == cc.ServerName() { @@ -143,7 +156,7 @@ func init() { } case "all": if len(args) != 2 { - return "Usage: send <player <server> <name> | current <server> | all <server>>" + return usage() } for clt := range proxy.Clts() { @@ -154,7 +167,7 @@ func init() { } } default: - return "Usage: send <player <server> <name> | current <server> | all <server>>" + return usage() } return "" |