diff --git a/computers/commands.lua b/computers/commands.lua index a89be2d..492cc5e 100644 --- a/computers/commands.lua +++ b/computers/commands.lua @@ -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") diff --git a/computers/commands/cd/conf.json b/computers/commands/cd/conf.json index a67e64a..20574fa 100644 --- a/computers/commands/cd/conf.json +++ b/computers/commands/cd/conf.json @@ -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" } \ No newline at end of file diff --git a/computers/commands/cd/init.lua b/computers/commands/cd/init.lua index 925350f..45a5483 100644 --- a/computers/commands/cd/init.lua +++ b/computers/commands/cd/init.lua @@ -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 diff --git a/computers/commands/mkdir/conf.json b/computers/commands/mkdir/conf.json index f862bbc..e624619 100644 --- a/computers/commands/mkdir/conf.json +++ b/computers/commands/mkdir/conf.json @@ -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" } \ No newline at end of file diff --git a/computers/commands/mkdir/init.lua b/computers/commands/mkdir/init.lua index dad19f7..5dbdd54 100644 --- a/computers/commands/mkdir/init.lua +++ b/computers/commands/mkdir/init.lua @@ -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 diff --git a/computers/commands/touch/conf.json b/computers/commands/touch/conf.json index 2501f4c..0d69882 100644 --- a/computers/commands/touch/conf.json +++ b/computers/commands/touch/conf.json @@ -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" } \ No newline at end of file diff --git a/computers/commands/touch/init.lua b/computers/commands/touch/init.lua index 9039d79..0e28c43 100644 --- a/computers/commands/touch/init.lua +++ b/computers/commands/touch/init.lua @@ -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 diff --git a/computers/gui.lua b/computers/gui.lua index cef87e5..df7bd72 100644 --- a/computers/gui.lua +++ b/computers/gui.lua @@ -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 .."$" .. " " diff --git a/computers/init.lua b/computers/init.lua index 55849b4..7e3f3a3 100644 --- a/computers/init.lua +++ b/computers/init.lua @@ -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",