Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- shell.run("clear")
- function cPrint(str, ypos)
- w, h = term.getSize()
- for i=1,w-1 do
- write("-")
- end
- term.setCursorPos(w/2-#str/2, ypos)
- write(str)
- end
- cPrint("ComputerCraft Virtual Bank", 1)
- 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 tWords[5] 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 or 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
- else
- print("Junk received from " ..id)
- end
- elseif tWords[1] == "NEW" then --NEW:<UR NAME>:<UR PASS>
- if tWords[3] then
- 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
- else
- print("Junk received from " ..id)
- end
- elseif tWords[1] == "VERIFY" then
- if tWords[3] then
- if fs.exists("Accounts/" ..tWords[2]) then
- a = fs.open("Accounts/" ..tWords[2], "r")
- Password = a.readLine()
- a.close()
- if Password == tWords[3] then
- rednet.send(id, "Correct")
- print(id.. " logged in.")
- else
- rednet.send(id, "Wrong")
- print("Failed #2 (" ..Password.. ")")
- end
- else
- rednet.send(id, "Wrong")
- print("Failed #1")
- end
- else
- print("Junk received from " ..id)
- end
- elseif tWords[1] == "CHECK" then --CHECK:<UR NAME> will send you the balance of <UR NAME>
- if tWords[2] then
- test = fs.open("Accounts/" ..tWords[2], "r")
- if test then
- test.readLine()
- rednet.send(id, test.readLine())
- test.close()
- print("Checked!")
- else
- rednet.send(id, "Unknown Username/Pass")
- end
- else
- print("Junk received from " ..id)
- end
- else
- print("Junk received from " ..id)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment