summaryrefslogtreecommitdiff
path: root/nanochat/pylon.lua
diff options
context:
space:
mode:
authorolive <olive@olive.ooo>2026-09-17 20:29:09 +0100
committerolive <olive@olive.ooo>2026-09-17 20:29:09 +0100
commit9157750d04dfb2863bc5822b908336e663b141b1 (patch)
tree3ec8ac81aef2ea1e67db38d6c2b013ee8dddab33 /nanochat/pylon.lua
parent87ed4adab569504e4ce053f8288a84404f63c8dc (diff)
Use shortname config rather than hard-coding [x] and so on.
Pylons may also make their own choce in how they format the short-name when sending out (or do it differently altogether), rather than it being baked-in by the receiving pylon.
Diffstat (limited to 'nanochat/pylon.lua')
-rw-r--r--nanochat/pylon.lua22
1 files changed, 11 insertions, 11 deletions
diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua
index 8e510bc..6546f05 100644
--- a/nanochat/pylon.lua
+++ b/nanochat/pylon.lua
@@ -22,33 +22,33 @@ end
function Nanochat:recving()
while true do
self.sock:write("SKIP "..self.lastid.."\n")
- local deliverables = {}
+ local deliverables = {} -- holey
local n = tonumber(assert(self.sock:read("*l")))
for i=1,n do
local msg = assert(self.sock:read("*l"))
local chan, msgi = msg:match("^([^ ]+) ()")
if chan then
- if not deliverables[chan] then deliverables[chan] = {} end
local sender, body = msg:match("^([^:]+): (.+)$", msgi)
if sender then
- deliverables[chan][#deliverables[chan]+1] = { i=i, sender="[n]"..sender, body=body }
+ deliverables[i] = { source_channel=Channel(self, chan), sender=sender, body=body }
else
- deliverables[chan][#deliverables[chan]+1] = { i=i, sender="[n]", body=msg:sub(msgi,-1) }
+ deliverables[i] = { source_channel=Channel(self, chan), sender="", body=msg:sub(msgi,-1) }
end
+ else
+ -- ignore messages without a channel, they stay nanochat-local
end
end
local s = self.sock:read("*l")
self.lastid = tonumber(assert(s))
- for chan,blorp in pairs(deliverables) do
- for _,d in ipairs(blorp) do
- local id = d.i - n + self.lastid
- d.i = nil
+ for i=1,n do
+ local msg = deliverables[i] ; if msg then
+ local id = i - n + self.lastid
if self.usids[id] then
self.usids[id] = nil
else
- self.log:proto('<',chan,d.sender,d.body)
- self.wilson:deliver(Channel(self, chan), d)
+ self.log:proto('<', msg.source_channel.descriptor, msg.sender, msg.body)
+ self.wilson:deliver(msg)
end
end
end
@@ -60,7 +60,7 @@ end
function Nanochat:sending()
for dest_channel, message in self.inbox:iter() do
self.log:proto('>',dest_channel,message.sender,message.body)
- assert(self.sock:write("SEND "..dest_channel.descriptor.." "..message.sender..": "..message.body.."\n"))
+ assert(self.sock:write("SEND "..dest_channel.descriptor.." ["..message.source_channel.pylon.shortname.."] "..message.sender..": "..message.body.."\n"))
local id = tonumber(assert(self.sock:read("*l")))
self.usids[id] = true
end