Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"top","bottom","left","right","front","back"}
- for i = 1,6 do
- a = sides[i]
- if peripheral.getType(a) == "modem" then
- rednet.open(a)
- break
- end
- end
- while true do
- for i = 1,6 do
- a = sides[i]
- if peripheral.getType(a) == "drive" then
- dr = a
- drive = peripheral.wrap(a)
- break
- end
- end
- id,msg,protocol = rednet.receive()
- if protocol == "money" then
- if not fs.exists("disk/"..msg) then
- print("[CREATE] Created account "..msg.." with 0$")
- rednet.send(id,"new")
- file = fs.open("disk/"..msg,"w")
- file.write("0")
- file.close()
- else
- file = fs.open("disk/"..msg,"r")
- money = file.readAll()
- file.close()
- print(msg.." has "..money.."$")
- rednet.send(id,money)
- end
- else
- from = string.sub(msg,1,4)
- from = tonumber(from)+0
- money = string.sub(msg,5,string.len(msg))
- to = protocol
- file1 = fs.open("disk/"..from,"r")
- money1 = tonumber(file1.readAll())
- file1.close()
- if money1 >= tonumber(money) then
- file1 = fs.open("disk/"..from,"w")
- file1.write(money1-money)
- file1.close()
- print("[PAY] Taken from "..from.." "..money.."$")
- rednet.send(id,200)
- if fs.exists("money/"..to) then
- file2 = fs.open("money/"..to,"r")
- money2 = file2.readAll()
- file2.close()
- file2 = fs.open("money/"..to,"w")
- file2.write(money2+money)
- print("[PAY] Payed "..money.."$ to "..to)
- else
- file2 = fs.open("money/"..to,"w")
- file2.write(money)
- file2.close()
- print("[CREATE] Created account "..to.." with "..money.."$")
- print("[PAY] Payed "..money.."$ to "..to)
- end
- else
- print("[ERROR] "..from.."hasn't got enough money")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement