Added files

This commit is contained in:
Tmanyo 2017-03-25 15:07:50 -04:00 committed by GitHub
parent 4bd15f31bc
commit a48d5fb362
9 changed files with 306 additions and 0 deletions

65
base.lua Normal file
View File

@ -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)

178
commands/base_commands.lua Normal file
View File

@ -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)

6
init.lua Normal file
View File

@ -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")

57
nodes.lua Normal file
View File

@ -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}
})

BIN
textures/case.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
textures/monitor_bottom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

BIN
textures/monitor_screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

BIN
textures/tower_front.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B