HimbeerserverDE / mt-multiserver-chatcommands

mt-multiserver-chatcommands provides a useful chat command interface for mt-multiserver-proxy.
MIT License
5 stars 2 forks source link

`gperms` inconsistentcy #2

Closed Minetest-j45 closed 2 years ago

Minetest-j45 commented 2 years ago

With the gperms command, you can only do gperms <group>, and the group is not optional. This is inconsistent with perms, which defaults to you if you don't specify a name.

Here is an untested diff file that might fix it but I'm not sure if it will work. diff.txt To test this, use git apply diff.txt to apply the diff file to your local branch

HimbeerserverDE commented 2 years ago

This won't work if you have no group (it will crash the proxy). Since proxy.Conf().UserGroups is a map that's directly being decoded into there is no default value, you need to handle it yourself. See the group command:

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]",
    TelnetUsage: "group <name>",
    Handler: func(cc *proxy.ClientConn, w io.Writer, 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
        }

        if cc == nil {
            return "Telnet usage: group <name>"
        }

        grp, ok := proxy.Conf().UserGroups[cc.Name()]
        if !ok {
            grp = "default"
        }

        return "Your group: " + grp
    },
})