Advertisement
NanoBob

NanoStorage server

Dec 24th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local storagePrefix="str"
  2. local messagePrefix="con"
  3.  
  4. function connectAllClients()
  5.     allClients={}
  6.     repeat
  7.         local timer = os.startTimer(1)
  8.         message=#allClients+1
  9.         rednet.broadcast(messagePrefix..message)
  10.         local event,id,message=os.pullEvent()
  11.         if event=="rednet_message" then
  12.             if message==storagePrefix..message then
  13.                 allClients[message]=id
  14.                 timedOut=false
  15.                 rednet.send(id,"Connection accepted")
  16.             end
  17.         elseif event=="timer" and id==timer then
  18.             timedOut=true
  19.         else
  20.             timedOut=false
  21.         end
  22.     until timedOut==true   
  23.     return allClients
  24. end
  25.  
  26. function getAllClientItems()
  27.     if allClients==nil then
  28.         connectAllClients()
  29.     end
  30.     allClientItems={}
  31.     for id,data in ipairs(allClients) do
  32.         rednet.send(id,"Requesting itemlist")
  33.         repeat
  34.             id,message=rednet.receive()
  35.         until messageID==id
  36.         itemString=message
  37.         itemTable=toTable(itemString)
  38.         allClientItems[id]=itemTable
  39.     end
  40.     return allClientItems
  41. end
  42.  
  43. function toTable(tableString)
  44.    
  45. end
  46.  
  47. function fromTable(toStringTable)
  48.     workTable=toStringTable
  49.     fullString=""
  50.     repeat
  51.         for id,data in pairs(workTable) do
  52.            
  53.         end
  54.     until type(data)~="table"
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement