aboutsummaryrefslogtreecommitdiff
path: root/chatcommands.go
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2021-09-09 18:08:06 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2021-09-09 18:08:06 +0200
commitb3b355c4abd11b46ea0e31e636af9eef179599ec (patch)
treede14404f6c5f14b561be97a700d64f6caabc137e /chatcommands.go
parent5b22bb8d11618d5cdf72c574d086eda2be53717c (diff)
Add basic chat commands
Diffstat (limited to 'chatcommands.go')
-rw-r--r--chatcommands.go62
1 files changed, 58 insertions, 4 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 ""
+ },
+ })
}