add wallpaper and mesh routing support
This commit is contained in:
18
.wallpaper.nfp
Normal file
18
.wallpaper.nfp
Normal file
@@ -0,0 +1,18 @@
|
||||
0000000000000055555555d0000000000000000000000000000
|
||||
00000000055555d00555555d000000000000000000000000000
|
||||
000000005555555d00055555d00000000000000000000000000
|
||||
0000000055555555d05055555d3d30000000000000033300000
|
||||
00000000055555555d05555555d3d3000000000003333300000
|
||||
30000000300055555555d555555d3d333333303333333333330
|
||||
3303333333353555555d5d555555d3333033333333330330000
|
||||
033330303035355555555555555d3d333033033033333300000
|
||||
003030333333555ffff555ffff55d3303333333333303300077
|
||||
0033333033035555555555555555d3333303330330333000878
|
||||
78830333333535555555f555555d3d303333333333037787778
|
||||
87844bb0b0bb55b5555555555dbddbbbbbb0bbbb44407878888
|
||||
0780044bbbb0bb5b55555555dbdbb0b0bbbbbb4440778888888
|
||||
7870040b0b0bbbbb55555555dbbbbbbb0bb0b44407888808888
|
||||
78080044bbbbb0bb55555555db0bb0bb0bbbb40077870878087
|
||||
78788004bbb0bbb555555555dbbbbbbbbbbb440078788887787
|
||||
778788004b0bbbb5555555555dbbbb0bbb04408878888088777
|
||||
777888004bbbbb555555555555dbbbbbbbb4008878088878888
|
||||
@@ -1,7 +1,7 @@
|
||||
local window = require("libs.window")
|
||||
local threading = require("libs.threading")
|
||||
local x, y = term.getSize()
|
||||
local win = window.create("Shell", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2))
|
||||
local win = window.create("Launcher", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2))
|
||||
win.decorations = false
|
||||
win.alwaysOnTop = true
|
||||
local apps = {}
|
||||
|
||||
111
modules/entrypointclient.lua
Normal file
111
modules/entrypointclient.lua
Normal file
@@ -0,0 +1,111 @@
|
||||
local max_distance = 220
|
||||
|
||||
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
|
||||
return
|
||||
end
|
||||
local message_queue = {}
|
||||
modem.open(15125)
|
||||
local 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)
|
||||
local last_heartbeat = os.epoch("utc")
|
||||
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
parallel.waitForAny(receive, connect)
|
||||
os.shutdown()
|
||||
@@ -66,15 +66,19 @@ end
|
||||
|
||||
local function desktop()
|
||||
local image = nft.load(".wallpaper.nft")
|
||||
local paint_image = paintutils.loadImage(".wallpaper.nfp")
|
||||
local w, h = term.getSize()
|
||||
term.setBackgroundColor(colors.lightGray)
|
||||
term.setBackgroundColor(colors.white)
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.gray)
|
||||
term.write(" Desktop ")
|
||||
term.clearLine()
|
||||
term.write(" "..((_G.windows[#_G.windows] or {name=""}).name or "").." ")
|
||||
if image then
|
||||
nft.draw(image,1,1)
|
||||
elseif paint_image then
|
||||
paintutils.drawImage(paint_image,1,2)
|
||||
end
|
||||
end
|
||||
local threading = require("libs.threading")
|
||||
|
||||
Reference in New Issue
Block a user