so so much...

This commit is contained in:
2025-12-22 12:01:01 -08:00
parent a19fe74de1
commit 4e0a5871bd
7 changed files with 1740 additions and 0 deletions

3
.settings Normal file
View File

@@ -0,0 +1,3 @@
{
[ "motd.path" ] = "/rom/motd.txt:/motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt:/rom/cccbridge_motd.txt",
}

BIN
apps/test Normal file

Binary file not shown.

6
entertest.lua Normal file
View File

@@ -0,0 +1,6 @@
local containers = require "libs.containers"
local appid = ...
local w,h = term.getSize()
local win = window.create(term.native(),1,2,w,h-2,true)
local env = containers.getENV(fs.combine("/apps",appid),true, win)
containers.start(env)

1524
libs/containers.lua Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,119 @@
local max_distance = 120
local expect = dofile("rom/modules/main/cc/expect.lua")
local expect, field = expect.expect, expect.field
local pullEvent = os.pullEventRaw
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
term.clear()
term.setCursorPos(1,1)
_G.network = {}
if not modem then
shell.run("shell")
os.shutdown()
end
local message_queue = {}
modem.open(15125)
local canidate = {id = -1, distance = max_distance}
local last_heartbeat = os.epoch("utc")
local function receive()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
canidate.distance = distance
last_heartbeat = os.epoch("utc")
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
if distance > max_distance then
modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id})
canidate = {id = -1, distance = max_distance}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function ()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then
canidate.id = msg.sender
canidate.distance = distance
end
end
end
end
end)
if canidate.id == -1 then
sleep(5)
else
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
last_heartbeat = os.epoch("utc")
end
end
elseif msg.protocol == "packet" then
if msg.hops >= 1 then
os.queueEvent("network_packet",msg.content,msg.sender,msg.hops)
end
end
end
end
end
function _G.network.send(msg,destination)
if not msg then error("No message provided",2) end
if not destination then error("No destination provided",2) end
message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0}
end
function _G.network.getCandidate()
return canidate
end
local function connect()
while true do
if os.epoch("utc") - last_heartbeat > 200 then
canidate = {id = -1, distance = max_distance}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function ()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then
canidate.id = msg.sender
canidate.distance = distance
end
end
end
end
end)
if canidate.id == -1 then
sleep(5)
else
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
last_heartbeat = os.epoch("utc")
end
else
local msg = table.remove(message_queue,1)
if msg then
modem.transmit(15125,15125,msg)
end
end
sleep()
end
end
function _G.network.run()
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function ()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then
canidate.id = msg.sender
canidate.distance = distance
end
end
end
end
end)
last_heartbeat = os.epoch("utc")
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
parallel.waitForAny(receive, connect)
end

3
startup/01_repo.lua Normal file
View File

@@ -0,0 +1,3 @@
local lib = {}
_G.repo = lib

85
startup/99_phoneOS.lua Normal file
View File

@@ -0,0 +1,85 @@
local apps = {}
local containers = loadfile("/libs/containers.lua")()
local focusedapp = nil
_G.app = {}
function _G.app.focusapp(pid)
print("focusing "..pid)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(false)
end
focusedapp = apps[pid]
print(focusedapp)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(true)
end
end
function _G.app.launch(id)
local w,h = term.getSize()
if not fs.exists(fs.combine("/apps",id)) then return false,"App Not Found" end
local win = window.create(term.native(),1,2,w,h-2,false)
print("loading "..id)
local env = containers.getENV(fs.combine("/apps",id),true, win)
local appobj = {win=win,co=nil,id=id,title=""}
function env.setAppTitle(str) appobj.title=str end
print("loaded "..id)
appobj.co = coroutine.create(function () containers.start(env) end)
local pid = -1
for k=1,#apps+1 do
if apps[k] == nil then
apps[k] = appobj
pid = k
end
end
app.focusapp(pid)
end
local function render()
while true do
local w,h = term.getSize()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
term.clearLine()
term.write(os.date("%I:%M %p"))
local candidate = network.getCandidate()
local right = "id: "..tostring(candidate.id).." dist: "..tostring(math.floor(candidate.distance+0.5)).." m"
if candidate.id == -1 then
right = "disconnected"
end
term.setCursorPos(w-right:len()+1,1)
term.write(right)
sleep()
end
end
local function process()
while true do
local event = {os.pullEvent()}
if focusedapp then
if focusedapp.event then
local success, content = coroutine.resume(focusedapp.co,table.unpack(focusedapp.event))
if success then
focusedapp.event = nil
focusedapp.filter = content
else
app.focusapp(-1)
end
elseif focusedapp.filter == nil or focusedapp.filter == event[1] then
local success, content = coroutine.resume(focusedapp.co,table.unpack(event))
if success then
focusedapp.filter = content
else
app.focusapp(-1)
end
end
end
for k,v in pairs(apps) do
if v.filter == nil or v.filter == event[1] and v.event == nil and not v == focusedapp then
v.event = event
end
end
end
end
print("launching test..")
app.launch("test")
print("launched")
parallel.waitForAny(process,render,network.run)