Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- canRun=false
- local modem=peripheral.find("modem")
- if modem~=nil and modem.isWireless() then
- canRun=true
- modem.open(662)
- else
- print("No wireledd modem")
- return;
- end
- if not fs.exists("moneys") then
- people={["Sylvyrfysh"]=1000,["Iban1223"]=1000,["milianlou"]=1000,["alion8me"]=1000}
- _file=fs.open("moneys","w")
- _file.write(textutils.serialize(people));
- _file.flush()
- _file.close()
- else
- _file=fs.open("moneys","r")
- people=textutils.unserialize(_file.readAll())
- _file.close()
- end
- pins={["Sylvyrfysh"]=5820,["Iban1223"]=3221,["milianlou"]=0107,["alion8me"]=1235,["jediboy2"]=9471}
- while canRun do
- ok,_err=pcall(function()
- e={os.pullEvent()}
- if e[1]=="key" and e[2]==keys.q then
- _file=fs.open("moneys","w")
- _file.write(textutils.serialize(people));
- _file.flush()
- _file.close()
- return
- elseif e[1]=="modem_message" then
- msg=textutils.unserialize(e[5])
- if not msg.from or not msg.to or not tonumber(msg.pin) or not tonumber(msg.amount) or not pins[msg.from] or not pins[msg.to] then
- modem.transmit(8816,1,"USER_OR_PIN_INCORRECT")
- else
- if tonumber(msg.amount) and tonumber(msg.pin)==tonumber(pins[msg.from]) and (people[msg.from]-tonumber(msg.amount))>=0 and tonumber(msg.amount)>=0 then
- people[msg.from]=people[msg.from]-tonumber(msg.amount)
- people[msg.to]=people[msg.to]+tonumber(msg.amount)
- modem.transmit(8816,1,"GOOD_PURCHASE")
- print("Good transfer from "..msg.from.." to "..msg.to)
- _file=fs.open("moneys","w")
- _file.write(textutils.serialize(people));
- _file.flush()
- _file.close()
- else
- print("error in purchase")
- pcall(function()
- print(msg.pin)
- end)
- pcall(function()
- print(msg.from)
- end)
- pcall(function()
- print(pins[msg.from])
- end)
- pcall(function()
- print(msg.amount)
- end)
- pcall(function()
- print(people[msg.from]-tonumber(msg.amount))
- end)
- modem.transmit(8816,1,"BAD_PURCHASE")
- end
- end
- end
- end)
- if not ok then
- _file=fs.open("errors","a")
- _file.write(_err.."\n");
- _file.flush()
- _file.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement