Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local diskDriveSide = "left"
- function RandomString()
- length = 16
- if length < 1 then return nil end
- local array = {}
- for i=1, length do
- array[i] = string.char(math.random(32,126))
- end
- return table.concat(array)
- end
- function compare()
- local disk_f = io.open("disk/pw.txt", "r")
- if disk_f == nil then
- term.setCursorPos(1,4)
- print("File or code does not exist.")
- sleep(3)
- else
- local disk_pw = disk_f:read("*l")
- disk_f:close()
- local lastID_f = io.open("lastid.txt", "r")
- local lastID = lastID_f:read("*l")
- lastID_f:close()
- while true do
- term.setCursorPos(1,4)
- print("Checking..")
- sleep(0.3)
- for fileNumber = 1, lastID do
- print("Checking : "..fileNumber..".txt")
- local check_f = io.open(fileNumber..".txt","r")
- local line = check_f:read("*l")
- sleep(0.1)
- if line == disk_pw then
- local nick = check_f:read("*l")
- print("Username: " ..nick)
- print("Press any key to exit")
- os.pullEvent()
- return
- end
- end
- print("Invalid, press any key to exit.")
- os.pullEvent()
- return
- end
- end
- function newID()
- local genCode = RandomString()
- if disk.isPresent(diskDriveSide) == false then
- term.setCursorPos(1,4)
- print("Insert Disk!")
- sleep(3)
- else
- term.setCursorPos(1,4)
- term.write("Please type in the player name : ")
- local playerName = read()
- disk.setLabel(diskDriveSide, "SPCard - " ..playerName)
- local disk_pw = io.open("disk/pw.txt", "w")
- disk_pw:write(genCode)
- disk_pw:close()
- local root_lastID = io.open("lastid.txt","r")
- local lastID = root_lastID:read("*l")
- root_lastID:close()
- root_lastID = io.open("lastid.txt","w")
- newID = lastID+1
- root_lastID:write(newID)
- root_lastID:close()
- local root_newID = io.open(newID..".txt","w")
- root_newID:write(genCode)
- root_newID:write("\n")
- root_newID:write(playerName)
- root_newID:close()
- term.setCursorPos(1,6)
- print("Generated!")
- sleep(2)
- end
- end
- end
- function mainMenu()
- term.clear()
- term.setCursorPos(1,1)
- print("1. Verify")
- print("2. Make New ID Card")
- local event, key = os.pullEvent("char")
- if key == "1" then
- if disk.isPresent(diskDriveSide) == false then
- term.setCursorPos(1,4)
- print("Insert Disk!")
- sleep(3)
- else
- compare()
- end
- elseif key == "2" then
- newID()
- else
- sleep(0.1)
- end
- end
- while true do
- mainMenu()
- end
Advertisement
Add Comment
Please, Sign In to add comment