Advertisement
Wyvern67

Untitled

Jul 8th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. rednet.open("top")
  2. local accounts = {}
  3. 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}
  4. local id = 0
  5. local msg = ""
  6. local grant = false
  7. local pos1 = 0
  8. local pos2 = 0
  9. local act = ""
  10. local target = ""
  11. local amount = 0
  12. local price = {}
  13.  
  14. function readAccount()
  15.     local file = fs.open("accounts","r")
  16.     local line = ""
  17.     local name = ""
  18.     local money = 0
  19.     local pos = 0
  20.     line = file.readLine()
  21.     repeat
  22.         pos = string.find(line,":")
  23.         name = string.sub(line,1,pos-1)
  24.         money = string.sub(line,pos+1)
  25.         accounts[name] = money
  26.         line = file.readLine()
  27.     until not line
  28.     file.close()
  29. end
  30.  
  31. function readPrice()
  32.     local file = fs.open("prix","r")
  33.     local line = ""
  34.     local uuid = 0
  35.     local prix = 0
  36.     local pos = 0
  37.     line = file.readLine()
  38.     repeat
  39.         pos = string.find(line,":")
  40.         uuid = string.sub(line,1,pos-1)
  41.         prix = string.sub(line,pos+1)
  42.         price[uuid] = prix
  43.         line = file.readLine()
  44.     until not line
  45.     file.close()
  46. end
  47.  
  48. function saveAccount()
  49.     local file = fs.open("accounts","w")
  50.     for name,money in pairs(accounts) do
  51.         file.writeLine(name..":"..money)
  52.     end
  53.     file.close()
  54. end
  55.  
  56. function addPrice(uuid,price)
  57.     local file = fs.open("prix", "w")
  58.     file.writeLine(uuid..":"..price)
  59. end
  60.  
  61. readAccount()
  62. readPrice()
  63. while true do
  64.     id, msg = rednet.receive()
  65.     grant = false
  66.     for i = 1,#authorized do
  67.         if(authorized[i] == id) then grant = true end
  68.     end
  69.     if grant then
  70.         pos1 = string.find(msg,":")
  71.         pos2 = string.find(msg,";")
  72.         act = string.sub(msg,1,pos1-1)
  73.         target = string.sub(msg,pos1+1,pos2-1)
  74.         amount = tonumber(string.sub(msg,pos2+1))
  75.         if act == "dep" then
  76.             if not accounts[target] then
  77.                 accounts[target] = 0
  78.             end
  79.             accounts[target] = accounts[target] + amount
  80.             rednet.send(id,"confirmed")
  81.         elseif act == "deb" then
  82.             if not accounts[target] then
  83.             accounts[target] = 0
  84.             end
  85.             if tonumber(accounts[target]) < amount then rednet.send(id,"low")
  86.             else
  87.                 accounts[target] = accounts[target] - amount
  88.                 rednet.send(id,"confirmed")
  89.             end
  90.         elseif act == "req" then
  91.             rednet.send(id,tostring(accounts[target]))
  92.         elseif act == "price" then
  93.             rednet.send(id,tostring(price[target]))
  94.         elseif act == "run" then
  95.             shell.run(target)
  96.         elseif act == "pget" then
  97.             shell.run("pastebin", "get", target, amount)
  98.         end
  99.         saveAccount()
  100.         term.clear()
  101.         term.setCursorPos(1,1)
  102.         for name,money in pairs(accounts) do
  103.             print(name.." : "..money)
  104.         end
  105.     end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement