-- RemFS Server hostname="" hostroot="hostfiles/" rednet.host("remfs", hostname) rednet.host("remfsh", hostname) local hndls={} local freeh={} function add(queue, val) queue[(#queue)+1]=val end function peek(queue) return queue[1] end function shiftDown(queue) while i=2,#queue do queue[i-1]=queue[i] end queue[#queue]=nil end function takeaway(queue) obj=queue[1] while i=2,#queue do queue[i-1]=queue[i] end queue[#queue]=nil return obj end while true do sid, msg, ptc = rednet.receive() if(ptc=="remfs") then if(msg[1]=="open")then msg[2]=hostroot+msg[2] ok, ret = pcall(fs[msg[1]],unpack(msg, 2)) hid=nil if(#freeh==0) then hid=(#hndls)+1 else hid=takeaway(freeh) end handls[hid]=ret rednet.send(sid, hid,"remfs") else msg[2]=hostroot+msg[2] --erg=fs[msg[1]](unpack(msg, 2)) ok, ret = pcall(fs[msg[1]],unpack(msg, 2)) rednet.send(sid, ret,"remfs") end elseif(ptc=="remfsh") then ok, ret = pcall(hndls[msg[3]][msg[1]],msg[2]) if not(ret==nil) then rednet.send(sid, ret,"remfsh") end if msg[1]=="close" then add(freeh,msg[3]) end end end