< Back to top
Something is wrong with the NetHack server
Blake Thomas in development

This morning, a bunch of people on Discord told me that the Nethack server looks like this:

It's not supposed to look like that, so I started to investigate.

This looked like some client-side problems I had to deal with while writing the client in the first place, so I decided to start debugging this from the Javascript side. I had left in a lot of (commented out) logging, so I went and turned that back on. The first thing I noticed was that instead of printing the first

  ## dgamelaunch 1.5.1 - network console game launcher

line on line 3 like it should, it put it on line 21. Further investigation revealed that when the VT100 parser recieved the escape code ^[[1B (which moves the cursor down one line) on line 2, it moved it to line 21. (People who are better at Javascript than me probably already know the answer ;) ) I was eventually able to track this down to the function responsible for moving the cursor being called with the wrong arguments. When a ^[[xB is recieved, the VT100 parser calls

move_curs(cx, cy + vt100_params[0])

, where cx/cy is the current cursor position, and vt100_params[0] is x. When cy was 2 and vt100_params[0] was "1", Javascript did the obvious thing and concatenated them to make "21". Good for you, Javascript. You get a gold star for type inference.

Of course, this is solvable with liberal application of parseInt(), and the first screen now looked like:

which is mostly correct, but when I pressed l to log in, the problems returned:

Some more investigation revealed that dgamelaunch expected the sequence ^[[J to clear the entire screen, whereas the VT100 specification requires CSI J to take an explicit argument, where ^[[0J means 'clear the screen up to the cursor', ^[[1J means 'clear the screen after the cursor', and ^[[2J means 'clear the entire screen'. Since the first two forms aren't used by nethack, I simply ignored the argument and cleared the entire screen regardless.

And it works again!

The only remaining problem is that I have no idea why this started happening. It correlates with reconfiguring the EC2 instance's HTTP server to be able to support this blog and Nethack at the same time (which is a story for another day), and so the best guess I have is that something in there messed with what termcap entry dgamelaunch is looking at and that's what caused the ^[[J mix-up, but as for why the Javascript type coercion problem only just came up I have no idea.