Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Protocol = "4523"
- local Balance = 0
- rednet.open(peripherals.find("modem”))
- function Loop()
- rednet.host(Protocol,"Ser_B_1")
- while true do
- local Req = "Accepted"
- local a, b, c = rednet.receive(Protocol)
- local id, Acc, Key, Amount, Item = textutils.unserialize(b)
- local Result = FindAccount(Acc)
- if Result ~= false then
- if Amount > 40 and Key == "0000" then
- Req = "declined"
- else
- if Balance - Amount >= 0 then Req = "accepted" ChangeBalance(Result,Amount) end
- end
- else
- Req = "declined"
- end
- rednet.send(a,Req,Protocol)
- end
- end
- function ChangeBalance(account,Amount)
- local file = fs.open(account,"r")
- local Code = file.readLine()
- local Bal = file.readLine()
- file.close()
- local F = fs.open(account,"w")
- F.writeLine(Code)
- F.writeLine(Bal - Amount)
- F.close()
- end
- function FindAccount(Code)
- local Res = false
- local List = fs.list("accounts")
- for i = 1, #List do
- local File = fs.open(fs.combine("accounts",List[i]),"r")
- if File.readLine() == Code then Res = fs.combine("accounts",List[i]) Balance = File.readLine() end
- File.close()
- end
- return Res
- end
Add Comment
Please, Sign In to add comment