From f8be69143c29606e189337be00594db59d9699ba Mon Sep 17 00:00:00 2001 From: Minetest-j45 <55553015+Minetest-j45@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:00:17 +0100 Subject: Fix gperms inconsistency (#2) --- chatcommands.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'chatcommands.go') diff --git a/chatcommands.go b/chatcommands.go index ec62923..0519b89 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -278,20 +278,34 @@ func init() { }, }) proxy.RegisterChatCmd(proxy.ChatCmd{ - Name: "gperms", - Perm: "cmd_gperms", - Help: "Show the permissions of a group.", - Usage: "gperms ", + Name: "gperms", + Perm: "cmd_gperms", + Help: "Show the permissions of a group.", + Usage: "gperms [group]", + TelnetUsage: "gperms ", Handler: func(cc *proxy.ClientConn, w io.Writer, args ...string) string { - if len(args) != 1 { - return "Usage: gperms " + if len(args) > 0 { + if len(args) != 1 { + return "Usage: gperms [group]" + } + + perms, ok := proxy.Conf().Groups[args[0]] + if !ok { + return "Group does not exist." + } + return "Group permissions: " + strings.Join(perms, ", ") + } + + if cc == nil { + return "Telnet usage: gperms " } - perms, ok := proxy.Conf().Groups[args[0]] + grp, ok := proxy.Conf().UserGroups[cc.Name()] if !ok { - return "Group does not exist." + grp = "default" } + perms, _ := proxy.Conf().Groups[grp] return "Group permissions: " + strings.Join(perms, ", ") }, }) -- cgit v1.2.3