client
term.clear()
term.setCursorPos(1,1)
rednet.open("left")
local successfullogin = false
print("welcome to the bank")
print("1] login")
print("2] create new account")
print("3] shutdown")
write(">")
local firstoption = read()
if firstoption == "1" then
rednet.send(51,"login", true)
write("account number: ")
local accountnumb = read()
write("pin: ")
local pinnumb = read("*")
rednet.send(51, accountnumb, true)
local senderId, message, distance = rednet.receive(5)
print(message)
senderId, message, distance = rednet.receive()
if pinnumb == message then
successfullogin=true
end
elseif firstoption == "2" then
rednet.send(51, "create new account", true)
write("Enter a 4 digit pin for your account: ")
local pin = read("*")
rednet.send(51,pin, true)
localaccountsenderId, accountnumber, accountdistance = rednet.receive()
write("Your account number is: "..accountnumber)
sleep(2)
elseif firstoption == "3" then
print("shutting down...")
sleep(1)
os.shutdown()
else
print("unsuccessful login")
sleep(1)
end
function menu()
print("1) withdraw")
print("2) deposit")
print("3) wire tranfer")
print("4) balance inquiry")
print("5) logoff")
write("Enter a number: ")
local option = read()
if option == "1" then
print("Enter go back to go back to the menu")
write("How much? ")
local amount = read()
if amount == "go back" then
menu()
else
rednet.send(51, "withdraw", true)
rednet.send(51, amount, true)
print("withdrawing funds...")
print("gold will be in withdraw area")
sleep(1)
menu()
end
elseif option == "2" then
write("Do you want to deposit? y/n")
local deposit = read()
if deposit == "y" then
rednet.send(51,"deposit", true)
else
menu()
end
elseif option =="3" then
--wire transfer code
elseif option == "4" then
rednet.send(51, "balance", true)
local senderidbalance, balancemessage, distancebalance = rednet.receive()
print(balancemessage)
elseif option == "5" then
shell.run("startup")
else
print("That isn't a selection")
sleep(1)
end
sleep(2)
menu()
end
if successfulogin == true then
rednet.send(51, "validuser", true)
menu()
else
term.clear()
term.setCursorPos(1,1)
shell.run("startup")
end
server
print("This is the account server")
print("If you need to add an account then please do so through the admin computer in the server rooom")
print("Do not restart ever")
print("If you restart then all of the accounts and pins will be lost")
local pins = ""
local accounts= ""
local accountsId = ""
local realaccount = false
local accountaccess = false
rednet.open("top")
local account = {566001,566002,566003,566004}
local accountId = {46,52,53,54}
local pin = {}
local accountbalance = {0,0,0,0}
function accountlogin() -- sets it so you can acces account functions
local senderId, message, distance = rednet.receive()
if message == "login" then
senderId, message, distance = rednet.receive()
for i,v in ipairs(account) do
if message == v then
accountnumb = message
realaccount = true
rednet.send(senderId, "accessing your account...", true)
pins = (pin[i])
accountsId = (accountID[i])
rednet.send(senderId, pins, true)
else
rednet.send(senderId, "That account doesnt exist", true)
end
break
end
senderId, message, distance = rednet.receive()
if message == "validuser" then
accountaccess = true
end
elseif message == "withdraw" then
senderId, message, distance = rednet.receive()
rednet.send(accountsId, message, true)
elseif message== "deposit" then
senderId, message, distance = rednet.receive()
rednet.send(accountsId, message, true)
elseif message == "create new account" then
senderId, message, distance = rednet.receive()
table.insert(pin, message)
for i,v in ipairs(pin) do
if message == v then
local newaccount = (account[i])
rednet.send(senderId, newaccount, true)
end
end
elseif message == "wire transfer" then
--wire transfer code
else
end
end
while true do
accountlogin()
end