Quintuple_agent

Helping mistamadd001

Feb 10th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 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. end
  33.  
  34. while true do
  35.     cID,cName = "test7","yetanothertest"
  36.     sleep(0.5)
  37.     if fs.exists('clients/'..cID)then
  38.         print('Client already installed')
  39.         rednet.send(cID, 'done')
  40.     else
  41.     local file = fs.open('clients/'..cID,'w')
  42.     file.write(cName)
  43.     file.close()
  44.     local file = fs.open('clients/cids','r')
  45.     local data = file.readAll()
  46.     file.close()
  47.     data = textutils.unserialize(data)
  48.     local dataLength = 1
  49.     if data ~= nil then
  50.         dataLength = #data + 1
  51.     else
  52.         data={}
  53.     end
  54.     data[dataLength] = cID
  55.     local file = fs.open('clients/cids','w')
  56.     file.write(textutils.serialize(data))
  57.     file.close()
  58.     print('Client Install Successful')
  59.     rednet.send(cID, 'done')
  60.   end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment