slprogtools: read-only flag for memory copier added.

Memory Copier dongle can now be write-protected.

Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
This commit is contained in:
Michal Cieslakiewicz 2018-12-07 17:48:26 +01:00
parent 959a0a42fa
commit c41fbd41f4
2 changed files with 13 additions and 10 deletions

View File

@ -40,7 +40,7 @@ git clone https://github.com/realmicu/minetest-micupack.git micupack
Devices for interacting with SaferLua Controller from TechPack mod:
- Memory Copier - portable dongle to transfer code between SL Controllers in much simpler
and faster way than copying it with text books
and faster way than copying it with text books; can be write-protected
- Memory Programmer - improved Memory Copier, with read/write protection to prevent
accidental memory loss and code injection functionality (works like original Programmer
but for SL Controllers); it allows to replace special marker in init() section

View File

@ -155,6 +155,7 @@ local function formspec_copier(tool, tubelib_id)
local init_flag = tool_meta:get_int("init_flag") ~= 0
local loop_flag = tool_meta:get_int("loop_flag") ~= 0
local note_flag = tool_meta:get_int("note_flag") ~= 0
local ro_flag = tool_meta:get_int("ro_flag") ~= 0
local init_len = string.len(tool_meta:get_string("init_code"))
local loop_len = string.len(tool_meta:get_string("loop_code"))
local note_len = string.len(tool_meta:get_string("note_text"))
@ -168,12 +169,14 @@ local function formspec_copier(tool, tubelib_id)
"checkbox[0.5,1.5;init_flag;include " .. msg_M .. "init()" .. msg_W ..
" code (size: " .. tostring(init_len) .. ");" ..
tostring(init_flag) .. "]" ..
"checkbox[0.5,2.25;loop_flag;include " .. msg_M .. "loop()" .. msg_W ..
"checkbox[0.5,2;loop_flag;include " .. msg_M .. "loop()" .. msg_W ..
" code (size: " .. tostring(loop_len) .. ");" ..
tostring(loop_flag) .. "]" ..
"checkbox[0.5,3;note_flag;include " .. msg_M .. "notes" .. msg_W ..
"checkbox[0.5,2.5;note_flag;include " .. msg_M .. "notes" .. msg_W ..
" text (size: " .. tostring(note_len) .. ");" ..
tostring(note_flag) .. "]" ..
"checkbox[0.5,3;ro_flag;read only (archive mode);" ..
tostring(ro_flag) .. "]" ..
"button_exit[5,0.75;1.5,1;clear;Clear]" ..
"button_exit[5,1.5;1.5,1;download;Download]" ..
"button_exit[5,2.25;1.5,1;upload;Upload]" ..
@ -312,6 +315,10 @@ local function init_metadata_copier(player, tool)
local tool_meta = tool:get_meta()
local tool_upd = false
local metatable = tool_meta:to_table()
if not metatable.fields["ro_flag"] then
tool_meta:set_int("ro_flag", 0)
tool_upd = true
end
if not metatable.fields["init_flag"] then
tool_meta:set_int("init_flag", 1)
tool_upd = true
@ -350,10 +357,6 @@ local function init_metadata_programmer(player, tool)
tool_meta:set_int("wo_flag", 0)
tool_upd = true
end
if not metatable.fields["ro_flag"] then
tool_meta:set_int("ro_flag", 0)
tool_upd = true
end
if not metatable.fields["prog_mark"] then
tool_meta:set_string("prog_mark", def_marker)
tool_upd = true
@ -461,20 +464,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if fields.clear or fields.download or fields.upload then
-- copier window or memory tab buttons
-- (this must work also for copier which has no RW flags)
-- (this must work also for copier which has no WO flag)
local ro_flag = tool_meta:get_int("ro_flag") == 1
local wo_flag = tool_meta:get_int("wo_flag") == 1
if (fields.clear or fields.download) and ro_flag then
play_beep_err(player_name)
minetest.chat_send_player(player_name,
msg_Y .. "[" .. label .. "] " .. msg_R ..
"Device memory is write-protected! (see security tab)")
"Device memory is write-protected!")
return true
elseif fields.upload and wo_flag then
play_beep_err(player_name)
minetest.chat_send_player(player_name,
msg_Y .. "[" .. label .. "] " .. msg_R ..
"Device memory is read-protected! (see security tab)")
"Device memory is read-protected!")
return true
end
local init_flag = tool_meta:get_int("init_flag") ~= 0