Terraxel

Computercraft AE2 Monitoring server

Jul 20th, 2022 (edited)
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. protocol = 'ae2_monitoring'
  2. hostname = 'server.ae2_mon.txl'
  3. routerSide = 'top'
  4. ae2Side = 'left'
  5.  
  6. function handleMessage(message)
  7.     if message.request == nil then
  8.         return nil
  9.     end
  10.    
  11.     if message.request == 'stock' then
  12.         return handleStockMessage(message)
  13.     end
  14. end
  15.  
  16. function handleStockMessage(message)
  17.     if message.requestedItem == nil then
  18.         return nil
  19.     end
  20.  
  21.     print("Stock request for ".. message.requestedItem)
  22.  
  23.     local search = ae2.findItem(message.requestedItem)
  24.  
  25.     if search == nil then
  26.         return {name=message.requestedItem, count=0}
  27.     end
  28.  
  29.     local itemData = search.getMetadata()
  30.     return {name=itemData.displayName, count=itemData.count}
  31. end
  32.  
  33. rednet.open(routerSide)
  34. rednet.host(protocol, hostname)
  35.  
  36. ae2 = peripheral.wrap(ae2Side)
  37.  
  38. while true do
  39.     senderId, message, usedProtocol = rednet.receive(protocol)
  40.     response = handleMessage(message)
  41.     rednet.send(senderId, response, protocol)
  42. end
  43.  
  44.  
Add Comment
Please, Sign In to add comment