mushclient icon indicating copy to clipboard operation
mushclient copied to clipboard

NAWS reports strange values when tabbing back to an open world

Open gesslar opened this issue 4 years ago • 4 comments

When tabbing back to an open world, NAWS sends several messages to the mud, some with incorrect values. I have uploaded a video to YouTube demonstrating this.

I start with a clean output, switch to another world, come back to the world with NAWS enabled and you can see that the MUD is receiving several NAWS dimensions (width,height).

I have my game reporting every time it receives NAWS information.

https://www.youtube.com/watch?v=1K1UdF8PcCg

gesslar avatar Feb 25 '21 01:02 gesslar

The width is right. The height is calculated by dividing the dynamically-obtained window height by the number of pixels per character in the chosen font. When the window is not active it seems that the information about the window height (returned by the OS) is not correct.

I'm not sure of a workaround for this, except to perhaps ignore the height unless the window is active.

Alternatively use the OnPluginWorldOutputResized plugin callback, and then find the output size, and calculate the number of lines yourself at that point.

nickgammon avatar Mar 01 '21 21:03 nickgammon

GetInfo (241) gives you the output font height. GetInfo (280) gives you the output window height.

http://www.gammon.com.au/scripts/doc.php?function=GetInfo

For example:

print (math.floor (GetInfo (280) / GetInfo (241)))

nickgammon avatar Mar 01 '21 21:03 nickgammon

I'm not using a plugin for NAWS. I'm using "Negotiate About Windows Size" from the world's output options.

  1. Why is it sending it "correctly" the first time, incorrectly two times, and then correctly the fourth time?
  2. Why is it sending it 4 times?

gesslar avatar Mar 01 '21 23:03 gesslar

If you have NAWS activated, the client sends the NAWS information when it gets a "window resized" message from the operating system. For some reason it looks like it gets four messages, and for two of them when it inquires about what the size is (from the operating system) it gets the wrong result.

You don't resize the window every couple of minutes do you? You could always turn that option off once it has sent the size correctly once.

Or even, turn the option off, and after resizing the window make an alias that sends the NAWS sequence yourself (using the information I posted above). You would use SendPkt to do that. The sequence is:

IAC,   // Interpret as command (0xFF)
SB,    // subnegotiation  (0xFA)
TELOPT_NAWS,   // NAWS  (31)
HIBYTE (iNewWidth), LOBYTE (iNewWidth),  // the width (high-order byte, low-order byte)
HIBYTE (height), LOBYTE (height),        // the height (high-order byte, low-order byte)
IAC,   // Interpret as command  (0xFF)
SE     // subnegotiation end (0xF0)

So for example, in Lua:

local width = math.floor (GetInfo (281) / GetInfo (240))  -- window width divided by average character width
local height = math.floor (GetInfo (280) / GetInfo (241)) -- window height divided by output font height
SendPkt (string.char (0xFF, 0xFA, 31, 
         bit.shr (width, 8), bit.band (width, 0xFF), 
         bit.shr (height, 8), bit.band (height, 0xFF), 
         0xFF, 0xF0))

nickgammon avatar Mar 11 '21 21:03 nickgammon