diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-10 15:29:22 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-10 15:29:22 +0200 |
commit | dc6910fc14ecb2fdfcf36dd84857b6937f5e12bf (patch) | |
tree | 1bb3d675964919283e2620300112c43128e5ae72 | |
parent | 642138ac4bdcb012e2bfba92e320678f42499556 (diff) |
Fix perms command + add group and gperms commands
-rw-r--r-- | chatcommands.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/chatcommands.go b/chatcommands.go index 409603f..af1f5e3 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -200,15 +200,73 @@ func init() { }, }) proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "group", + Perm: "cmd_group", + Help: "Display the group of a player. Display your group if no player name is specified.", + Usage: "group [name]", + Handler: func(cc *proxy.ClientConn, args ...string) string { + if len(args) > 0 { + if len(args) != 1 { + return "Usage: group [name]" + } + + grp, ok := proxy.Conf().UserGroups[args[0]] + if !ok { + grp = "default" + } + + return "Group: " + grp + } + + grp, ok := proxy.Conf().UserGroups[cc.Name()] + if !ok { + grp = "default" + } + + return "Your group: " + grp + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ Name: "perms", Perm: "cmd_perms", Help: "Show the permissions of a player. Show your permissions if no player name is specified.", Usage: "perms [name]", Handler: func(cc *proxy.ClientConn, args ...string) string { + if len(args) > 0 { + if len(args) != 1 { + return "Usage: perms [name]" + } + + clt := proxy.Find(args[0]) + if clt == nil { + return "Player not connected." + } + + return "Player permissions: " + strings.Join(clt.Perms(), ", ") + } + return "Your permissions: " + strings.Join(cc.Perms(), ", ") }, }) proxy.RegisterChatCmd(proxy.ChatCmd{ + Name: "gperms", + Perm: "cmd_gperms", + Help: "Show the permissions of a group.", + Usage: "gperms <group>", + Handler: func(cc *proxy.ClientConn, args ...string) string { + if len(args) != 1 { + return "Usage: gperms <group>" + } + + perms, ok := proxy.Conf().Groups[args[0]] + if !ok { + return "Group not existent." + } + + return "Group permissions: " + strings.Join(perms, ", ") + }, + }) + proxy.RegisterChatCmd(proxy.ChatCmd{ Name: "server", Perm: "cmd_server", Help: "Display your current upstream server and all other configured servers. If a valid server name is specified, switch to that server.", |