aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/misc.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
commit21df26984da91143c15587f5a03c98d68c3adc4e (patch)
treeaaa707a628ad331f67890023dffe1b4f60dd01d3 /builtin/game/misc.lua
parentb09fc5de5cdb021f43ad32b7e3f50dc75c0bc622 (diff)
parenteabf05758e3ba5f6f4bb1b8d1d1f02179b84e410 (diff)
downloaddragonfireclient-21df26984da91143c15587f5a03c98d68c3adc4e.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'builtin/game/misc.lua')
-rw-r--r--builtin/game/misc.lua116
1 files changed, 35 insertions, 81 deletions
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 63d64817c..997b1894a 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -6,6 +6,16 @@ local S = core.get_translator("__builtin")
-- Misc. API functions
--
+-- @spec core.kick_player(String, String) :: Boolean
+function core.kick_player(player_name, reason)
+ if type(reason) == "string" then
+ reason = "Kicked: " .. reason
+ else
+ reason = "Kicked."
+ end
+ return core.disconnect_player(player_name, reason)
+end
+
function core.check_player_privs(name, ...)
if core.is_player(name) then
name = name:get_player_name()
@@ -111,53 +121,6 @@ function core.get_player_radius_area(player_name, radius)
end
-function core.hash_node_position(pos)
- return (pos.z + 32768) * 65536 * 65536
- + (pos.y + 32768) * 65536
- + pos.x + 32768
-end
-
-
-function core.get_position_from_hash(hash)
- local x = (hash % 65536) - 32768
- hash = math.floor(hash / 65536)
- local y = (hash % 65536) - 32768
- hash = math.floor(hash / 65536)
- local z = (hash % 65536) - 32768
- return vector.new(x, y, z)
-end
-
-
-function core.get_item_group(name, group)
- if not core.registered_items[name] or not
- core.registered_items[name].groups[group] then
- return 0
- end
- return core.registered_items[name].groups[group]
-end
-
-
-function core.get_node_group(name, group)
- core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
- return core.get_item_group(name, group)
-end
-
-
-function core.setting_get_pos(name)
- local value = core.settings:get(name)
- if not value then
- return nil
- end
- return core.string_to_pos(value)
-end
-
-
--- See l_env.cpp for the other functions
-function core.get_artificial_light(param1)
- return math.floor(param1 / 16)
-end
-
-
-- To be overriden by protection mods
function core.is_protected(pos, name)
@@ -240,7 +203,7 @@ end
-- HTTP callback interface
-function core.http_add_fetch(httpenv)
+core.set_http_api_lua(function(httpenv)
httpenv.fetch = function(req, callback)
local handle = httpenv.fetch_async(req)
@@ -256,7 +219,8 @@ function core.http_add_fetch(httpenv)
end
return httpenv
-end
+end)
+core.set_http_api_lua = nil
function core.close_formspec(player_name, formname)
@@ -273,40 +237,30 @@ end
core.dynamic_media_callbacks = {}
--- PNG encoder safety wrapper
-
-local o_encode_png = core.encode_png
-function core.encode_png(width, height, data, compression)
- if type(width) ~= "number" then
- error("Incorrect type for 'width', expected number, got " .. type(width))
- end
- if type(height) ~= "number" then
- error("Incorrect type for 'height', expected number, got " .. type(height))
- end
-
- local expected_byte_count = width * height * 4
+-- Transfer of certain globals into async environment
+-- see builtin/async/game.lua for the other side
- if type(data) ~= "table" and type(data) ~= "string" then
- error("Incorrect type for 'height', expected table or string, got " .. type(height))
+local function copy_filtering(t, seen)
+ if type(t) == "userdata" or type(t) == "function" then
+ return true -- don't use nil so presence can still be detected
+ elseif type(t) ~= "table" then
+ return t
end
-
- local data_length = type(data) == "table" and #data * 4 or string.len(data)
-
- if data_length ~= expected_byte_count then
- error(string.format(
- "Incorrect length of 'data', width and height imply %d bytes but %d were provided",
- expected_byte_count,
- data_length
- ))
- end
-
- if type(data) == "table" then
- local dataBuf = {}
- for i = 1, #data do
- dataBuf[i] = core.colorspec_to_bytes(data[i])
- end
- data = table.concat(dataBuf)
+ local n = {}
+ seen = seen or {}
+ seen[t] = n
+ for k, v in pairs(t) do
+ local k_ = seen[k] or copy_filtering(k, seen)
+ local v_ = seen[v] or copy_filtering(v, seen)
+ n[k_] = v_
end
+ return n
+end
- return o_encode_png(width, height, data, compression or 6)
+function core.get_globals_to_transfer()
+ local all = {
+ registered_items = copy_filtering(core.registered_items),
+ registered_aliases = core.registered_aliases,
+ }
+ return all
end