Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --the idea for this program is to receive a request for a transfer of a currency, then check account, send if it is possible, then complete the transfer, then send it has been completed
- --settings
- settings_ServerID = "ExBankServer_01"
- RouterSide = "SIDE"
- FOUNDACCOUNT = -1
- ClientID = 0
- TargetAccount = 0
- TransferAmount = 0
- --mainprogram
- start()
- function start()
- print("starting server")
- print("Network connection establishing")
- transfermanager()
- end
- function transfermanager()
- rednet.open(RouterSide)
- if rednet.isOpen(RouterSide) then
- print("server is now online")
- rednet.host(1, settings_ServerID)
- while true do
- local senderId, message, protocol = rednet.receive()
- if protocol = ServerID then
- findAccount(message)
- if FOUNDACCOUNT != -1 then
- print("account Found, now establishing transfer")
- rednet.send(senderId, "Account Found", 2)
- ClientID = senderId
- transferSetup()
- else
- rednet.send(senderId, "Account not found", 2)
- print("account not found on server")
- end
- end
- else
- print("failed to open router, will restart in 1 minute, if this was your first time starting the program, please check to see that the setting RouterSide is setup correctly")
- sleep(60)
- os.shutdown
- end
- end
- function findaccount(account)
- FOUNDACCOUNT = -1
- if fs.exists(account) then
- FOUNDACCOUNT = account
- end
- end
- function transfersetup()
- h = fs.open(FOUNDACCOUNT, "w")
- local AccountCredit = fs.readall()
- local senderId, message, protocol = rednet.receive()
- if senderId = ClientID then
- print("server ready for transfer")
- if message = "Details" then
- print("was requested Details instead of transfer, sending info now")
- rednet.send(ClientID,AccountCredit,2)
- os.shutdown
- else
- local senderId, message, protocol = rednet.receive()
- if senderId = ClientID then
- TargetAccount = message
- local senderId, message, protocol = rednet.receive()
- if senderId = ClientID then
- TransferAmount = message
- print("completed Download of requested Transfer, now executing transfer"
- fs.open(FOUNDACCOUNT, "w")
- if fs.readAll() >= TransferAmount then
- else
- print("Unable to continue with transaction due to insignificant funds")
- sleep(120)
- os.restart()
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement