
storeserver
By: a guest on
May 4th, 2012 | syntax:
Lua | size: 0.96 KB | hits: 19 | expires: Never
rednet.open("back")
os.loadAPI("split")
print("Google Store Server")
print("Please put the wireless modem on the back.")
t = {"downloads","downloads/info","downloads/files"}
for i = 1, 3 do
if (fs.exists(t[i])) then
print(t[i].." found!")
else
print(t[i].." not found. Creating...")
fs.makeDir(t[i])
end
end
print("Google Store Server Initialized!")
while true do
local id, msg = rednet.receive()
msg = split(msg,":")
if (msg[1] == "store_ping") then
print(id.." is requesting download list.")
local list = "Download list...\n" + table.concat(fs.list("downloads/files"))
rednet.send(id,"list:"+list)
elseif (msg[1] == "download") then
print(id.." is wanting to download "..msg[2].."!")
if (fs.exists("downloads/files/"..msg[2])) then
print("downloads/files/"..msg[2].." exists!")
link = fs.open("downloads/files/"..msg[2],"r")
rednet.send(id,link.readAll())
link.close()
else
rednet.send(id,"existerror")
print(msg[2].." doesn't exist!")
end
end
end