Quote:
This mud does permit me to set the line length to 999, but doing so pads a boat load of white spaces to the end of the lines.
That is very weird. I mean, adding spaces? Who does that?
Surely a line length of 999 should just mean allow 999 characters before wrapping, not add 990 spaces to the end of a 10-character line?
One problem I see from your posted packet is that you haven't actually reached the next line yet (there is no 0D 0A at the end) so this line will continue to the next packet.
Your posted line, for example, has 393 bytes not 999.
Can't the implementor at least not add the spaces? That is a huge overhead for the MUD for no reason. I mean, all he has to do is do a "trim" at the MUD end before sending the line.
Anyway, I think this plugin will do it for you, if they won't change the MUD:
|
To save and install the Omit_Trailing_Spaces plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Omit_Trailing_Spaces.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Omit_Trailing_Spaces.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Omit_Trailing_Spaces"
author="Nick Gammon"
id="a9ebc1f78f75b3bfc7c12e3b"
language="Lua"
purpose="Omit trailing spaces from packets"
date_written="2014-08-30 08:11"
date_modified="2014-08-30 16:25"
requires="4.80"
version="1.3"
>
</plugin>
<!-- Script -->
<script>
<![CDATA[
local previousPacket = { }
local lines = { }
-- trim trailing spaces, add to lines table
function trimTrailing (s)
s = string.gsub (s, "\r", "")
lines [#lines + 1] = (string.gsub (s, "^(.-)[ ]*$", "%1"))
return "" -- omit from the existing line
end -- end of function trimTrailing
function OnPluginPacketReceived (packet)
-- wait for compression to be turned on
if not GetInfo (103) then
return packet
end -- if
-- add packet to previous ones
previousPacket [#previousPacket + 1] = packet
-- combine into one long string
local allPackets = table.concat (previousPacket)
lines = { } -- no lines yet
-- break up combined packet into lines with CR/LF in them
local LeftOver = string.gsub (allPackets, "([^\n]*)\n", trimTrailing)
-- if no carriage-return/linefeed in line return nothing
if #lines == 0 then
return ""
end -- if
-- this last part did not have a CR/LF in it
previousPacket = { LeftOver }
-- return existing lines with the LF added back
return table.concat (lines, "\n") .. "\n"
end -- OnPluginPacketReceived
function OnPluginConnect ()
previousPacket = {}
end -- OnPluginConnect
]]>
</script>
</muclient>
[EDIT] Amended to fix a few bugs.
What this does is initially batch up incoming packets until it gets a CR/LF (0D0A). This allows for long lines to be split over multiple packets.
After each packet arrives it assembles the combined packets into one long string, and tries to break it up into lines. In the process, trailing spaces are omitted. Those lines are then returned.
Warning: It is the nature of such a process that "prompting" will not work. eg.
Enter your name:
Enter your password:
This is because the CR/LF "trigger" has not arrived.
There's nothing much that can be done about that, although possible you could amend it to have a timer, and output a partial line if (say) two seconds have elapsed.
You could disable the plugin initially (eg. during the logon process) and then enable it once logged on. You could make a couple of triggers to do that.
Note re MCCP.
If your MUD uses compression, I have made the plugin do nothing until compression is turned on, or it will behave strangely.
If your MUD does not use compression (MCCP) then omit these lines:
-- wait for compression to be turned on
if not GetInfo (103) then
return packet
end -- if
[EDIT] Amended again (to version 1.3) to fix a fairly major bug where previous lines would keep re-appearing. |