Map editing no longer needs mod trust

This commit is contained in:
Wuzzy 2024-11-27 17:32:30 +01:00
parent 5d10163f56
commit 28ac474cc2
2 changed files with 18 additions and 37 deletions

View File

@ -9,13 +9,12 @@ The tutorial castle is saved in the game itself in schematics and other binary m
### Summary ### Summary
1. If Luanti is running, shut it down 1. If Luanti is running, shut it down
2. Trust the code. In the settings menu or `minetest.conf`, add `tutorial_mapgen` to `secure.trusted_mods` 2. In `minetest.conf`, add `tutorial_debug_map_editing = true`
3. In `minetest.conf`, add `tutorial_debug_map_editing = true` 3. In `minetest.conf`, add `tutorial_debug_edit_item_spawners = true`
4. In `minetest.conf`, add `tutorial_debug_edit_item_spawners = true` 4. Start Luanti and create a new world and enter the world in singleplayer (there should be a confirmation message in chat)
5. Start Luanti and create a new world and enter the world in singleplayer (there should be a confirmation message in chat) 5. Edit the map to your likings
6. Edit the map to your likings 6. Grant yourselves the `tutorialmap` privilege
7. Grant yourselves the `tutorialmap` privilege 7. Use `/tsave` command to save the map
8. Use `/tsave` command to save the map
Note: `tutorial_debug_map_editing=true` will automatically enable Creative Mode. Note: `tutorial_debug_map_editing=true` will automatically enable Creative Mode.
@ -23,12 +22,6 @@ The changes will end up in `<world directory>/mapdata`. Copy this directory to `
If you want to edit item spawn positions, see the details below. If you want to edit item spawn positions, see the details below.
### Mod security
First, you need to list `tutorial_mapgen` as a trusted mod because the `/tsave` command needs write access.
You can review the relevant code in `mods/tutorial_mapgen/init.lua`.
Use the setting `secure.trusted_mods` to edit the list of trusted mods.
### Editing the map ### Editing the map
You want to only edit the map data files. Here's how: You want to only edit the map data files. Here's how:
@ -57,5 +50,3 @@ If you mess with item spawners, the setting `tutorial_debug_edit_item_spawners`
### Testing and finalizing ### Testing and finalizing
To test your new map, remove the 2 `minetest.conf` settings and create a new world and check if everything works. If it does work, you can commit your changes now. To test your new map, remove the 2 `minetest.conf` settings and create a new world and check if everything works. If it does work, you can commit your changes now.
(Note: The `/tsave` command is not available if the `tutorial_mapgen` mod failed to request an "insecure" environment due to mod security issues.)

View File

@ -5,7 +5,6 @@
-- the raw castle, no grass layer or other random decorations will be generated. -- the raw castle, no grass layer or other random decorations will be generated.
-- Also, 2 commands to manage the schematic will be available: -- Also, 2 commands to manage the schematic will be available:
-- /treset and /tsave commands will be available. -- /treset and /tsave commands will be available.
-- (/tsave only if tutorial is trusted mod)
local map_editing = minetest.settings:get_bool("tutorial_debug_map_editing") local map_editing = minetest.settings:get_bool("tutorial_debug_map_editing")
-- == END OF DEBUG SETTINGS == -- == END OF DEBUG SETTINGS ==
@ -18,8 +17,6 @@ local c_grass = minetest.get_content_id("tutorial_default:grass_5")
tutorial.map_directory = minetest.get_modpath("tutorial_mapgen").."/mapdata/" tutorial.map_directory = minetest.get_modpath("tutorial_mapgen").."/mapdata/"
tutorial.map_save_directory = minetest.get_worldpath().."/mapdata/" tutorial.map_save_directory = minetest.get_worldpath().."/mapdata/"
local insecure_environment = minetest.request_insecure_environment()
-- entity management functions -- entity management functions
local function init_item_spawners(spawners) local function init_item_spawners(spawners)
@ -146,7 +143,7 @@ local function save_region(minp, maxp, probability_list, filename, slice_prob_li
-- Serialize entries -- Serialize entries
result = minetest.serialize(result) result = minetest.serialize(result)
local file, err = insecure_environment.io.open(filename..".meta", "wb") local file, err = io.open(filename..".meta", "wb")
if err ~= nil then if err ~= nil then
error("Couldn't write to \"" .. filename .. "\"") error("Couldn't write to \"" .. filename .. "\"")
end end
@ -305,24 +302,17 @@ if map_editing then
end, end,
}) })
-- Add commands for saving map and entities, but only if tutorial mod is trusted -- Add commands for saving map and entities
if insecure_environment then minetest.register_chatcommand("tsave", {
minetest.register_chatcommand("tsave", { params = "",
params = "", description = "Saves the tutorial map",
description = "Saves the tutorial map", privs = {tutorialmap=true},
privs = {tutorialmap=true}, func = function(name, param)
func = function(name, param) if not save_schematic() then
if not save_schematic() then minetest.chat_send_player(name, "An error occurred while saving Tutorial World schematic")
minetest.chat_send_player(name, "An error occurred while saving Tutorial World schematic") end
end end,
end, })
})
else
minetest.log("warning", "Could not create insecure environment! /tsave command is disabled.")
minetest.register_on_joinplayer(function(player)
minetest.chat_send_player(player:get_player_name(), "Could not create insecure environment! /tsave command is not available.")
end)
end
end end
------ Map Generation ------ Map Generation