0

I have created a simple MUD client that has finally managed to connect to the server. However, I'm getting a bunch of unrecognizable characters in my output window.

Screenshot

I have highlighted some of the characters on this screenshot. I believe most of these are colorcodes, some are hyperlinks. Some might even be newline characters.

I think that the charset on the server is ASCII (it can be changed by the user.) Here is the code that presents the text in my client:

    private void getDataFromServer() {
        byte[] bytesToRead = new byte[client.ReceiveBufferSize];
        int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
        updateOutputWindow(Encoding.ASCII.GetString(bytesToRead, 0, bytesRead));
    }

    private void updateOutputWindow(string text) {
        if (InvokeRequired) {
            Invoke(new MethodInvoker(delegate () {
                updateOutputWindow(text);
            }));
        }
        else {
            rtb_outputWindow.AppendText(text);
            MessageBox.Show(text);
        }
    }

Is it possible to somehow interpret these characters?

  • https://en.wikipedia.org/wiki/ANSI_escape_code – L.B Aug 12 '17 at 22:42
  • I tried doing: updateOutputWindow(Encoding.Default.GetString(bytesToRead, 0, bytesRead)); And going through all the different Encodings. The ones who worked were all pretty similar, but the unrecognized characters remained. I read somewhere that my client doesn't have MXP support - I don't know how to get it, though.. –  Aug 13 '17 at 08:01
  • Have you read the link I posted? it is not about encoding. It is about emulating VT100 terminals – L.B Aug 13 '17 at 12:28
  • I see. Is there a way to easily convert these escape chars into something else (color, for example)? According to the link you posted the first character is 'ESC' (it shows up as a "whitebox" in my client) - is there some way to make it show up as a proper character? I tried doing this just to see what would happen: if (text.Contains("[1;37m")) MessageBox.Show("escape char found!"); the MessageBox showed up as expected. –  Aug 13 '17 at 13:44
  • 1
    1- Change your project settings to console (project/settings/application/output type) this will open a console window. 2- enable "ENABLE_VIRTUAL_TERMINAL_PROCESSING" like in [this question](https://stackoverflow.com/questions/44574274/setconsolemode-fails-with-zero-lasterror-0) 3-Write your data to console – L.B Aug 13 '17 at 23:38

0 Answers0