]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/game/chatcommands.lua
Prevent null concatenation when /deleteblocks is provided an incorrect format
[dragonfireclient.git] / builtin / game / chatcommands.lua
index 9293e98f49164e409d62a1ede1a8fc6808f767d9..2d94817e8f016fbef245c45a3edcdaec72e26756 100644 (file)
@@ -252,7 +252,7 @@ core.register_chatcommand("clearpassword", {
        description = "set empty password",
        privs = {password=true},
        func = function(name, param)
-               toname = param
+               local toname = param
                if toname == "" then
                        return false, "Name field required"
                end
@@ -326,46 +326,48 @@ core.register_chatcommand("teleport", {
                        return true, "Teleporting to " .. target_name
                                        .. " at "..core.pos_to_string(p)
                end
+
+               if not core.check_player_privs(name, {bring=true}) then
+                       return false, "You don't have permission to teleport other players (missing bring privilege)"
+               end
+
+               local teleportee = nil
+               local p = {}
+               local teleportee_name = nil
+               teleportee_name, p.x, p.y, p.z = param:match(
+                               "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
+               p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
+               if teleportee_name then
+                       teleportee = core.get_player_by_name(teleportee_name)
+               end
+               if teleportee and p.x and p.y and p.z then
+                       teleportee:setpos(p)
+                       return true, "Teleporting " .. teleportee_name
+                                       .. " to " .. core.pos_to_string(p)
+               end
                
-               if core.check_player_privs(name, {bring=true}) then
-                       local teleportee = nil
-                       local p = {}
-                       local teleportee_name = nil
-                       teleportee_name, p.x, p.y, p.z = param:match(
-                                       "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
-                       p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
-                       if teleportee_name then
-                               teleportee = core.get_player_by_name(teleportee_name)
-                       end
-                       if teleportee and p.x and p.y and p.z then
-                               teleportee:setpos(p)
-                               return true, "Teleporting " .. teleportee_name
-                                               .. " to " .. core.pos_to_string(p)
-                       end
-                       
-                       local teleportee = nil
-                       local p = nil
-                       local teleportee_name = nil
-                       local target_name = nil
-                       teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
-                       if teleportee_name then
-                               teleportee = core.get_player_by_name(teleportee_name)
-                       end
-                       if target_name then
-                               local target = core.get_player_by_name(target_name)
-                               if target then
-                                       p = target:getpos()
-                               end
-                       end
-                       if teleportee and p then
-                               p = find_free_position_near(p)
-                               teleportee:setpos(p)
-                               return true, "Teleporting " .. teleportee_name
-                                               .. " to " .. target_name
-                                               .. " at " .. core.pos_to_string(p)
+               local teleportee = nil
+               local p = nil
+               local teleportee_name = nil
+               local target_name = nil
+               teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
+               if teleportee_name then
+                       teleportee = core.get_player_by_name(teleportee_name)
+               end
+               if target_name then
+                       local target = core.get_player_by_name(target_name)
+                       if target then
+                               p = target:getpos()
                        end
                end
-
+               if teleportee and p then
+                       p = find_free_position_near(p)
+                       teleportee:setpos(p)
+                       return true, "Teleporting " .. teleportee_name
+                                       .. " to " .. target_name
+                                       .. " at " .. core.pos_to_string(p)
+               end
+               
                return false, 'Invalid parameters ("' .. param
                                .. '") or player not found (see /help teleport)'
        end,
@@ -401,6 +403,44 @@ core.register_chatcommand("set", {
        end,
 })
 
+core.register_chatcommand("deleteblocks", {
+       params = "[here] [<pos1> <pos2>]",
+       description = "delete map blocks contained in area pos1 to pos2",
+       privs = {server=true},
+       func = function(name, param)
+               local p1 = {}
+               local p2 = {}
+               if param == "here" then
+                       local player = core.get_player_by_name(name)
+                       if player == nil then
+                               core.log("error", "player is nil")
+                               return false, "Unable to get current position; player is nil"
+                       end
+                       p1 = player:getpos()
+                       p2 = p1
+               else
+                       local pos1, pos2 = unpack(param:split(") ("))
+                       if pos1 == nil or pos2 == nil then
+                               return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
+                       end
+
+                       p1 = core.string_to_pos(pos1 .. ")")
+                       p2 = core.string_to_pos("(" .. pos2)
+
+                       if p1 == nil or p2 == nil then
+                               return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
+                       end
+               end
+
+               if core.delete_area(p1, p2) then
+                       return true, "Successfully cleared area ranging from " ..
+                               core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
+               else
+                       return false, "Failed to clear one or more blocks in area"
+               end
+       end,
+})
+
 core.register_chatcommand("mods", {
        params = "",
        description = "List mods installed on the server",
@@ -424,6 +464,7 @@ local function handle_give_command(cmd, giver, receiver, stackstring)
                return false, receiver .. " is not a known player"
        end
        local leftover = receiverref:get_inventory():add_item("main", itemstack)
+       local partiality
        if leftover:is_empty() then
                partiality = ""
        elseif leftover:get_count() == itemstack:get_count() then
@@ -721,3 +762,20 @@ core.register_chatcommand("msg", {
        end,
 })
 
+core.register_chatcommand("last-login", {
+       params = "[name]",
+       description = "Get the last login time of a player",
+       func = function(name, param)
+               if param == "" then
+                       param = name
+               end
+               local pauth = core.get_auth_handler().get_auth(param)
+               if pauth and pauth.last_login then
+                       -- Time in UTC, ISO 8601 format
+                       return true, "Last login time was " ..
+                               os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
+               end
+               return false, "Last login time is unknown"
+       end,
+})
+