From a48d5fb362af5b6a137599bf325db330c8824a61 Mon Sep 17 00:00:00 2001 From: Tmanyo Date: Sat, 25 Mar 2017 15:07:50 -0400 Subject: [PATCH] Added files --- base.lua | 65 ++++++++++++ commands/base_commands.lua | 178 +++++++++++++++++++++++++++++++++ init.lua | 6 ++ nodes.lua | 57 +++++++++++ textures/case.png | Bin 0 -> 158 bytes textures/monitor_bottom.png | Bin 0 -> 220 bytes textures/monitor_screen.png | Bin 0 -> 226 bytes textures/monitor_screen_on.png | Bin 0 -> 366 bytes textures/tower_front.png | Bin 0 -> 188 bytes 9 files changed, 306 insertions(+) create mode 100644 base.lua create mode 100644 commands/base_commands.lua create mode 100644 init.lua create mode 100644 nodes.lua create mode 100644 textures/case.png create mode 100644 textures/monitor_bottom.png create mode 100644 textures/monitor_screen.png create mode 100644 textures/monitor_screen_on.png create mode 100644 textures/tower_front.png diff --git a/base.lua b/base.lua new file mode 100644 index 0000000..e76d459 --- /dev/null +++ b/base.lua @@ -0,0 +1,65 @@ +function terminal_form(player) + local output = minetest.serialize(cprompt) + local end_out = output:gsub("{", ""):gsub("}", ""):gsub("return", ""):gsub("\"", ""):gsub(",", ""):gsub("\\", "") + minetest.show_formspec(player:get_player_name(), "lua_computer:terminal", + "size[10,10]" .. + "background[0,0;10,10;monitor_screen.png;true]" .. + "textarea[.8,.5;8.84,9.37;terminal;;>" .. minetest.formspec_escape(end_out) .. "]" .. + "button[1,9.5;2,1;submit;]") +end + +-- If there isn't a file, make one. +local f, err = io.open(minetest.get_worldpath() .. "/email_information.db", "r") +if f == nil then + local f, err = io.open(minetest.get_worldpath() .. "/email_information.db", "w") + f:write(minetest.serialize(email)) + f:close() +end + +-- Saves changes to player's account. +function save_email() + local data = email + local f, err = io.open(minetest.get_worldpath() .. "/email_information.db", "w") + if err then + return err + end + f:write(minetest.serialize(data)) + f:close() +end + +-- Reads changes from player's account. +function read_email() + local f, err = io.open(minetest.get_worldpath() .. "/email_information.db", "r") + local data = minetest.deserialize(f:read("*a")) + f:close() + return data +end + +command_list = {} +refined_commands = {} +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "lua_computer:terminal" then + if fields.submit then + if fields.terminal ~= nil then + local s = minetest.serialize(cprompt) + local s_fin = s:gsub("{", ""):gsub("}", ""):gsub("return", ""):gsub("\"", "") + if string.match(fields.terminal, ">help") then + table.insert(cprompt, "help\n\nLua_Computer OS v0.1\n" .. + "You can view all commands by typing: command -list.\n>") + terminal_form(player) + end + if string.match(fields.terminal, ">command %-list") then + command_list = minetest.get_dir_list(minetest.get_modpath("lua_computer") .. + "/commands", false) + refined_commands = minetest.serialize(command_list):gsub("base_commands.lua", "") + :gsub(".lua", ""):gsub(",", "\n"):gsub(" ", "") + table.insert(cprompt, "command -list\n" .. refined_commands .. + " \nclose open\ndelete restart\n" .. + "help save\nip shutdown\nnew " .. + " time\n>") + terminal_form(player) + end + end + end + end +end) diff --git a/commands/base_commands.lua b/commands/base_commands.lua new file mode 100644 index 0000000..d2149b0 --- /dev/null +++ b/commands/base_commands.lua @@ -0,0 +1,178 @@ +fname = {} +close_question = {} +do_nothing = {} +total = 1 +email = {} +email_current_body = {} +email_current_subject = {} +recipient = {} +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "lua_computer:terminal" then + if fields.submit then + if string.match(fields.terminal, ">ip") then + local playername = player:get_player_name() + table.insert(cprompt, "ip\n\n" .. minetest.get_player_ip(playername) .. "\n>") + terminal_form(player) + end + if string.match(fields.terminal, ">new %-name .+") then + fname = string.match(fields.terminal, ">new %-name .+"):gsub(">new %-name ", "") + command_list = minetest.get_dir_list(minetest.get_modpath("lua_computer") .. + "/commands", false) + refined_commands = minetest.serialize(command_list):gsub("base_commands.lua", "") + :gsub(".lua", ""):gsub(",", "\n"):gsub(" ", "") + if string.match(refined_commands, fname) then + table.insert(cprompt, "new -name " .. fname .. " \n\nFile already exists.\n>") + else + cprompt = " " + end + terminal_form(player) + end + if string.match(fields.terminal, ">save") then + if fname == "" or fname == nil then + table.insert(cprompt, "save\n\nNo file is currently being edited.\n>") + terminal_form(player) + else + local f, err = io.open(minetest.get_modpath("lua_computer") .. "/commands/" .. + fname .. ".lua", "r") + if f == nil then + local f, err = io.open(minetest.get_modpath("lua_computer") .. + "/commands/" .. fname .. ".lua", "w") + local code = fields.terminal:gsub(">", ""):gsub("save", "") + f:write(code) + f:close() + else + local f, err = io.open(minetest.get_modpath("lua_computer") .. + "/commands/" .. fname .. ".lua", "w") + local code = fields.terminal:gsub(">", ""):gsub("save", "") + f:write(code) + f:close() + end + cprompt = {} + fname = "" + terminal_form(player) + end + end + if string.match(fields.terminal, ">open .+") then + local command_raw = string.match(fields.terminal, ">open .+") + local file_to_edit = command_raw:gsub(">open ", "") + local f, err = io.open(minetest.get_modpath("lua_computer") .. "/commands/" .. + file_to_edit, "r") + local code_to_edit = f:read("*a") + f:close() + cprompt = {} + table.insert(cprompt, code_to_edit) + fname = file_to_edit:gsub(".lua", "") + terminal_form(player) + end + if string.match(fields.terminal, ">close\n\n.+") then + do_nothing = 1 + elseif string.match(fields.terminal, ">close") then + if fname == nil then + table.insert(cprompt, ">close\n\nNo file is currently being edited.\n>") + terminal_form(player) + else + if close_question == 0 then + terminal_form(player) + else + table.insert(cprompt, ">close\n\nAre you sure you want to close? [Y/N]\n>") + terminal_form(player) + close_question = 1 + end + end + end + if string.match(fields.terminal, ">y.+") then + do_nothing = 1 + elseif string.match(fields.terminal, ">n.+") then + do_nothing = 1 + elseif string.match(fields.terminal, ">y") then + if close_question == 1 then + cprompt = {} + fname = "" + terminal_form(player) + close_question = 0 + else + table.insert(cprompt, "y\n\nNo action currently requires your approval.\n>") + terminal_form(player) + end + end + if string.match(fields.terminal, ">n") then + if close_question == 1 then + terminal_form(player) + close_question = 0 + fname = "" + else + table.insert(cprompt, "n\n\nNo action currently requires your approval.\n>") + terminal_form(player) + end + end + if string.match(fields.terminal, ">delete .+") then + local command_raw1 = string.match(fields.terminal, ">delete .+") + local file_to_delete = command_raw1:gsub(">delete ", "") + os.remove(minetest.get_modpath("lua_computer") .. "/commands/" .. file_to_delete) + table.insert(cprompt, "delete " .. file_to_delete .. " \n\nFile successfully deleted.\n>") + terminal_form(player) + end + if string.match(fields.terminal, ">restart") then + cprompt = {} + fname = "" + terminal_form(player) + end + if string.match(fields.terminal, ">shutdown") then + cprompt = {} + fname = "" + minetest.close_formspec(player:get_player_name(), "lua_computer:terminal") + end + if string.match(fields.terminal, ">time") then + table.insert(cprompt, "time\n\n" .. os.date("%c", os.time()) .. " \n>") + terminal_form(player) + end + if string.match(fields.terminal, ">email %-compose .+") then + recipient = string.match(fields.terminal, ">email %-compose .+"): + gsub(">email", ""):gsub("compose", ""):gsub(" ", ""):gsub("-", "") + if not email[total][recipient] then + email[total][recipient] = {} + else + total = #email[recipient] + 1 + email[total][recipient] = {} + end + table.insert(email[total][recipient],1,{sender=player:get_player_name()}) + cprompt = {} + table.insert(cprompt, "Subject:") + terminal_form(player) + email_current_subject = 1 + email_current_body = 1 + save_email() + end + if string.match(fields.terminal, "> Subject: .+") then + if email_current_subject ~= 1 then + do_nothing = 1 + else + if fields.terminal:sub(12, fields.terminal:len()) == nil then + table.insert(email[total][recipient],1,{subject="(No Subject)"}) + else + table.insert(email[total][recipient],1,{subject=fields.terminal: + sub(12, fields.terminal:len())}) + end + email_current_subject = 0 + save_email() + cprompt = {} + table.insert(cprompt, "Body:") + terminal_form(player) + end + end + if string.match(fields.terminal, "> Body: .+") then + if email_current_body ~= 1 then + do_nothing = 1 + elseif email_current_body == 1 then + table.insert(email[total][recipient],1,{body=fields.terminal:sub(9, fields.terminal: + len())}) + email_current_body = 0 + save_email() + cprompt = {} + table.insert(cprompt, "Email Successfully sent!") + terminal_form(player) + end + end + end + end +end) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..2d3e34a --- /dev/null +++ b/init.lua @@ -0,0 +1,6 @@ +cprompt = {} + +-- Load Lua files +dofile(minetest.get_modpath("lua_computer") .. "/nodes.lua") +dofile(minetest.get_modpath("lua_computer") .. "/base.lua") +dofile(minetest.get_modpath("lua_computer") .. "/commands/base_commands.lua") diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..0c6354c --- /dev/null +++ b/nodes.lua @@ -0,0 +1,57 @@ +local tmr = 0 +minetest.register_node("lua_computer:monitor_off", { + description = "Lua Computer Monitor", + tiles = { + "case.png", + "monitor_bottom.png", + "case.png", + "case.png", + "monitor_screen.png", + "case.png", + }, + groups = {cracky=3}, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + terminal_form(player) + local timer = minetest.get_node_timer(pos):start(0.2) + end, + on_timer = function(pos, elapsed) + if minetest.get_node_timer(pos):get_elapsed() == 2 then + minetest.set_node(pos, {name="lua_computer:monitor_on"}) + end + end +}) + +minetest.register_node("lua_computer:monitor_on", { + description = "Lua Computer Monitor On", + tiles = { + "case.png", + "monitor_bottom.png", + "case.png", + "case.png", + "monitor_screen_on.png", + "case.png", + }, + groups = {cracky=3, not_in_creative_inventory=1}, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + terminal_form(player) + local timer = minetest.get_node_timer(pos):start(0.2) + end, + on_timer = function(pos, elapsed) + if minetest.get_node_timer(pos):get_elapsed() == 2 then + minetest.set_node(pos, {name="lua_computer:monitor_off"}) + end + end +}) + +minetest.register_node("lua_computer:tower", { + description = "Lua Computer Tower", + tiles = { + "case.png", + "monitor_bottom.png", + "case.png", + "case.png", + "tower_front.png", + "case.png", + }, + groups = {cracky=3} +}) diff --git a/textures/case.png b/textures/case.png new file mode 100644 index 0000000000000000000000000000000000000000..edbd518ff4dad45e054b1b29c98bcbd0b72e94d1 GIT binary patch literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=sh%#5Ar-gYUU1}PVBla;2)_F! x-ly22GN9pAik&ti6AOocf*!PC{xWt~$(695@?A#MNw literal 0 HcmV?d00001 diff --git a/textures/monitor_bottom.png b/textures/monitor_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..ea56ef55f1a5645f564573089492530195f133b9 GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=i#=T&Ln>~)z3t1@pdi2&u+iF6 zeR^K_7M%$^O-Cxb^Pls77AQ1aw)UEBkq`sJXR+;1YECLUoM&NRxWmZ6z%y^_lzhf} zIvflR1`YOwQPs>qBcZ@R;DF^ib3Z6g;Ir%lpe6)xsBhpC1af;WXh_OAtkwa`a4;BL qp1-hKckM0)m!Bq*d@;YIHKASIrzelF{r5}E+wvpkIe literal 0 HcmV?d00001 diff --git a/textures/monitor_screen.png b/textures/monitor_screen.png new file mode 100644 index 0000000000000000000000000000000000000000..2239a34b3e98b17f1d9befd36e67e75629595a07 GIT binary patch literal 226 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=D?MEtLn>~)y}gmE*+8W2V#0xQ zjK3KkF?)!={JlToNt(c`TT8#pd)QoWmt?ebPygcdbwEuF2liU|){BE!B!UUD2f76r z=AEhe8vi$FeeL`6sgg(i*e^uAUOFZ4O$o!+YupNDyNn+go)>oja&PbI)0aP5#?8R+ a;UedpNqAgyOf1pn>`Q4GYhPgU79FN~|(o?!Fz@Z{=VuI%9;B$J5aPSK<4-^Ii5Q#9ESr!Lp9GA+vb|p zi#=K-SP`>+>avx$wuJ_YRNZ`AVlB0kx!}~{tfeZRS4?_e?Yj1{;KJXOM|=k~pDm34 zUOhE6({SGQXa)(!X$r>`?48c(I5OCIinx{;mc@Qg-K6uF8)PkUph2GP!7&bon3+2> z*3|{4U0#{j<}7`AE;C1y!@TD=XS|bXc>g<{;qu(ujNyO(NggP9&hYM7^6zK9KF>uM c7#hkenOog5-QG0^ECyNU>FVdQ&MBb@0LgQYaR2}S literal 0 HcmV?d00001 diff --git a/textures/tower_front.png b/textures/tower_front.png new file mode 100644 index 0000000000000000000000000000000000000000..451fe4bf3cbf2d98dafcd56431213229b94510c0 GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=&7LlfAr-gY-aN?5ARxfvuu%14 zefplCm4#=Lxea#eSgyQ!tKN@^;lW$xX>*n{Ff3qZ$YEZSETRb1%D`~IlmkpNv@lqF z1R2^O!~ztJ-3=1eaD>P)IOsHZ{BMMEU{pgbl=UH-&7o(8`o#&Ai$Nluu6{1-oD!M< D$678L literal 0 HcmV?d00001