Advertisement
incinirate

Security

Nov 16th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. rednet.open("back")
  4. sfile = fs.open("sfile","a")
  5. rfile = fs.open("sfile","r")
  6.  
  7. bmh = 10
  8.  
  9. --Format = amt,serial
  10. if rfile.readLine() == nil then
  11.   sfile.writeLine("0")
  12.   ser = "0"
  13. end
  14.  
  15. function incrementSerial()
  16.   ser = ser + 1
  17. end
  18.  
  19. function checkMoney(account)
  20.   rednet.send(bmh,"check")
  21.   rednet.send(bmh,account)
  22.   id,msg = rednet.receive()
  23.   if id == bmh then
  24.     return tonumber(msg)
  25.   end
  26. end
  27.  
  28. function checkornil(str,sera)
  29.   if str==nil then
  30.   return true
  31.   fail=true
  32.   end
  33.   if str==sera then return true end
  34.   return false
  35. end
  36.  
  37. function checkSecurity(amt,serc,acc)
  38.   rfile.close()
  39.   rfile = fs.open("sfile","r")
  40.   repeat
  41.   until checkornil(rfile.readLine(),amt..","..serc)
  42.   if fail == true then
  43.     fail = false
  44.     return false
  45.   end
  46.   if checkMoney(acc) > amt then
  47.   return true
  48.   else
  49.   return false
  50.   end
  51. end
  52.  
  53. function createNote(amt)
  54.   incrementSerial()
  55.   sfile.writeLine(amt..","..ser)
  56.   return ser
  57. end
  58.  
  59. if tArgs[1] == "cn" then
  60.   createNote(tArgs[2])
  61. elseif tArgs[1] == "cs" then
  62.   checkSecurity(tArgs[2],tArgs[3],tArgs[4])
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement