From 8adb23d04e42c5ecff4cdb1986f45fb8af55e613 Mon Sep 17 00:00:00 2001 From: cheapie Date: Mon, 30 Jan 2017 20:07:00 -0600 Subject: Add content --- init.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 init.lua (limited to 'init.lua') diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..162e98f --- /dev/null +++ b/init.lua @@ -0,0 +1,80 @@ +math.randomseed(os.time()) + +local function tempname() + local name = "/tmp/das-" + name = name..math.random(1000,9999) + return(name) +end + +local on_digiline_receive = function (pos, node, channel, msg) + local meta = minetest.get_meta(pos) + local setchan = meta:get_string("channel") + local dev = meta:get_string("device") + local intemp = tempname() + local outtemp = tempname() + local ret = {} + local sendlen = 0 + if channel ~= setchan then return end + if type(msg) ~= "table" then return end + local cdb = "" + for i=1,string.len(msg.cdb),1 do + local byte = string.sub(msg.cdb,i,i) + cdb = string.format("%s %02X",cdb,string.byte(byte)) + end + local cmd = "sudo sg_raw -vvvR "..dev..cdb + if msg.request then + cmd = cmd.." -r "..msg.request.." -o "..intemp + end + if msg.data then + sendlen = string.len(msg.data) + local outfile = io.open(outtemp,"w") + outfile:write(msg.data) + outfile:close() + cmd = cmd.." -s "..sendlen.." -i "..outtemp + end + print(cmd) + os.execute(cmd) + if msg.request then + local infile = io.open(intemp,"r") + if infile then + local indata = infile:read("*all") + infile:close() + os.execute("sudo rm "..intemp) + ret.data = indata + end + end + if msg.data then + os.execute("sudo rm "..outtemp) + end + digiline:receptor_send(pos, digiline.rules.default, channel, ret) +end + +minetest.register_node("das:scsi_gateway", { + tiles = { + "das_logo.png" + }, + digiline = + { + receptor = {}, + effector = {action = on_digiline_receive} + }, + groups = {cracky=2}, + description = "DAS<->SCSI Gateway", + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec","size[8,4;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;6,2;device;Device;${device}]button_exit[2.25,3;3,1;submit;Save]") + meta:set_string("device","/dev/sda") + meta:set_string("channel","scsi") + end, + on_receive_fields = function(pos, formname, fields, sender) + local name = sender:get_player_name() + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then + minetest.record_protection_violation(pos,name) + return + end + local meta = minetest.get_meta(pos) + if fields.channel then meta:set_string("channel",fields.channel) end + if fields.device then meta:set_string("device",fields.device) end + end, + sounds = default.node_sound_stone_defaults() +}) -- cgit v1.2.3