This commit is contained in:
kepler155c
2018-10-24 19:12:03 -04:00
parent 55653aa494
commit 3687df3d36
11 changed files with 333 additions and 38 deletions

52
milo/plugins/remote.lua Normal file
View File

@@ -0,0 +1,52 @@
local Event = require('event')
local Milo = require('milo')
local Socket = require('socket')
local device = _G.device
local manipulator = device.manipulator_1
local turtle = _G.turtle
local context = Milo:getContext()
local function client(socket)
repeat
local data = socket:read()
if not data then
break
end
if data.request == 'list' then
local items = Milo:listItems()
Milo:mergeResources(items)
socket:write(items)
elseif data.request == 'transfer' then
context.inventoryAdapter:provide(
data.item,
data.count,
nil,
context.localName)
turtle.eachFilledSlot(function(slot)
manipulator.getInventory().pullItems(
context.localName,
slot.index,
slot.count)
end)
end
until not socket.connected
end
if device.wireless_modem then
Event.addRoutine(function()
debug('Milo: listening on port 4242')
while true do
local socket = Socket.server(4242)
debug('connection from ' .. socket.dhost)
Event.addRoutine(function()
client(socket)
end)
end
end)
end