Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft & SGCraft ]]--
- --[[ DiscoveryImporter ]]--
- --[[ by Dog ]]--
- --[[ aka ]]--
- --[[ HydrantHunter ]]--
- --[[ pastebin: AAjVTFA3 ]]--
- local addressBook, newGates, numNewGates = { }, { }, 0
- print("")
- --# Check for necessary files and ingest data
- if not fs.exists("gateList") then
- print("Unable to locate discoDialer gateList")
- print("Nothing to import to ccDHD address book\n")
- return
- end
- if not fs.exists("/data/DHDgates") then
- print("Unable to locate ccDHD address book")
- print("Address book will be generated in /data\n")
- if not fs.exists("/data") then fs.makeDir("/data") end
- else
- local dhdData = fs.open("/data/DHDgates", "r")
- addressBook = textutils.unserialize(dhdData.readAll())
- dhdData.close()
- if #addressBook >= 23976 then
- print("ccDHD address book is FULL\n")
- return
- end
- end
- for address in io.lines("gateList") do
- 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
- end
- if #addressBook + #newGates > 23976 then
- print("Not enough room in ccDHD address book\n")
- return
- end
- --# Merge address books
- local matchFound = false --# matchFound indicates if a matching gate was found or not
- for i = 1, #newGates do --# start cycling through the 'new' list of gates
- for j = 1, #addressBook do --# search the address book for a matching address
- if newGates[i].addr == addressBook[j].addr then --# if the gate is already in the address book...
- matchFound = true --# ...set matchFound to true and...
- break --# stop the address book search loop and move on to the next gate in the 'new' list
- end
- end
- if not matchFound then --# if a match wasn't found...
- addressBook[#addressBook + 1] = { } --# initialize a new address book entry
- for k, v in pairs(newGates[i]) do --# loop through the gate entries...
- addressBook[#addressBook][k] = v --# ...and add them to the new address book entry
- end
- numNewGates = numNewGates + 1
- else
- matchFound = false --# if a match was found, reset the variable for the next iteration of the loop
- end
- end
- --# Save data
- local dhdData = fs.open("/data/DHDgates", "w")
- dhdData.write(textutils.serialize(addressBook))
- dhdData.close()
- --# Display results
- print(tostring(#newGates) .. " new addresses processed.")
- print(tostring(numNewGates) .. " new addresses added.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement