Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- shell.run("clear")
- print("ComputerCraft Virtual Bank")
- fs.makeDir("Accounts")
- while true do
- id, message = rednet.receive()
- local tWords = {}
- for match in string.gmatch(message, "[^:\t]+") do
- table.insert( tWords, match )
- end
- --Format:
- --GIVE:<YOUR NAME>:<YOUR PASS>:<HOW MUCH U WANNA GIVE TO...>:<YOUR FRIEND>
- if tWords[1] == "GIVE" then
- if fs.exists("Accounts/" ..tWords[2]) then
- a = fs.open("Accounts/" ..tWords[2], "r")
- --File Format:
- --<Pass>
- --<Your money>
- Password = a.readLine()
- YourCurrent = tonumber(a.readLine())
- YourPay = tonumber(tWords[4])
- a.close()
- if tWords[3] == Password and fs.exists("Accounts/" ..tWords[5]) then
- if YourCurrent > YourPay pr YourCurrent == YourPay then
- test = fs.open("Accounts/" ..tWords[5], "r")
- TheirPass = test.readLine()
- TheirCurrency = tonumber(test.readLine())
- test.close()
- fs.delete("Accounts/" ..tWords[5])
- test = fs.open("Accounts/" ..tWords[5], "w")
- test.writeLine(TheirPass)
- test.writeLine(TheirCurrency + YourPay)
- YourCurrent = YourCurrent - YourPay
- test.close()
- print(tWords[2].. " gave " ..tWords[5].. " $" ..YourPay)
- else
- print("Insignificant funds")
- end
- else
- print("Payment failed. " ..id)
- end
- else
- print("Payment failed. " ..id)
- end
- elseif tWords[1] == "NEW" then --NEW:<UR NAME>:<UR PASS>
- if fs.exists("Accounts/" ..tWords[2]) then
- print("Register failed. " ..id)
- else
- test = fs.open("Accounts/" ..tWords[2], "w")
- if test then
- test.writeLine(tWords[3])
- test.writeLine("0") --0 dollars
- test.close()
- else
- print("Register failed... :C")
- end
- print("Register complete!")
- end
- elseif tWords[1] == "CHECK" then
- test = fs.open("Accounts/" ..tWords[2], "r")
- test.readLine()
- rednet.send(id, test.readLine())
- test.close()
- else
- print("Junk received from " ..id)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment