mirror of
https://github.com/mt-mods/home_workshop_modpack.git
synced 2025-07-01 07:50:39 +02:00
add lua sandbox, tabs, stuff
This commit is contained in:
7
computers/commands/exit/conf.json
Normal file
7
computers/commands/exit/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "exit",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.42,
|
||||
"help": "exits the computer"
|
||||
}
|
7
computers/commands/exit/init.lua
Normal file
7
computers/commands/exit/init.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function exit(pos, input, data)
|
||||
minetest.close_formspec(data.player:get_player_name(), "")
|
||||
|
||||
return "you shouldnt see this"
|
||||
end
|
||||
|
||||
return exit
|
7
computers/commands/expr/conf.json
Normal file
7
computers/commands/expr/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "expr",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.42,
|
||||
"help": "exicutes mathmatical expresions"
|
||||
}
|
14
computers/commands/expr/init.lua
Normal file
14
computers/commands/expr/init.lua
Normal file
@ -0,0 +1,14 @@
|
||||
function expr(pos, input, data)
|
||||
local output
|
||||
local func = computers.sandbox.loadstring("return " .. input, {env={}})
|
||||
|
||||
if func then output = func() end
|
||||
|
||||
if type(output) ~= "number" or output == nil then
|
||||
return "Error: invalid or missing input"
|
||||
end
|
||||
|
||||
return tostring(output)
|
||||
end
|
||||
|
||||
return expr
|
7
computers/commands/nano/conf.json
Normal file
7
computers/commands/nano/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "nano",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.42,
|
||||
"help": "allows editing of files"
|
||||
}
|
113
computers/commands/nano/init.lua
Normal file
113
computers/commands/nano/init.lua
Normal file
@ -0,0 +1,113 @@
|
||||
function nano(pos, input, data)
|
||||
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||
local files = computers.api.get_dir_keyed_list(path, false)
|
||||
|
||||
if not input then return "no file designated" end
|
||||
if not files[input:split(" ")[1]] then return "file " .. input:split(" ")[1] .. " not found" end
|
||||
if computers.formspec.get_index_by_name(
|
||||
computers.formspec.registered_kast[data.player:get_player_name()],
|
||||
"nano_btn"
|
||||
) then return "nano is already open, please close it" end
|
||||
|
||||
local f = io.open(path .. "/" .. input:split(" ")[1])
|
||||
if not f then return "error reading file" end
|
||||
local file = f:read("*all")
|
||||
f:close()
|
||||
|
||||
--clean up if there exists a legacy nano_ctn
|
||||
local nctn = computers.formspec.get_index_by_name(
|
||||
computers.formspec.registered_kast[data.player:get_player_name()],
|
||||
"nano_ctn"
|
||||
)
|
||||
if nctn then
|
||||
local fs = computers.formspec.registered_kast[data.player:get_player_name()]
|
||||
table.remove(fs, nctn)
|
||||
computers.formspec.registered_kast[data.player:get_player_name()] = fs
|
||||
minetest.chat_send_all(dump(fs))
|
||||
end
|
||||
|
||||
local form = computers.gui.add_tab(data.player, "Nano", {
|
||||
type = "container",
|
||||
name = "nano_ctn",
|
||||
state = 1,
|
||||
x = 0,
|
||||
y = 1,
|
||||
{
|
||||
type = "background",
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 10,
|
||||
h = 11,
|
||||
texture_name = "[combine:16x16^[noalpha"
|
||||
},
|
||||
{
|
||||
type = "textarea",
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 10,
|
||||
h = 10,
|
||||
name = "nano_editor",
|
||||
--read_only = 1,
|
||||
--label = "test",
|
||||
default = file,
|
||||
close_on_enter = false,
|
||||
--this breaks the scrollbar
|
||||
--[[ props = {
|
||||
border = false,
|
||||
} ]]
|
||||
},
|
||||
{
|
||||
type = "box",
|
||||
x = 0,
|
||||
y = 10,
|
||||
w = 10,
|
||||
h = 1,
|
||||
color = "#ffffff"
|
||||
},
|
||||
{
|
||||
type = "field",
|
||||
x = 0,
|
||||
y = 10,
|
||||
w = 10,
|
||||
h = 1,
|
||||
name = "nano_commands",
|
||||
close_on_enter = false,
|
||||
pwd = "",
|
||||
props = {
|
||||
border = false,
|
||||
},
|
||||
on_event = function(form, player, element, value, fields)
|
||||
if value == "save" and fields.nano_editor then
|
||||
--minetest.chat_send_all(fields.nano_editor)
|
||||
if #fields.nano_editor < 12000 then --12000 is luacheck line length of 120 * 100 lines
|
||||
minetest.safe_file_write(path .. "/" .. input:split(" ")[1], fields.nano_editor)
|
||||
else
|
||||
computers.api.chat_send_player(player, minetest.colorize("red", "[Nano]: file is to long"))
|
||||
end
|
||||
elseif value == "exit" then
|
||||
local btn = computers.formspec.get_index_by_name(form, "nano_btn")
|
||||
local ctn = computers.formspec.get_index_by_name(form, "nano_ctn")
|
||||
form[ctn].state = 1
|
||||
table.remove(form, btn)
|
||||
--table.remove(form, ctn) cant actually remove it from within itself, therefore we hide it
|
||||
local tindex = 0
|
||||
for index, tab in pairs(form.tabs) do
|
||||
if tab == "nano" then tindex = index end
|
||||
end
|
||||
table.remove(form.tabs, tindex)
|
||||
tindex = computers.formspec.get_index_by_name(form, "terminal_ctn")
|
||||
|
||||
form[tindex].state = 0
|
||||
else
|
||||
computers.api.chat_send_player(player, minetest.colorize("red", "[Nano]: invalid command"))
|
||||
end
|
||||
|
||||
return form
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
return form
|
||||
end
|
||||
|
||||
return nano
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "touch",
|
||||
"license": "MIT",
|
||||
"version": 0.2,
|
||||
"engine": 0.4,
|
||||
"version": 0.3,
|
||||
"engine": 0.42,
|
||||
"help": "creates a file in the current path"
|
||||
}
|
@ -3,11 +3,14 @@ function touch(pos, input, data)
|
||||
--make dir to be safe
|
||||
minetest.mkdir(path)
|
||||
|
||||
if #minetest.get_dir_list(path, false) > 10
|
||||
and not minetest.check_player_privs(data.player, "computers_filesystem") then
|
||||
return "ERROR: you have reached your max file limit"
|
||||
end
|
||||
|
||||
if input and input ~= "" and not input:find("/") then
|
||||
for _, item in pairs(minetest.get_dir_list(path, nil)) do
|
||||
if item == input then
|
||||
return "ERROR: trying to create already existing file/folder"
|
||||
end
|
||||
if computers.api.get_dir_keyed_list(path, nil)[input] then
|
||||
return "ERROR: trying to create already existing file/folder"
|
||||
end
|
||||
minetest.safe_file_write(path .. "/" .. input, "")
|
||||
return "file " .. input .. " created"
|
||||
|
Reference in New Issue
Block a user