Make terminal error and help much more verbose.
This commit is contained in:
parent
b6ecf4d259
commit
8d11dccd91
@ -41,22 +41,22 @@ local commands = {
|
|||||||
end,
|
end,
|
||||||
append = function(output, params, c)
|
append = function(output, params, c)
|
||||||
if not c.rw then
|
if not c.rw then
|
||||||
return output .. "\nno write access"
|
return output .. "\nError: No write access"
|
||||||
end
|
end
|
||||||
local what, _ = get_cmd_params(params)
|
local what, _ = get_cmd_params(params)
|
||||||
if what == "" then
|
if what == "" then
|
||||||
return output .. "\nMissing file name"
|
return output .. "\nError: Missing file name"
|
||||||
end
|
end
|
||||||
c.writing = what
|
c.writing = what
|
||||||
return output .. "\n" .. "writing \"" .. what .. "\". Enter STOP on a line by itself to finish"
|
return output .. "\nWriting \"" .. what .. "\". Enter STOP on a line by itself to finish"
|
||||||
end,
|
end,
|
||||||
write = function(output, params, c)
|
write = function(output, params, c)
|
||||||
if not c.rw then
|
if not c.rw then
|
||||||
return output .. "\nno write access"
|
return output .. "\nError: No write access"
|
||||||
end
|
end
|
||||||
local what, _ = get_cmd_params(params)
|
local what, _ = get_cmd_params(params)
|
||||||
if what == "" then
|
if what == "" then
|
||||||
return output .. "\nMissing file name"
|
return output .. "\nError: Missing file name"
|
||||||
end
|
end
|
||||||
c.writing = what
|
c.writing = what
|
||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
@ -68,37 +68,37 @@ local commands = {
|
|||||||
meta:set_string("files", minetest.write_json(files))
|
meta:set_string("files", minetest.write_json(files))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return output .. "\n" .. "writing \"" .. what .. "\". Enter STOP on a line by itself to finish"
|
return output .. "\nWriting \"" .. what .. "\". Enter STOP on a line by itself to finish"
|
||||||
end,
|
end,
|
||||||
remove = function(output, params, c)
|
remove = function(output, params, c)
|
||||||
if not c.rw then
|
if not c.rw then
|
||||||
return output .. "\nno write access"
|
return output .. "\nError: No write access"
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
local meta_files = meta:get_string("files")
|
local meta_files = meta:get_string("files")
|
||||||
if not meta_files or meta_files == "" then
|
if not meta_files or meta_files == "" then
|
||||||
return output .. "\nNo such file"
|
return output .. "\nError: No such file"
|
||||||
end
|
end
|
||||||
local files = minetest.parse_json(meta_files) or {}
|
local files = minetest.parse_json(meta_files) or {}
|
||||||
local first, _ = get_cmd_params(params)
|
local first, _ = get_cmd_params(params)
|
||||||
if files[first] then
|
if files[first] then
|
||||||
files[first] = nil
|
files[first] = nil
|
||||||
else
|
else
|
||||||
return output .. "\n" .. "No such file"
|
return output .. "\nError: No such file"
|
||||||
end
|
end
|
||||||
meta:set_string("files", minetest.write_json(files))
|
meta:set_string("files", minetest.write_json(files))
|
||||||
return output .. "\n" .. "removed \"" .. first .. "\""
|
return output .. "\nRemoved \"" .. first .. "\""
|
||||||
end,
|
end,
|
||||||
list = function(output, params, c)
|
list = function(output, params, c)
|
||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
local meta_files = meta:get_string("files")
|
local meta_files = meta:get_string("files")
|
||||||
local files
|
local files
|
||||||
if not meta_files or meta_files == "" then
|
if not meta_files or meta_files == "" then
|
||||||
return output .. "\nNo files found"
|
return output .. "\nError: No files found"
|
||||||
end
|
end
|
||||||
files = minetest.parse_json(meta_files) or {}
|
files = minetest.parse_json(meta_files) or {}
|
||||||
if not files then
|
if not files then
|
||||||
return output .. "\nNo files found"
|
return output .. "\nError: No files found"
|
||||||
end
|
end
|
||||||
for k, _ in pairs(files) do
|
for k, _ in pairs(files) do
|
||||||
output = output .. "\n" .. k
|
output = output .. "\n" .. k
|
||||||
@ -112,26 +112,26 @@ local commands = {
|
|||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
local meta_files = meta:get_string("files")
|
local meta_files = meta:get_string("files")
|
||||||
if not meta_files or meta_files == "" then
|
if not meta_files or meta_files == "" then
|
||||||
return output .. "\nNo such file"
|
return output .. "\nError: No such file"
|
||||||
end
|
end
|
||||||
local files = minetest.parse_json(meta_files) or {}
|
local files = minetest.parse_json(meta_files) or {}
|
||||||
local first, _ = get_cmd_params(params)
|
local first, _ = get_cmd_params(params)
|
||||||
if files[first] then
|
if files[first] then
|
||||||
return output .. "\n" .. files[first]
|
return output .. "\n" .. files[first]
|
||||||
else
|
else
|
||||||
return output .. "\n" .. "No such file"
|
return output .. "\nError: No such file"
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
lock = function(output, params, c)
|
lock = function(output, params, c)
|
||||||
if not c.rw then
|
if not c.rw then
|
||||||
return output .. "\nno write access"
|
return output .. "\nError: no write access"
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
meta:set_int("locked", 1)
|
meta:set_int("locked", 1)
|
||||||
return output .. "\n" .. "terminal locked"
|
return output .. "\n" .. "Terminal locked"
|
||||||
end,
|
end,
|
||||||
unlock = function(output, params, c)
|
unlock = function(output, params, c)
|
||||||
return output .. "\n" .. "unable to connect to authentication service"
|
return output .. "\n" .. "Error: unable to connect to authentication service"
|
||||||
end,
|
end,
|
||||||
help = function(output, params, c)
|
help = function(output, params, c)
|
||||||
if params ~= "" then
|
if params ~= "" then
|
||||||
@ -139,11 +139,14 @@ local commands = {
|
|||||||
if help[h] then
|
if help[h] then
|
||||||
return output .. "\n" .. help[h]
|
return output .. "\n" .. help[h]
|
||||||
else
|
else
|
||||||
return output .. "\nno help for \"" .. h .. "\""
|
return output .. "\nError: No help for \"" .. h .. "\""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return output .. "\n" ..
|
return output .. "\n" ..
|
||||||
"append clear echo help list lock read remove unlock write"
|
"Available commands:\n" ..
|
||||||
|
" append\n clear\n echo\n help\n list\n lock\n" ..
|
||||||
|
" read\n remove\n unlock\n write\n" ..
|
||||||
|
"Type `help <command>` for more help about that command"
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +175,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
-- input validation
|
-- input validation
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local c = context[name]
|
local c = context[name]
|
||||||
if not context[name] then
|
if not c then
|
||||||
minetest.log("error", name .. " sends invalid formspec data")
|
minetest.log("error", name .. " sends invalid formspec data")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -187,7 +190,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if not c.rw then
|
if not c.rw then
|
||||||
c.writing = nil
|
c.writing = nil
|
||||||
output = output .. "\n" .. line
|
output = output .. "\n" .. line
|
||||||
output = output .. "\nno write access"
|
output = output .. "\nError: no write access"
|
||||||
c.output = output
|
c.output = output
|
||||||
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
||||||
return true
|
return true
|
||||||
@ -214,8 +217,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
files[c.writing] = files[c.writing] .. "\n" .. line
|
files[c.writing] = files[c.writing] .. "\n" .. line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
meta:set_string("files", minetest.write_json(files))
|
if string.len(files[c.writing]) < 16384 then
|
||||||
output = output .. "\n" .. line
|
local json = minetest.write_json(files)
|
||||||
|
if string.len(json) < 49152 then
|
||||||
|
meta:set_string("files", json)
|
||||||
|
output = output .. "\n" .. line
|
||||||
|
else
|
||||||
|
output = output .. "\n" .. "Error: no space left on device"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
output = output .. "\n" .. "Error: maximum file length exceeded"
|
||||||
|
end
|
||||||
c.output = output
|
c.output = output
|
||||||
minetest.show_formspec(name, "terminal:", make_formspec(output, ""))
|
minetest.show_formspec(name, "terminal:", make_formspec(output, ""))
|
||||||
else
|
else
|
||||||
@ -225,7 +237,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
local meta = minetest.get_meta(c.pos)
|
local meta = minetest.get_meta(c.pos)
|
||||||
local cmd, params = get_cmd_params(line)
|
local cmd, params = get_cmd_params(line)
|
||||||
if meta:get_int("locked") == 1 and cmd ~= "unlock" then
|
if meta:get_int("locked") == 1 and cmd ~= "unlock" then
|
||||||
output = output .. "\nTerminal locked, type \"unlock\" to unlock it"
|
output = output .. "\nError: Terminal locked, type \"unlock\" to unlock it"
|
||||||
c.output = output
|
c.output = output
|
||||||
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
||||||
return true
|
return true
|
||||||
@ -235,13 +247,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if fn then
|
if fn then
|
||||||
output = fn(output, params, c)
|
output = fn(output, params, c)
|
||||||
else
|
else
|
||||||
output = output .. "\n" .. "Syntax Error. Try \"help\""
|
output = output .. "\n" .. "Error: Syntax Error. Try \"help\""
|
||||||
end
|
end
|
||||||
c.output = output
|
c.output = output
|
||||||
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
minetest.show_formspec(name, "terminal:", make_formspec(output, "> "))
|
||||||
end
|
end
|
||||||
elseif fields.quit then
|
elseif fields.quit then
|
||||||
|
context[name] = nil
|
||||||
minetest.sound_play("terminal_power_off", {pos = c.pos})
|
minetest.sound_play("terminal_power_off", {pos = c.pos})
|
||||||
|
else
|
||||||
|
minetest.log("error", name .. " sends invalid formspec data")
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user