priv gate things + bugfixes

This commit is contained in:
unknown 2022-02-13 10:43:41 -05:00
parent 3e4e65e01b
commit 2593c55ee3
9 changed files with 33 additions and 12 deletions

View File

@ -1,6 +1,12 @@
computers.registered_commands = {}
computers.registered_confs = {}
minetest.register_privilege("computers_filesystem", {
description = "advanced use of computers filesystem",
give_to_singleplayer = false,
give_to_admin = false,
})
function computers.register_command(modpath)
local func = dofile(modpath .. "/init.lua")
local f = io.open(modpath .. "/conf.json")

View File

@ -1,7 +1,7 @@
{
"name": "cd",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"version": 0.11,
"engine": 0.41,
"help": "move in and out of folders"
}

View File

@ -1,4 +1,7 @@
function cd(pos, input, data)
if not minetest.check_player_privs(data.player, "computers_filesystem") then
return "ERROR: permision denied"
end
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
if input and input ~= "" and not input:find("/") and not input:find("\\") then

View File

@ -1,7 +1,7 @@
{
"name": "mkdir",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"version": 0.11,
"engine": 0.41,
"help": "makes a dir in the current path"
}

View File

@ -1,4 +1,7 @@
function mkdir(pos, input, data)
if not minetest.check_player_privs(data.player, "computers_filesystem") then
return "ERROR: permision denied"
end
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
if input and input ~= "" and not input:find("/") and not input:find("\\") then

View File

@ -1,7 +1,7 @@
{
"name": "touch",
"license": "MIT",
"version": 0.1,
"version": 0.2,
"engine": 0.4,
"help": "creates a file in the current path"
}

View File

@ -4,6 +4,11 @@ function touch(pos, input, data)
minetest.mkdir(path)
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
end
minetest.safe_file_write(path .. "/" .. input, "")
return "file " .. input .. " created"
else

View File

@ -127,7 +127,8 @@ function computers.load_gui(pos, node, clicker)
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
local text = form[cindex][eindex].default
local pass_table = {
element = element
element = element,
player = player
}
if value == "clear" then
@ -136,17 +137,20 @@ function computers.load_gui(pos, node, clicker)
local cdata = value:split(" ", false, 1)
if computers.registered_commands[cdata[1]] then
if value == "clear" then
form[cindex][eindex].default = "user:~$ "
elseif value == "" then
form[cindex][eindex].default = text .. "user:~" .. element.pwd .."$" .. "\n"
elseif computers.registered_commands[cdata[1]] and cdata[2] == "-v" then
form[cindex][eindex].default = text .. value .. "\n" ..
computers.registered_confs[cdata[1]].version .. "\nuser:~" .. element.pwd .."$" .. "\n"
elseif computers.registered_commands[cdata[1]] then
form[cindex][eindex].default = text .. value .. "\n"
text = form[cindex][eindex].default
local output = computers.registered_commands[cdata[1]](pos, cdata[2], pass_table)
if output and type(output) == "string" then
form[cindex][eindex].default = text .. output .. "\n" .. "user:~" .. element.pwd .."$" .." "
end
elseif value == "clear" then
form[cindex][eindex].default = "user:~$ "
elseif value == "" then
form[cindex][eindex].default = text .. "user:~" .. element.pwd .."$" .. "\n"
else
form[cindex][eindex].default = text .. value ..
"\nERROR: command not found\n" .. "user:~" .. element.pwd .."$" .. " "

View File

@ -8,7 +8,7 @@ minetest.mkdir(computers.devicepath) --make sure it exists
minetest.mkdir(computers.networkpath) --make sure it exists
computers.os = {
version = 0.4,
version = 0.41,
name = "kuto",
authors = {"wsor", "luk3yx"},
license = "MIT",