diff options
-rw-r--r-- | chatcommands.go | 62 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 6 |
3 files changed, 65 insertions, 5 deletions
diff --git a/chatcommands.go b/chatcommands.go index 6bead9f..3f4c233 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -1,14 +1,68 @@ package main import ( + "fmt" + "os" "strings" "github.com/HimbeerserverDE/mt-multiserver-proxy" ) func init() { - testCmd := func(cc *proxy.ClientConn, args ...string) string { - return strings.Join(args, " ") - } - proxy.RegisterChatCmd("test", testCmd) + proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "shutdown", + Perm: "cmd_shutdown", + Handler: func(cc *proxy.ClientConn, args ...string) string { + proc, err := os.FindProcess(os.Getpid()) + if err != nil { + return "Could not find process: " + err.Error() + } + + proc.Signal(os.Interrupt) + return "" + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "reload", + Perm: "cmd_reload", + Handler: func(cc *proxy.ClientConn, args ...string) string { + if err := proxy.LoadConfig(); err != nil { + return "Configuration could not be reloaded. Old config is still active. Error: " + err.Error() + } + + return "Configuration reloaded. You should restart if you encounter any problems." + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "perms", + Perm: "cmd_perms", + Handler: func(cc *proxy.ClientConn, args ...string) string { + return "Your permissions: " + strings.Join(cc.Perms(), " ") + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "server", + Perm: "cmd_server", + Handler: func(cc *proxy.ClientConn, args ...string) string { + if len(args) == 0 { + srvs := make([]string, len(proxy.Conf().Servers)) + for i, srv := range proxy.Conf().Servers { + srvs[i] = srv.Name + } + + return fmt.Sprintf("Connected to: %s | Servers: %s", cc.ServerName(), strings.Join(srvs, " ")) + } + + srv := strings.Join(args, " ") + if cc.ServerName() == srv { + return "Already connected to this server." + } + + if err := cc.Hop(srv); err != nil { + return "Could not switch servers. Reconnect if you encounter any problems. Error: " + err.Error() + } + + return "" + }, + }) } @@ -2,7 +2,7 @@ module github.com/HimbeerserverDE/mt-multiserver-chatcommands go 1.17 -require github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210907171759-2e3d72cccc0e +require github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909160525-4f15ec2a77e4 require ( github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b // indirect @@ -8,6 +8,12 @@ github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210906212651-d55fa7e1df github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210906212651-d55fa7e1dfa9/go.mod h1:8xnFy8wsJTDIUkMExnTq5fdiUNbnL6udwytjRM6woDw= github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210907171759-2e3d72cccc0e h1:kvwl8vAK93Ao1nlOZoheqZwlpjBp+wDOV+JNopF4LbM= github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210907171759-2e3d72cccc0e/go.mod h1:8xnFy8wsJTDIUkMExnTq5fdiUNbnL6udwytjRM6woDw= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909144031-4c5063b9f9c5 h1:nvADaR80KGq8T/M9CUaaPEv9irQBSzH3VMVXCmQoVlU= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909144031-4c5063b9f9c5/go.mod h1:8xnFy8wsJTDIUkMExnTq5fdiUNbnL6udwytjRM6woDw= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909152737-bcc9359996bf h1:93yW1WChwSdLy1bkCHesVQOFC9rZ4cu3/ncLQLdLkwc= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909152737-bcc9359996bf/go.mod h1:8xnFy8wsJTDIUkMExnTq5fdiUNbnL6udwytjRM6woDw= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909160525-4f15ec2a77e4 h1:aI7wyYQTG+9z8k8dAj2ih0ZKTXmBnGEkV5ji/ZP0MN4= +github.com/HimbeerserverDE/mt-multiserver-proxy v0.0.0-20210909160525-4f15ec2a77e4/go.mod h1:8xnFy8wsJTDIUkMExnTq5fdiUNbnL6udwytjRM6woDw= github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b h1:xqNC1S76U5U+eFyzr5Ld+8aPOLaDFCw6f1uddjui+h8= github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b/go.mod h1:pxNH8S2nh4n2DWE0ToX5GnnDr/uEAuaAhJsCpkDLIWw= github.com/anon55555/mt v0.0.0-20210623155243-152b6697e62c h1:+T4M4zm8QMMnH56jopsKcCBxItSsb6jtulB3ZKFYETU= |