Posted 11 June 2012 - 02:47 AM
Is it possible to make a server to store data and other files in minecraft? Can you send files and directories and such over rednet? If so HOW
Thank you
Thank you
file = fs.open(location, mode)
Example code:
file = fs.open("helloworld", r)
local var = file.readAll()
file.close() -- IMPORTANT
rednet.send(id, file)
Example code:
rednet.send(0, passwordData)
Ohreally?:As for sending directories, no, there's no way to send an entire directory with files inside.
local fAllFiles = fs.list("/")
for i, fItem in pairs(fAllFiles) do
if fs.isDir(fItem) then
local fDirFiles = fs.list(fItem)
for ij, fDirItem in pairs(fDirFiles) do
local fDirItemRead = fs.open(fDirItem, "r")
if fDirItemRead then
rednet.broadcast(fDirItemRead.readAll())
fDirItemRead.close()
else
error("Error when handling file in directory '"..fItem.."'.nFile deleted while processing?")
end
end
else
local fItemRead = fs.open(fItem, "r")
if fItemRead then
rednet.broadcast(fItemRead.readAll())
fItemRead.close()
else
error("Error when handling file '"..fItem.."'.nFile deleted while processing?")
end
end
end
Wow, didn't know that was possible.Ohreally?:
Sure:Thank you both but i don't get the directories thing… can you put "–" and explain it
local fAllFiles = fs.list("/") -- Now fAllFiles is a table of all files on the computer.
for i, fItem in pairs(fAllFiles) do -- Loop through each file in fAllFiles
if fs.isDir(fItem) then -- If the file is a directory
local fDirFiles = fs.list(fItem) -- Now fDirFiles is a table of all files in the directory
for ij, fDirItem in pairs(fDirFiles) do -- Loop through each file in fDirFiles
local fDirItemRead = fs.open(fDirItem, "r") -- Open the current "selected" file in read mode
if fDirItemRead then -- If the file exists / no errors when opening
rednet.broadcast(fDirItemRead.readAll()) -- Broadcast the file contents
fDirItemRead.close() -- Close the file handler
else -- Else (if the file doesn't exist / there is an error)
error("Error when handling file in directory '"..fItem.."'.nFile deleted while processing?") -- Quit program with error message inside "s
end -- End
end -- same, lol
else -- If the file isn't a directory
local fItemRead = fs.open(fItem, "r") -- Open the current "selected" file in read mode
if fItemRead then -- If the file exists / no errors when opening
rednet.broadcast(fItemRead.readAll())
fItemRead.close()
else -- Else (if the file doesn't exist / there is an error)
error("Error when handling file '"..fItem.."'.nFile deleted while processing?") -- Quit program with error message inside "s
end -- What the End comment said, k? I'm gonna stop these comments now.
end
end
=)