Guest User

controllerSetup

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