mistamadd001

Untitled

Feb 10th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. local id = os.getComputerID()
  2.  
  3. function openRednet()
  4.   local listOfSides = rs.getSides()
  5.   listofPossibles = {}
  6.   local counter1 = 0
  7.   while true do
  8.     counter1 = counter1+1
  9.  
  10.     if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
  11.      table.insert(listofPossibles,tostring(listOfSides[counter1]))
  12.     end
  13.  
  14.     if counter1 == 6 and table.maxn(listofPossibles) == 0 then
  15.      
  16.      return nil
  17.     end
  18.  
  19.     if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
  20.      rednet.open(listofPossibles[1])
  21.      return listofPossibles[1]
  22.     end
  23.   end
  24. end
  25.  
  26. openRednet()
  27.  
  28. if fs.exists('clients') == false then
  29.   fs.makeDir('clients')
  30.   local file = fs.open('clients/cids','w')
  31.   file.close()
  32. else
  33. end
  34.  
  35. while true do
  36.   cID,cName = rednet.receive()
  37.   sleep(0.5)
  38.   if fs.exists('clients/'..cID)then
  39.     print('Client already installed')
  40.     rednet.send(cID, 'done')
  41.   else
  42.     local file = fs.open('clients/'..cID,'w')
  43.     file.write(cName)
  44.     file.close()
  45.     local file = fs.open('clients/cids','r')
  46.     local data = file.readAll()
  47.     file.close()
  48.     data = textutils.unserialize(data)
  49.     if data == nil then
  50.       data = {}
  51.     end
  52.     table.insert(data, tonumber(cID))
  53.     local file = fs.open('clients/cids','w')
  54.     file.write(textutils.serialize(data))
  55.     print('Client Install Successful')
  56.     rednet.send(cID, 'done')
  57.   end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment