diff options
Diffstat (limited to 'nanochat/pylon.lua')
| -rw-r--r-- | nanochat/pylon.lua | 22 |
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 |
