Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables--
- local remoteUserAccount
- local remoteUserPIN
- local userAccount
- local userPIN
- local userBalance
- local remoteOtherAccount
- local otherPIN
- local otherBalance
- local remoteAmount
- local senderId
- local message
- local protocol
- --Setup Networking--
- rednet.open("back")
- --Basic Functions--
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --Bank Functions--
- local function SendMoney()
- --Gets Variables From Remote Terminal--
- senderId, message, protocol = rednet.receive("bankSend")
- remoteUserAccount = message
- rednet.send(senderId, "confirmed", "confirmation")
- senderId, message, protocol = rednet.receive("bankSend")
- remoteOtherAccount = message
- rednet.send(senderId, "confirmed", "confirmation")
- senderId, message, protocol = rednet.receive("bankSend")
- remoteAmount = message
- rednet.send(senderId, "confirmed", "confirmation")
- senderId, message, protocol = rednet.receive("bankSend")
- remoteUserPIN = message
- --Checks If User Accounts Exist And Have Enough Money--
- if fs.exists("accounts/" .. remoteUserAccount) then
- local UserFile = fs.open("accounts/" .. remoteUserAccount, "r")
- UserFile.readLine()
- userPIN = UserFile.readLine()
- if remoteUserPIN ~= userPIN then
- rednet.send(senderId, "Incorrect PIN", "bankStatus")
- os.reboot()
- end
- userBalance = UserFile.readLine()
- UserFile.close()
- if fs.exists("accounts/" .. remoteOtherAccount) then
- local OtherFile = fs.open("accounts/" .. remoteOtherAccount, "r")
- OtherFile.readLine()
- otherPIN = OtherFile.readLine()
- otherBalance = OtherFile.readLine()
- OtherFile.close()
- if tonumber(remoteAmount) <= tonumber(userBalance) then
- local UserFile = fs.open("accounts/" .. remoteUserAccount, "w")
- UserFile.writeLine(remoteUserAccount)
- UserFile.writeLine(remoteUserPIN)
- userBalance = tostring(tonumber(userBalance) - tonumber(remoteAmount))
- UserFile.writeLine(userBalance)
- UserFile.close()
- local OtherFile = fs.open("accounts/" .. remoteOtherAccount, "w")
- OtherFile.writeLine(remoteOtherAccount)
- OtherFile.writeLine(otherPIN)
- otherBalance = tostring(tonumber(otherBalance) + tonumber(remoteAmount))
- OtherFile.writeLine(otherBalance)
- OtherFile.close()
- local LogFile = fs.open("log", "a")
- LogFile.writeLine("Sending " .. remoteAmount .. " from " .. remoteUserAccount .. " to " .. remoteOtherAccount)
- rednet.send(senderId, "Transfer Complete", "bankStatus")
- os.reboot()
- else
- rednet.send(senderId, "Insuffcient Funds", "bankStatus")
- os.reboot()
- end
- else
- rednet.send(senderId, "Account Not Found", "bankStatus")
- os.reboot()
- end
- else
- rednet.send(senderId, "Account Not Found", "bankStatus")
- os.reboot()
- end
- end
- local function CheckBalance()
- --Gets Variables From Remote Terminal--
- senderId, message, protocol = rednet.receive("balanceCheck")
- remoteUserAccount = message
- rednet.send(senderId, "confirmed", "confirmation")
- senderId, message, protocol = rednet.receive("balanceCheck")
- remoteUserPIN = message
- --Validates PIN And Sends Balance--
- if fs.exists("accounts/" .. remoteUserAccount) then
- local UserFile = fs.open("accounts/" .. remoteUserAccount, "r")
- UserFile.readLine()
- userPIN = UserFile.readLine()
- if remoteUserPIN ~= userPIN then
- rednet.send(senderId, "Incorrect PIN", "bankStatus")
- os.reboot()
- end
- userBalance = UserFile.readLine()
- rednet.send(senderId, "confirmed", "bankStatus")
- rednet.send(senderId, userBalance, "bankCheck")
- os.reboot()
- else
- rednet.send(senderId, "Account Not Found", "bankStatus")
- os.reboot()
- end
- end
- --Main Code--
- --Imports New User Accounts--
- if disk.isPresent("bottom") then
- local rawDiskPath = textutils.serialize(fs.find("/disk/accounts/*"))
- local accountTransferDestination = string.sub(rawDiskPath, 11, string.find(rawDiskPath, ",") - 2)
- local accountTransferDisk = string.sub(rawDiskPath, 6, string.find(rawDiskPath, ",") - 2)
- fs.move(accountTransferDisk, accountTransferDestination)
- disk.eject("bottom")
- end
- senderId, message, protocol = rednet.receive("bankFunction")
- if message == "SendMoney" then
- rednet.send(senderId, "confirmed", "confirmation")
- SendMoney()
- elseif message == "CheckBalance" then
- rednet.send(senderId, "confirmed", "confirmation")
- CheckBalance()
- else
- rednet.send(senderId, "confirmed", "confirmation")
- os.reboot()
- end
Add Comment
Please, Sign In to add comment