summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-01 02:08:51 +0100
committerubq323 <ubq323@ubq323.website>2024-04-01 02:08:51 +0100
commitb5c9d4bca3d329df0ade020d1b24a99a1cd118d8 (patch)
treeff2b80514a1716480cb41d5cf1356c6fa2795644
parent897c08957ccb146fbcd8744140de6edf831549ec (diff)
launch
-rwxr-xr-xlaunch.sh2
-rw-r--r--listener.lua40
2 files changed, 36 insertions, 6 deletions
diff --git a/launch.sh b/launch.sh
index 2bdc802..d9daeb6 100755
--- a/launch.sh
+++ b/launch.sh
@@ -3,4 +3,4 @@ fname="$1"
bname="${fname%.lua}"
git add .; git commit -m "launch $bname"; git push
-echo "$bname" | websocat wss://citrons.xyz/ws-echo/rebecca
+# echo "$bname" | websocat wss://citrons.xyz/ws-echo/rebecca
diff --git a/listener.lua b/listener.lua
index 1419f99..7560da6 100644
--- a/listener.lua
+++ b/listener.lua
@@ -1,6 +1,24 @@
local pm = require'pm'
local ws = assert(http.websocket("wss://citrons.xyz/ws-echo/rebecca"))
+local function splitw(str)
+ local res = {}
+ for s in str:gmatch("%S+") do
+ table.insert(res, s)
+ end
+ return res
+end
+
+local ops = {}
+function ops.deploy(pkgname)
+ pm.cc()
+ pm.dl(pkgname)
+ shell.run('bg '..pkgname)
+end
+function ops.test()
+ print("hello world")
+end
+
function main()
print("listening")
while true do
@@ -8,11 +26,23 @@ function main()
local parsed = assert(textutils.unserializeJSON(msg))
if parsed.msg then
print("got msg",parsed.msg)
- -- more sophisticated cmds later, maybe
- local pkgname = parsed.msg:gsub("%s","")
- pm.cc()
- pm.dl(pkgname)
- shell.run('bg '..pkgname)
+ local words = splitw(parsed.msg)
+ if words[1] ~= "RRP" then
+ print("non-RRP message!")
+ else
+ local target = words[2]
+ local mylabel = os.computerLabel()
+ if not (target == mylabel or target == "*")
+ print("not for me")
+ else
+ local op = words[3]
+ if ops[op] then
+ ops[op](unpack(args,4))
+ else
+ print("unknown op "..op)
+ end
+ end
+ end
end
end
end