Guest User

vs

a guest
Jul 2nd, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. local diskDriveSide = "left"
  2.  
  3. function RandomString()
  4.   length = 16
  5.   if length < 1 then return nil end
  6.   local array = {}
  7.   for i=1, length do
  8.     array[i] = string.char(math.random(32,126))
  9.  end
  10.   return table.concat(array)
  11. end
  12.  
  13. function compare()
  14.   local disk_f = io.open("disk/pw.txt", "r")
  15.   if disk_f == nil then
  16.     term.setCursorPos(1,4)
  17.     print("File or code does not exist.")
  18.     sleep(3)
  19.    else
  20.   local disk_pw = disk_f:read("*l")
  21.   disk_f:close()
  22.   local lastID_f = io.open("lastid.txt", "r")
  23.   local lastID = lastID_f:read("*l")
  24.   lastID_f:close()
  25.   while true do
  26.   term.setCursorPos(1,4)
  27.   print("Checking..")
  28.   sleep(0.3)
  29.     for fileNumber = 1, lastID do
  30.       print("Checking : "..fileNumber..".txt")
  31.       local check_f = io.open(fileNumber..".txt","r")
  32.       local line = check_f:read("*l")
  33.       sleep(0.1)
  34.     if line == disk_pw then
  35.       local nick = check_f:read("*l")
  36.       print("Username: " ..nick)
  37.       print("Press any key to exit")
  38.       os.pullEvent()
  39.       return
  40.     end
  41.     end
  42.     print("Invalid, press any key to exit.")
  43.     os.pullEvent()
  44.     return
  45. end
  46. end
  47.  
  48. function newID()
  49.   local genCode = RandomString()
  50.   if disk.isPresent(diskDriveSide) == false then
  51.     term.setCursorPos(1,4)
  52.     print("Insert Disk!")
  53.     sleep(3)
  54.    else
  55.     term.setCursorPos(1,4)
  56.     term.write("Please type in the player name : ")
  57.     local playerName = read()
  58.     disk.setLabel(diskDriveSide, "SPCard - " ..playerName)
  59.     local disk_pw = io.open("disk/pw.txt", "w")
  60.     disk_pw:write(genCode)
  61.     disk_pw:close()
  62.     local root_lastID = io.open("lastid.txt","r")
  63.     local lastID = root_lastID:read("*l")
  64.     root_lastID:close()
  65.     root_lastID = io.open("lastid.txt","w")
  66.     newID = lastID+1
  67.     root_lastID:write(newID)
  68.     root_lastID:close()
  69.     local root_newID = io.open(newID..".txt","w")
  70.     root_newID:write(genCode)
  71.     root_newID:write("\n")
  72.     root_newID:write(playerName)
  73.     root_newID:close()
  74.     term.setCursorPos(1,6)
  75.     print("Generated!")
  76.     sleep(2)
  77.   end
  78.   end
  79. end
  80.  
  81. function mainMenu()
  82.   term.clear()
  83.   term.setCursorPos(1,1)
  84.   print("1. Verify")
  85.   print("2. Make New ID Card")
  86.   local event, key = os.pullEvent("char")
  87.   if key == "1" then
  88.      if disk.isPresent(diskDriveSide) == false then
  89.         term.setCursorPos(1,4)
  90.         print("Insert Disk!")
  91.         sleep(3)
  92.       else
  93.        compare()
  94.      end
  95.    elseif key == "2" then
  96.      newID()
  97.    else
  98.      sleep(0.1)
  99.  end
  100. end
  101.  
  102. while true do
  103.   mainMenu()
  104. end
Advertisement
Add Comment
Please, Sign In to add comment