Advertisement
johnnic431

FevServ

Jun 22nd, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. canRun=false
  2. local modem=peripheral.find("modem")
  3. if modem~=nil and modem.isWireless() then
  4.     canRun=true
  5.     modem.open(662)
  6. else
  7.     print("No wireledd modem")
  8.     return;
  9. end
  10.  
  11. if not fs.exists("moneys") then
  12.     people={["Sylvyrfysh"]=1000,["Iban1223"]=1000,["milianlou"]=1000,["alion8me"]=1000}
  13.     _file=fs.open("moneys","w")
  14.     _file.write(textutils.serialize(people));
  15.     _file.flush()
  16.     _file.close()
  17. else
  18.     _file=fs.open("moneys","r")
  19.     people=textutils.unserialize(_file.readAll())
  20.     _file.close()
  21. end
  22.  
  23. pins={["Sylvyrfysh"]=5820,["Iban1223"]=3221,["milianlou"]=0107,["alion8me"]=1235,["jediboy2"]=9471}
  24.  
  25. while canRun do
  26.     ok,_err=pcall(function()
  27.         e={os.pullEvent()}
  28.         if e[1]=="key" and e[2]==keys.q then
  29.             _file=fs.open("moneys","w")
  30.             _file.write(textutils.serialize(people));
  31.             _file.flush()
  32.             _file.close()
  33.             return
  34.         elseif e[1]=="modem_message" then
  35.             msg=textutils.unserialize(e[5])
  36.             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
  37.                 modem.transmit(8816,1,"USER_OR_PIN_INCORRECT")
  38.             else
  39.                 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
  40.                     people[msg.from]=people[msg.from]-tonumber(msg.amount)
  41.                     people[msg.to]=people[msg.to]+tonumber(msg.amount)
  42.                     modem.transmit(8816,1,"GOOD_PURCHASE")
  43.                     print("Good transfer from "..msg.from.." to "..msg.to)
  44.                     _file=fs.open("moneys","w")
  45.                     _file.write(textutils.serialize(people));
  46.                     _file.flush()
  47.                     _file.close()
  48.                 else
  49.                     print("error in purchase")
  50.                     pcall(function()
  51.                         print(msg.pin)
  52.                     end)
  53.                     pcall(function()
  54.                         print(msg.from)
  55.                     end)
  56.                     pcall(function()
  57.                         print(pins[msg.from])
  58.                     end)
  59.                     pcall(function()
  60.                         print(msg.amount)
  61.                     end)
  62.                     pcall(function()
  63.                         print(people[msg.from]-tonumber(msg.amount))
  64.                     end)
  65.                     modem.transmit(8816,1,"BAD_PURCHASE")
  66.                 end
  67.             end
  68.         end
  69.     end)
  70.     if not ok then
  71.         _file=fs.open("errors","a")
  72.         _file.write(_err.."\n");
  73.         _file.flush()
  74.         _file.close()
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement