xXm0dzXx

Test

Jul 13th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. rednet.open("top")
  2. shell.run("clear")
  3. print("ComputerCraft Virtual Bank")
  4. fs.makeDir("Accounts")
  5.  
  6. while true do
  7.     id, message = rednet.receive()
  8.    
  9.     local tWords = {}
  10.     for match in string.gmatch(message, "[^:\t]+") do
  11.         table.insert( tWords, match )
  12.     end
  13.    
  14.     --Format:
  15.     --GIVE:<YOUR NAME>:<YOUR PASS>:<HOW MUCH U WANNA GIVE TO...>:<YOUR FRIEND>
  16.     if tWords[1] == "GIVE" then
  17.         if fs.exists("Accounts/" ..tWords[2]) then
  18.             a = fs.open("Accounts/" ..tWords[2], "r")
  19.             --File Format:
  20.             --<Pass>
  21.             --<Your money>
  22.             Password = a.readLine()
  23.             YourCurrent = tonumber(a.readLine())
  24.             YourPay = tonumber(tWords[4])
  25.             a.close()
  26.            
  27.             if tWords[3] == Password and fs.exists("Accounts/" ..tWords[5]) then
  28.                 if YourCurrent > YourPay pr YourCurrent == YourPay then
  29.                     test = fs.open("Accounts/" ..tWords[5], "r")
  30.                     TheirPass = test.readLine()
  31.                     TheirCurrency = tonumber(test.readLine())
  32.                     test.close()
  33.                    
  34.                     fs.delete("Accounts/" ..tWords[5])
  35.                    
  36.                     test = fs.open("Accounts/" ..tWords[5], "w")
  37.                     test.writeLine(TheirPass)
  38.                     test.writeLine(TheirCurrency + YourPay)
  39.                     YourCurrent = YourCurrent - YourPay
  40.                     test.close()
  41.                    
  42.                     print(tWords[2].. " gave " ..tWords[5].. " $" ..YourPay)
  43.                 else
  44.                     print("Insignificant funds")
  45.                 end
  46.             else
  47.                 print("Payment failed. " ..id)
  48.             end
  49.         else
  50.             print("Payment failed. " ..id)
  51.         end
  52.     elseif tWords[1] == "NEW" then --NEW:<UR NAME>:<UR PASS>
  53.         if fs.exists("Accounts/" ..tWords[2]) then
  54.             print("Register failed. " ..id)
  55.         else
  56.             test = fs.open("Accounts/" ..tWords[2], "w")
  57.             if test then
  58.                 test.writeLine(tWords[3])
  59.                 test.writeLine("0") --0 dollars
  60.                 test.close()
  61.             else
  62.                 print("Register failed... :C")
  63.             end
  64.            
  65.             print("Register complete!")
  66.         end
  67.     elseif tWords[1] == "CHECK" then
  68.         test = fs.open("Accounts/" ..tWords[2], "r")
  69.         test.readLine()
  70.         rednet.send(id, test.readLine())
  71.         test.close()
  72.     else
  73.         print("Junk received from " ..id)
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment