Advertisement
HydrantHunter

Discovery Address Importer

Apr 8th, 2016
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. --[[ LanteaCraft & SGCraft ]]--
  2. --[[   DiscoveryImporter   ]]--
  3. --[[        by Dog         ]]--
  4. --[[         aka           ]]--
  5. --[[     HydrantHunter     ]]--
  6. --[[  pastebin: AAjVTFA3   ]]--
  7. local addressBook, newGates, numNewGates = { }, { }, 0
  8. print("")
  9. --# Check for necessary files and ingest data
  10. if not fs.exists("gateList") then
  11.   print("Unable to locate discoDialer gateList")
  12.   print("Nothing to import to ccDHD address book\n")
  13.   return
  14. end
  15. if not fs.exists("/data/DHDgates") then
  16.   print("Unable to locate ccDHD address book")
  17.   print("Address book will be generated in /data\n")
  18.   if not fs.exists("/data") then fs.makeDir("/data") end
  19. else
  20.   local dhdData = fs.open("/data/DHDgates", "r")
  21.   addressBook = textutils.unserialize(dhdData.readAll())
  22.   dhdData.close()
  23.   if #addressBook >= 23976 then
  24.     print("ccDHD address book is FULL\n")
  25.     return
  26.   end
  27. end
  28. for address in io.lines("gateList") do
  29.   newGates[#newGates + 1] = { name = address, addr = address, rating = "U", iris = "none", callDrop = false, note = "Added from discoDialer", loc = { x = 99999, y = 99999, z = 99999, dim = "Unknown" } } --# ...create new entry
  30. end
  31. if #addressBook + #newGates > 23976 then
  32.   print("Not enough room in ccDHD address book\n")
  33.   return
  34. end
  35. --# Merge address books
  36. local matchFound = false                            --# matchFound indicates if a matching gate was found or not
  37. for i = 1, #newGates do                             --# start cycling through the 'new' list of gates
  38.   for j = 1, #addressBook do                        --# search the address book for a matching address
  39.     if newGates[i].addr == addressBook[j].addr then --# if the gate is already in the address book...
  40.       matchFound = true                             --# ...set matchFound to true and...
  41.       break                                         --# stop the address book search loop and move on to the next gate in the 'new' list
  42.     end
  43.   end
  44.   if not matchFound then                            --# if a match wasn't found...
  45.     addressBook[#addressBook + 1] = { }             --# initialize a new address book entry
  46.     for k, v in pairs(newGates[i]) do               --# loop through the gate entries...
  47.       addressBook[#addressBook][k] = v              --# ...and add them to the new address book entry
  48.     end
  49.     numNewGates = numNewGates + 1
  50.   else
  51.     matchFound = false                              --# if a match was found, reset the variable for the next iteration of the loop
  52.   end
  53. end
  54. --# Save data
  55. local dhdData = fs.open("/data/DHDgates", "w")
  56. dhdData.write(textutils.serialize(addressBook))
  57. dhdData.close()
  58. --# Display results
  59. print(tostring(#newGates) .. " new addresses processed.")
  60. print(tostring(numNewGates) .. " new addresses added.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement