Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OpenAll()
- for _,side in ipairs(rs.getSides()) do
- rednet.open(side)
- end
- end
- function split(str, pat)
- local t = { }
- local fpat = "(.-)"..pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function runServer()
- OpenAll()
- id, msg, d = rednet.receive()
- rmsg = split(msg, "!SP!")
- id2 = rmsg[1]
- cmd = rmsg[2]
- if cmd == "Activate" then
- fs.makeDir(id2)
- make = fs.open(id2.."/funds", "w")
- make.write("100")
- make.close()
- elseif cmd == "Transaction" then
- usr2 = rmsg[3]
- transaction = rmsg[4]
- usrmoney = fs.open(id2.."/funds", "r")
- money = usrmoney.readAll()
- usrmoney.close()
- usr2money = fs.open(usr2.."/funds", "r")
- money2 = usr2money.readAll()
- usr2money.close()
- money = money - transaction
- money2 = money2 + transaction
- nmoney = fs.open(id2.."/funds", "w")
- nmoney.write(money)
- nmoney.close()
- nmoney2 = fs.open(usr2.."/funds", "w")
- nmoney2.write(money2)
- nmoney2.close()
- elseif cmd == "ATM" then
- usrmoney = fs.open(id2.."/funds", "r")
- money = usrmoney.readAll()
- usrmoney.close()
- rednet.send(id, money)
- end
- runServer()
- end
- runServer()
Add Comment
Please, Sign In to add comment