Guest User

liquidServer

a guest
May 18th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --liquidServer v 0.1
  2.  
  3. rednet.open("left")
  4.  
  5. -- functions
  6.  
  7. local function receive()
  8.   local id, msg = rednet.receive()
  9.   local data = textutils.unserialize(msg)
  10.   local cmd = data[1]
  11.   term.clear()
  12.   term.setCursorPos(1,1)
  13.   print(id..": "..cmd)
  14. end
  15.  
  16. local function readFunc(liquid)
  17.   local file = fs.open("fluids/"..liquid, "r")
  18.   local lCount = tonumber(file.readAll())
  19.   file.close()
  20. end
  21.  
  22. local function writeFunc(liquid, lCount)
  23.   local file = fs.open("fluids/"..liquid, "w")
  24.   file.write(lCount)
  25.   file.close()
  26. end
  27.  
  28. --system code
  29.  
  30. while true do
  31.   local file = fs.open("server/id", "r")
  32.   local hId = tonumber(file.readAll())
  33.   file.close()
  34.   print(hId)
  35.   local file = fs.open("liquids/lava", "r")
  36.   local lava = file.readAll()
  37.   file.close()
  38.   local file = fs.open("liquids/water", "r")
  39.   local water = file.readAll()
  40.   file.close()
  41.   local file = fs.open("liquids/oil", "r")
  42.   local oil = file.readAll()
  43.   file.close()
  44.   receive()
  45.   if cmd == "lava" then
  46.     readFunc("lava")
  47.     lCount = lCount +1
  48.     writeFunc("lava", lCount)
  49.     if lCount == 2 then
  50.       rednet.send(hId, msg)
  51.       receive()
  52.       if cmd == "confirm" then
  53.         lCount = 0
  54.         writeFunc("lava", lCount)
  55.       end
  56.     end
  57.   elseif cmd == "water" then
  58.     readFunc("water")
  59.     lCount = lCount + 1
  60.     writeFunc("water", lCount)
  61.     if lCount == 20 then
  62.       rednet.send(hId, msg)
  63.       receive()
  64.       if cmd == "confirm" then
  65.         lCount = 0
  66.         writeFunc("water", lCount)
  67.       end
  68.     end
  69.   elseif cmd == "oil" then
  70.     readFunc("oil")
  71.     lCount = lCount +1
  72.     writeFunc("oil", lCount)
  73.     if lCount == 2 then
  74.       rednet.send(hId, msg)
  75.       receive()
  76.       if cmd == "confirm" then
  77.         lCount = 0
  78.         writeFunc("oil", lCount)
  79.       end
  80.     end
  81.   elseif cmd == "declined" then
  82.     rs.setOutput("right", true)
  83.     cmd = read()
  84.     if cmd == "pay" then
  85.       rednet.send(hId, msg)
  86.       receive()
  87.       if cmd == "confirm" then
  88.         rs.setOutput("right", false)
  89.       end
  90.     end
  91.   end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment