Advertisement
PancakePhD

Slot Disk Writer

May 13th, 2024 (edited)
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. local charset = {}  do -- [0-9a-zA-Z]
  2.     for c = 48, 57  do table.insert(charset, string.char(c)) end
  3.     for c = 65, 90  do table.insert(charset, string.char(c)) end
  4.     for c = 97, 122 do table.insert(charset, string.char(c)) end
  5. end
  6.  
  7. local function randomString(length)
  8.     if not length or length <= 0 then return '' end
  9.     math.randomseed(os.clock()^5)
  10.     return randomString(length - 1) .. charset[math.random(1, #charset)]
  11. end
  12.  
  13. write("Ready to receive disk...")
  14.  
  15. while true do
  16.     turtle.suck()
  17.     item = turtle.getItemDetail(1)
  18.  
  19.     if not item or item.name ~= "computercraft:disk" then
  20.         turtle.drop()
  21.     else
  22.         turtle.dropDown()
  23.        
  24.         write("\nEnter Owner's Name: ")
  25.         owner = read()
  26.  
  27.         diskId = disk.getID("bottom")
  28.         diskKey = randomString(5)
  29.  
  30.         slotId = 0
  31.         file = fs.open("slot/index", "r")
  32.  
  33.         if file then
  34.             slotId = file.read()
  35.             file.close()
  36.         end
  37.         file = fs.open("slot/index", "w")
  38.         file.write(slotId + 1)
  39.         file.close()
  40.                    
  41.         --Write Key to Floppy
  42.         file = fs.open("disk/keycard", "w")
  43.         file.write(diskKey)
  44.         file.close()
  45.         file = fs.open("disk/slot", "w")
  46.         file.write(slotId)
  47.         file.close()
  48.  
  49.         --Write Key to Server
  50.         file = fs.open("slot/"..slotId, "w")
  51.         file.write(diskKey)
  52.            
  53.         disk.setLabel("bottom", owner.."'s Slot Key")
  54.         write("Key Created, DiskID: "..diskId)
  55.         disk.eject("bottom")
  56.  
  57.         os.sleep(5)
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement