I'm using a plugin to modify packets, and basically I'm trying to pull information from telnet subnegotiations (\255\250\200...\255\240) and then cut them out of the packet. Once in a while (usually when the packets are coming very fast), the server will split a subnegotiation into two separate packets so I get a packet like [packet text]\255\250\200[portion of subnegotiation] followed immediately by a second packet: [rest of subnegotiation]\255\240[packet text]. Here's what I've coded to work around this with the relevant parts bolded.
function OnPluginPacketReceived(x)
Note("packet: " .. x)
x = string.gsub(x, "\255\251.", "")
if packet and not blackout then
subnegotiation(packet .. tostring(string.match(string.gsub(x, "\255\250\200.-\255\240", ""), "^.-\255\240")))
end
packet = ""
blackout = false
if string.find(x, "\255\250\200Char.Vitals\10NL:%d+/%d+ H:%d+/%d+ M:%d+/%d+ E:%d+/%d+ P:%d+/%d+ N:%d+/%d+ W:%d+/%d+ \255\240%-\255\249") then
blackout = true
c = {}
for a in string.gmatch(x, "\255\250\200Char.Vitals\10NL:%d+/%d+ H:%d+/%d+ M:%d+/%d+ E:%d+/%d+ P:%d+/%d+ N:%d+/%d+ W:%d+/%d+ \255\240%-\255\249") do
c[table.getn(c) + 1] = a
end
end
if not blackout then
while string.find(x, "\255\250\200.-\255\240") do
subnegotiation(string.match(x, "\255\250\200.-\255\240"))
x = string.gsub(x, "\255\250\200.-\255\240", "", 1)
end
packet = string.match(x, "\255\250\200.-$")
x = string.gsub(x, "^.*\255\240", "")
x = string.gsub(x, "\255\250\200.*$", "")
elseif blackout then
b = x
while string.find(b, "\255\250\200.-\255\240") do
subnegotiation(string.match(b, "\255\250\200.-\255\240"))
b = string.gsub(b, "\255\250\200.-\255\240", "", 1)
end
x = string.gsub(x, "\255\250\200Char.Vitals\10NL:%d+/%d+ H:%d+/%d+ M:%d+/%d+ E:%d+/%d+ P:%d+/%d+ N:%d+/%d+ W:%d+/%d+ \255\240%-\255\249", "\201")
x = string.gsub(x, "\255\250\200Char.Vitals\10NL:%d+/%d+ H:%d+/%d+ M:%d+/%d+ E:%d+/%d+ P:%d+/%d+ N:%d+/%d+ W:%d+/%d+ \255\240","")
for _,d in ipairs(c) do
x = string.gsub(x, "\201", d, 1)
end
end
if GetEntity("timestamp") == '1' then
x = string.gsub(x, "\255\249", " {" .. os.clock() - math.floor(os.clock() / 100) * 100 .. "}\255\249", 1)
end
return x
end
The problem is that sometimes a strange newline will appear in the output like so:
(The packets are visible because of the first line of my function: Note("packet: " .. x); also, in case it isn't clear, ÿúÈ = \255\250\200 and ÿð = \255\240)
packet: [32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:
End of packet
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w
packet: 27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù[32m6000h,[37m[32m 6300m,[37m[32m 6300e,[37m[32m 10p,[37m[32m 27900en,[37m[32m 29400w[37mÿúÈChar.Vitals
NL:0/100 H:6000/6000 M:6300/6300 E:6300/5700 P:10/10 N:27900/27900 W:29400/29400 ÿð elrx-ÿù
End of packet
elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
6000h, 6300m, 6300e, 10p, 27900en, 29400w elrx-
See how the last prompt in the first packet was split up? Somehow, either the newline after "Char.Vitals" wasn't taken out with the rest of the subnegotiation (which definitely was taken out because they're normally visible in the output) or a new newline was mysteriously inserted. Can anyone see how this happens?
I almost forgot: I set the option so that Mushclient converts ÿù to a newline, which is why the prompts are on separate lines in the output but not in the packet, in case anyone was wondering. |