Unfortunatly it doesn't use IAC GO/EOR code, but indeed do u se that escape character.
local buffer = ""
pattern = "%[32m<.+%[0;32m> " .. string.char(27) .. "%[0m"
function OnPluginPacketReceived (s)
buffer = buffer .. s
s = ""
local current_line = buffer
local newline_index, _ = string.find(buffer,"\n")
while newline_index ~= nil do
current_line = string.sub(buffer, 1, newline_index)
local _, prompt_inside = string.find(current_line, pattern)
if prompt_inside ~= nil then
newline_index = prompt_inside
current_line = string.sub(buffer, 1, newline_index) .. "\n"
end -- if
buffer = string.sub(buffer, newline_index + 1)
s = s .. current_line
newline_index, _ = string.find(buffer,"\n")
end -- while
if string.find(buffer, pattern) ~= nil then
s = s .. buffer .. "\n"
buffer = ""
end -- if
return s
end -- function OnPluginPacketReceived
This is what I do to rebuild prompts, I'm well aware it's a bit ugly to read hehe. Feel free to comment tho.
Problem I had without:
No newline at then end of last prompt, then had trouble to add one since sometimes it was splitted in several packets. Also had an issue when packets looked like this: "<prompt>You sit down."
What it basicaly does:
Concat packets until newline or until it matches a prompt and then send it. In the later case it adds a newline at the end of the prompt.
It generates some not needed blank lines, so I use an additional trigger to remove them all.
My problem now comes from MCCP compression. When I login if this script is enable what I get as packets are compressed datas, and of course it doesn't work at all. It can even crashes the connection. It's really strange tho, cause if I disable, connect, wait a bit (won't work if I don't wait long enough) and then enable it ... It works fine even tho the compression is still acive. It acts like at the uncompression part activate after OnPluginPacketReceived at first and then before ... Quite puzzling. Gonna look deeper in the forum for an answer, and will edit if I find any.
EDIT: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=8956
I didn't really get it, but I guess that's what I was looking for. Is there a way to edit the above script of mine so it keeps doing the same but don't corrupt the compression?
Side question, when is the compression negociated? Sometimes I have to wait like 2 mins before enabling the plugin, sometimes it's fine after 30s. |