I was the first to write a BBS that supports UTF-8 and
cp437, but we required selecting it manually
(x84/default/charset.py script).
Supporting UTF-8 is a nice touch, certainly makes it easier for callers to use a variety of modern terminals.
But I wanted to share
with you a technique that I've been using lately that
should allow your BBS Softwares to automatically detect
the client, using the "Query Cursor Position" sequence,
"\x1b[6n". You could also use this to automatically
detect for "bots" or "scanners" rather than real users.
At least, any bot would have to emulate a terminal to
respond correctly.
This same sequence can also be useful for testing for general ANSI support. Nice trick to use it to detect the unicode support level too!
In any case, if the "bots" are not responding to this
query, you can kick them off. You can detect if they
support utf-8, and, whether they support emojis etc.
CP437 terminals like SyncTerm will be "corrupted" by utf-
8 bytes or display characters incorrectly, and by
measuring the delta of the starting and ending position
of a character after displaying unicode string, we can
determine whether they are utf-8 capable automatically.
Great technique and thank you for sharing it. Since my BBS doesn't support UTF-8 (yet) I might use the detection to present a message to callers using UTF-8 terminals to let them know CP437 would be better.
I think the idea of testing for terminal emulation to detect bots is interesting. It may run the risk of false positives, if you get callers using odd terminals - probably more concern for those running older systems like CBBS or other pure ASCII systems. I wonder how many (if any) bots support the ANSI terminal emulation - I have noticed that some of the scanners are doing telnet protocol negotiation (not just sending raw text for login attempts). Gonna have to run some tests on these bots!
On a similar topic of detecting terminals - I have recently implemented sixel detection (and am curious if anyone has other/better techniques).
Sixel detection isn't too difficult, but from my tests different terminals respond to different queries.
"\x1b[4c" works with iTerm2
"\x1b[<0c" works with SyncTerm
Read the response which should end with 'c'. If the response has ;4 in it then that indicates that sixel is supported.
For sixel detection on my BBS, I send both strings ("\x1b[4c\x1b[<0c") and read until I receive a 'c' (or time out after a second or two). If I find ";4" in the response then I assume sixel support exists.
I'm still working on understanding how to specify if a terminal should scale the image when displaying (SyncTerm seems to scale automatically, iTerm2 doesn't).
Chris/akacastor
--- Maximus 3.01
* Origin: Another Millennium - Canada - another.tel (21:1/162)