Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chans = {
- atm = 1,
- db = 2,
- }
- local common = dofile("/disk/common")
- local blake = dofile("/disk/blake")
- local modem = peripheral.find("modem")
- modem.open(chans.atm)
- local function sendCmd(...)
- modem.transmit(chans.db, chans.atm, {...})
- local resp = common.waitForMsg(chans.db, 2)
- if resp then
- if resp[1] then
- return resp
- else
- printError(resp[2])
- end
- else
- printError("Timed out")
- end
- return resp
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("1. Register\n2. Login\n3. Exit")
- write("> ")
- local mode = tonumber(read())
- term.clear()
- term.setCursorPos(1,1)
- if mode == 1 then
- print("Register an account")
- write("Username: ")
- local username = read()
- write("Password: ")
- local password = read("*")
- local salt = sendCmd("register", username)
- if salt and salt[1] then
- local hash = blake.digest(password, salt[2])
- sendCmd(true, hash)
- print("Account created!")
- end
- sleep(2)
- elseif mode == 2 then
- print("Log-in into your account")
- write("Username: ")
- local username = read()
- write("Password: ")
- local password = read("*")
- local salt = sendCmd("auth", username)
- if salt and salt[1] then
- local hash = blake.digest(password, salt[2])
- local resp = sendCmd(true, hash)
- if resp and resp[1] then
- while true do
- term.clear() term.setCursorPos(1,1)
- print("Logged in as "..username)
- print("1. Check Balance\n2. Transfer money\n3. Exit")
- write("> ")
- local mode = tonumber(read())
- if mode == 1 then
- local bal = sendCmd("balance", username, hash)
- if bal and bal[1] then
- print("Your current balance is "..bal[2])
- end
- elseif mode == 2 then
- write("Recipient: ")
- local recip = read()
- write("Amount: ")
- local amt = read()
- local newbal = sendCmd("transfer", username, hash, recip, amt)
- if newbal and newbal[1] then
- print(amt.." has been sent to "..recip)
- print("Your balance is now "..newbal[2])
- end
- elseif mode == 3 then print("Logged off") break
- end
- print("Press any key to continue")
- os.pullEvent("key")
- end
- end
- end
- sleep(2)
- elseif mode == 3 then break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement