Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- local accounts = {}
- local authorized = {3598,3593,3563,3410,3414,3415,3541,3532,3533,3534,3535,3536,3537,3538,3678,3539,3540,3541,3542,3543,3544,3545,3546,3547,3548,3549,3550,3526,3527}
- local id = 0
- local msg = ""
- local grant = false
- local pos1 = 0
- local pos2 = 0
- local act = ""
- local target = ""
- local amount = 0
- local price = {}
- function readAccount()
- local file = fs.open("accounts","r")
- local line = ""
- local name = ""
- local money = 0
- local pos = 0
- line = file.readLine()
- repeat
- pos = string.find(line,":")
- name = string.sub(line,1,pos-1)
- money = string.sub(line,pos+1)
- accounts[name] = money
- line = file.readLine()
- until not line
- file.close()
- end
- function readPrice()
- local file = fs.open("prix","r")
- local line = ""
- local uuid = 0
- local prix = 0
- local pos = 0
- line = file.readLine()
- repeat
- pos = string.find(line,":")
- uuid = string.sub(line,1,pos-1)
- prix = string.sub(line,pos+1)
- price[uuid] = prix
- line = file.readLine()
- until not line
- file.close()
- end
- function saveAccount()
- local file = fs.open("accounts","w")
- for name,money in pairs(accounts) do
- file.writeLine(name..":"..money)
- end
- file.close()
- end
- function addPrice(uuid,price)
- local file = fs.open("prix", "w")
- file.writeLine(uuid..":"..price)
- end
- readAccount()
- readPrice()
- while true do
- id, msg = rednet.receive()
- grant = false
- for i = 1,#authorized do
- if(authorized[i] == id) then grant = true end
- end
- if grant then
- pos1 = string.find(msg,":")
- pos2 = string.find(msg,";")
- act = string.sub(msg,1,pos1-1)
- target = string.sub(msg,pos1+1,pos2-1)
- amount = tonumber(string.sub(msg,pos2+1))
- if act == "dep" then
- if not accounts[target] then
- accounts[target] = 0
- end
- accounts[target] = accounts[target] + amount
- rednet.send(id,"confirmed")
- elseif act == "deb" then
- if not accounts[target] then
- accounts[target] = 0
- end
- if tonumber(accounts[target]) < amount then rednet.send(id,"low")
- else
- accounts[target] = accounts[target] - amount
- rednet.send(id,"confirmed")
- end
- elseif act == "req" then
- rednet.send(id,tostring(accounts[target]))
- elseif act == "price" then
- rednet.send(id,tostring(price[target]))
- elseif act == "run" then
- shell.run(target)
- elseif act == "pget" then
- shell.run("pastebin", "get", target, amount)
- end
- saveAccount()
- term.clear()
- term.setCursorPos(1,1)
- for name,money in pairs(accounts) do
- print(name.." : "..money)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement