mirror of
https://github.com/kepler155c/opus
synced 2025-01-23 05:36:53 +00:00
proxy apis over wireless
This commit is contained in:
parent
84b2b8ce63
commit
7fd93e8a8b
@ -24,6 +24,9 @@ function Routine:terminate()
|
||||
end
|
||||
|
||||
function Routine:resume(event, ...)
|
||||
if coroutine.status(self.co) == 'running' then
|
||||
return
|
||||
end
|
||||
|
||||
if not self.co then
|
||||
error('Cannot resume a dead routine')
|
||||
|
@ -148,7 +148,15 @@ end
|
||||
function Point.adjacentPoints(pt)
|
||||
local pts = { }
|
||||
|
||||
for _, hi in pairs(_G.turtle.getHeadings()) do
|
||||
local headings = {
|
||||
[ 0 ] = { xd = 1, zd = 0, yd = 0, heading = 0, direction = 'east' },
|
||||
[ 1 ] = { xd = 0, zd = 1, yd = 0, heading = 1, direction = 'south' },
|
||||
[ 2 ] = { xd = -1, zd = 0, yd = 0, heading = 2, direction = 'west' },
|
||||
[ 3 ] = { xd = 0, zd = -1, yd = 0, heading = 3, direction = 'north' },
|
||||
[ 4 ] = { xd = 0, zd = 0, yd = 1, heading = 4, direction = 'up' },
|
||||
[ 5 ] = { xd = 0, zd = 0, yd = -1, heading = 5, direction = 'down' }
|
||||
}
|
||||
for _, hi in pairs(headings) do
|
||||
table.insert(pts, { x = pt.x + hi.xd, y = pt.y + hi.yd, z = pt.z + hi.zd })
|
||||
end
|
||||
|
||||
|
@ -95,9 +95,8 @@ end
|
||||
if not fs.exists('usr/autorun') then
|
||||
fs.makeDir('usr/autorun')
|
||||
end
|
||||
if not fs.exists('usr/etc/fstab') or not fs.exists('usr/etc/fstab.ignore') then
|
||||
if not fs.exists('usr/etc/fstab') then
|
||||
Util.writeFile('usr/etc/fstab', 'usr gitfs kepler155c/opus-apps/develop')
|
||||
Util.writeFile('usr/etc/fstab.ignore', 'forced fstab overwrite')
|
||||
end
|
||||
if not fs.exists('usr/config/shell') then
|
||||
Util.writeTable('usr/config/shell', {
|
||||
|
@ -53,6 +53,7 @@ function turtle.resetState()
|
||||
state.moveCallback = noop
|
||||
Pathing.reset()
|
||||
|
||||
turtle.abort = false
|
||||
return true
|
||||
end
|
||||
|
||||
@ -60,7 +61,7 @@ function turtle.reset()
|
||||
turtle.point.x = 0
|
||||
turtle.point.y = 0
|
||||
turtle.point.z = 0
|
||||
turtle.point.heading = 0
|
||||
turtle.point.heading = 0 -- should be facing
|
||||
turtle.point.gps = false
|
||||
turtle.abort = false -- should be part of state
|
||||
--turtle.status = 'idle' -- should be part of state
|
||||
@ -961,10 +962,10 @@ function turtle.run(fn, ...)
|
||||
end
|
||||
|
||||
function turtle.abortAction()
|
||||
if turtle.status ~= 'idle' then
|
||||
--if turtle.status ~= 'idle' then
|
||||
turtle.abort = true
|
||||
os.queueEvent('turtle_abort')
|
||||
end
|
||||
--end
|
||||
end
|
||||
|
||||
-- [[ Pathing ]] --
|
||||
|
34
sys/network/proxy.lua
Normal file
34
sys/network/proxy.lua
Normal file
@ -0,0 +1,34 @@
|
||||
local Event = require('event')
|
||||
local Socket = require('socket')
|
||||
|
||||
Event.addRoutine(function()
|
||||
while true do
|
||||
print('proxy: listening on port 188')
|
||||
local socket = Socket.server(188)
|
||||
|
||||
print('proxy: connection from ' .. socket.dhost)
|
||||
|
||||
Event.addRoutine(function()
|
||||
local api = socket:read(2)
|
||||
if api then
|
||||
local proxy = _G[api]
|
||||
|
||||
local methods = { }
|
||||
for k,v in pairs(proxy) do
|
||||
if type(v) == 'function' then
|
||||
table.insert(methods, k)
|
||||
end
|
||||
end
|
||||
socket:write(methods)
|
||||
|
||||
while true do
|
||||
local data = socket:read()
|
||||
if not data then
|
||||
break
|
||||
end
|
||||
socket:write({ proxy[data.fn](unpack(data.args)) })
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
@ -2,9 +2,12 @@ local Event = require('event')
|
||||
local Socket = require('socket')
|
||||
local Util = require('util')
|
||||
|
||||
local function telnetHost(socket)
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local term = _G.term
|
||||
|
||||
requireInjector(getfenv(1))
|
||||
local function telnetHost(socket)
|
||||
_G.requireInjector()
|
||||
|
||||
local Event = require('event')
|
||||
|
||||
@ -14,7 +17,7 @@ local function telnetHost(socket)
|
||||
|
||||
local termInfo = socket:read(5)
|
||||
if not termInfo then
|
||||
printtError('read failed')
|
||||
_G.printtError('read failed')
|
||||
return
|
||||
end
|
||||
|
||||
@ -45,7 +48,7 @@ local function telnetHost(socket)
|
||||
end
|
||||
|
||||
local shellThread = Event.addRoutine(function()
|
||||
os.run(getfenv(1), 'sys/apps/shell')
|
||||
os.run(_ENV, 'sys/apps/shell')
|
||||
Event.exitPullEvents()
|
||||
end)
|
||||
|
||||
@ -67,7 +70,6 @@ local function telnetHost(socket)
|
||||
end
|
||||
|
||||
Event.addRoutine(function()
|
||||
|
||||
print('telnet: listening on port 23')
|
||||
while true do
|
||||
local socket = Socket.server(23)
|
||||
@ -77,7 +79,6 @@ Event.addRoutine(function()
|
||||
multishell.openTab({
|
||||
fn = telnetHost,
|
||||
args = { socket },
|
||||
env = getfenv(1),
|
||||
title = 'Telnet Client',
|
||||
hidden = true,
|
||||
})
|
||||
|
@ -6,14 +6,18 @@
|
||||
* background read buffering
|
||||
]]--
|
||||
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'Net transport')
|
||||
|
||||
local computerId = os.getComputerID()
|
||||
|
||||
_G.transport = {
|
||||
local transport = {
|
||||
timers = { },
|
||||
sockets = { },
|
||||
}
|
||||
_G.transport = transport
|
||||
|
||||
function transport.open(socket)
|
||||
transport.sockets[socket.sport] = socket
|
||||
|
Loading…
Reference in New Issue
Block a user