From 8adb23d04e42c5ecff4cdb1986f45fb8af55e613 Mon Sep 17 00:00:00 2001 From: cheapie Date: Mon, 30 Jan 2017 20:07:00 -0600 Subject: Add content --- README | 11 +++++++ depends.txt | 2 ++ init.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ textures/das_logo.png | Bin 0 -> 855 bytes 4 files changed, 93 insertions(+) create mode 100644 README create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/das_logo.png diff --git a/README b/README new file mode 100644 index 0000000..4d22187 --- /dev/null +++ b/README @@ -0,0 +1,11 @@ +--- YOU PROBABLY DO NOT WANT TO USE THIS MOD --- + +This mod CAN (and WILL if you are not careful): +* Brick SCSI devices +* Format your hard drive +* Corrupt/overwrite files +* Many, many more Bad Things + +--- DO NOT RUN THIS ON A PUBLIC SERVER --- + +That said, if you do want to use it anyway, you will need to enable passwordless sudo (told you this mod was a bad idea) and install sg_raw. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..6346be3 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +digilines +default 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() +}) diff --git a/textures/das_logo.png b/textures/das_logo.png new file mode 100644 index 0000000..7b27e44 Binary files /dev/null and b/textures/das_logo.png differ -- cgit v1.2.3