xXm0dzXx

Bank

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