]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/chatcommands.lua
Fix /setpassword and /clearpassword
[dragonfireclient.git] / builtin / chatcommands.lua
index a7061e3a3f0d47dc8222115206d68cc0b54887b2..9f033aa17e74e73c9a295c77b8a0913aa3535fb0 100644 (file)
@@ -14,7 +14,7 @@ function minetest.register_chatcommand(cmd, def)
 end
 
 minetest.register_on_chat_message(function(name, message)
-       local cmd, param = string.match(message, "/([^ ]+) *(.*)")
+       local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
        if not param then
                param = ""
        end
@@ -101,9 +101,10 @@ minetest.register_chatcommand("privs", {
                if param == "" then
                        param = name
                else
-                       if not minetest.check_player_privs(name, {privs=true}) then
+                       --[[if not minetest.check_player_privs(name, {privs=true}) then
                                minetest.chat_send_player(name, "Privileges of "..param.." are hidden from you.")
-                       end
+                               return
+                       end]]
                end
                minetest.chat_send_player(name, "Privileges of "..param..": "..minetest.privs_to_string(minetest.get_player_privs(param), ' '))
        end,
@@ -130,7 +131,7 @@ minetest.register_chatcommand("grant", {
                local privs = minetest.get_player_privs(grantname)
                local privs_known = true
                for priv, _ in pairs(grantprivs) do
-                       if priv ~= "interact" and priv ~= "shout" and not minetest.check_player_privs(name, {privs=true}) then
+                       if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not minetest.check_player_privs(name, {privs=true}) then
                                minetest.chat_send_player(name, "Your privileges are insufficient.")
                                return
                        end
@@ -168,7 +169,7 @@ minetest.register_chatcommand("revoke", {
                local revokeprivs = minetest.string_to_privs(revokeprivstr)
                local privs = minetest.get_player_privs(revokename)
                for priv, _ in pairs(revokeprivs) do
-                       if priv ~= "interact" and priv ~= "shout" and not minetest.check_player_privs(name, {privs=true}) then
+                       if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not minetest.check_player_privs(name, {privs=true}) then
                                minetest.chat_send_player(name, "Your privileges are insufficient.")
                                return
                        end
@@ -192,12 +193,27 @@ minetest.register_chatcommand("setpassword", {
        description = "set given password",
        privs = {password=true},
        func = function(name, param)
-               if param == "" then
-                       minetest.chat_send_player(name, "Password field required")
+               local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
+               if not toname then
+                       toname = string.match(param, "^([^ ]+) *$")
+                       raw_password = nil
+               end
+               if not toname then
+                       minetest.chat_send_player(name, "Name field required")
                        return
                end
-               minetest.set_player_password(name, param)
-               minetest.chat_send_player(name, "Password set")
+               local actstr = "?"
+               if not raw_password then
+                       minetest.set_player_password(toname, "")
+                       actstr = "cleared"
+               else
+                       minetest.set_player_password(toname, minetest.get_password_hash(toname, raw_password))
+                       actstr = "set"
+               end
+               minetest.chat_send_player(name, "Password of player \""..toname.."\" "..actstr)
+               if toname ~= name then
+                       minetest.chat_send_player(toname, "Your password was "..actstr.." by "..name)
+               end
        end,
 })
 minetest.register_chatcommand("clearpassword", {
@@ -205,8 +221,13 @@ minetest.register_chatcommand("clearpassword", {
        description = "set empty password",
        privs = {password=true},
        func = function(name, param)
-               minetest.set_player_password(name, '')
-               minetest.chat_send_player(name, "Password cleared")
+               toname = param
+               if not toname then
+                       minetest.chat_send_player(toname, "Name field required")
+                       return
+               end
+               minetest.set_player_password(toname, '')
+               minetest.chat_send_player(name, "Password of player \""..toname.."\" cleared")
        end,
 })