Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| First thing, I think it is very bizarre for a server to backspace stuff it has sent. Backspacing was intended for humans to correct errors they make when typing. For a program to "correct itself" is very strange. Also, in the case you quote of "very long titles", say the server wants to display a 10-character max title, but the player has a 80-character title, then using its implementation it sends 80 characters of title, followed by 70 backspace characters. Doesn't this seem strange to anyone else?
In C, it is very easy for the programmer to set fixed width strings, and truncate. Eg., using printf:
Print a string: %s
Print a string padded out to 10 characters: %10s
Print a string padded to 10 characters, and truncating extras: %10.10s
Having grumbled about this particular server implementation, we now look at what the client has to do to process backspaces.
The client receives data in packets, not necessarily discrete lines, or even logical parts of a line. For example, an ANSI colour sequence (ESC [ some-number m) might be broken across 2 packets by the network layer.
Thus to work reliably the client maintains a "state machine" where it remembers, for each incoming byte, the current state. For example, when processing MXP (MUD Extension Protocol) the "<" symbol triggers the "MXP element" state, and the < symbol, and text following it, are not displayed in the client window.
Now imagine what would happen if we get "<" followed by backspace. It has to undo the state change, and revert to the previous state, whatever that was. This would be horrendously complex to handle every possible combination.
Having said all that, using the newish OnPluginPacketReceived plugin callback, we can write a small plugin that will handle backspaces at the packet level, before the data hits the state machine. This should work fine for you, providing the incoming data does not have backspaces over a packet boundary. For all I know this will be 99% of the time.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, July 23, 2005, 11:04 AM -->
<!-- MuClient version 3.66 -->
<!-- Plugin "ProcessBackspaces" generated by Plugin Wizard -->
<muclient>
<plugin
name="ProcessBackspaces"
author="Nick Gammon"
id="c4fef242b44904d009ade8a0"
language="Lua"
purpose="Process backspace characters in individual packets"
date_written="2005-07-23 11:01:38"
requires="3.59"
version="1.0"
>
</plugin>
<!-- Script -->
<script>
<![CDATA[
function OnPluginPacketReceived (s)
repeat
i = string.find (s, "\b") -- find backspace
if i then
if i <= 1 then
s = string.sub (s, 2) -- just delete the backspace
elseif i == 2 then
s = string.sub (s, 3) -- deleting first character
else
s = string.sub (s, 1, i - 2) .. string.sub (s, i + 1)
end -- if i > 1
end -- if backspace found
until not i
return s
end -- function OnPluginPacketReceived
]]>
</script>
</muclient>
Just copy the above text, paste it into a text editor, and save as ProcessBackspaces.xml. Then use the plugin menu to add that as a MUSHclient plugin. That should fix your problem. :)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|