14 Aug, 2010, Scionwest wrote in the 1st comment:
Votes: 0
Greetings everyone,

Clients currently connect to my C# telnet server via their own telnet client (I use puttytel) and play the game via their terminal. Anyone know of a way that I can clear the clients terminal screen of all text? Is there a specific way of doing this over telnet or am I going to have to fake it in some way? I know each telnet terminal has a different way of handling commands and such from the server, so I am curious if there is a standard that they all use for it or not. I read a telnet standardization document but really couldn't make heads or tells of what it meant lol.

Anyone know how I can do this without spamming the terminal full of blank lines?

Thanks
14 Aug, 2010, Scandum wrote in the 2nd comment:
Votes: 0
Sending \eSending \e[2J should do the trick.
14 Aug, 2010, Scionwest wrote in the 3rd comment:
Votes: 0
Thanks! No closing bracket?
14 Aug, 2010, Cratylus wrote in the 4th comment:
Votes: 0
Scionwest said:
Thanks! No closing bracket?


http://www.termsys.demon.co.uk/vtansi.ht...
14 Aug, 2010, Scionwest wrote in the 5th comment:
Votes: 0
Hmm, when I try to use that, it fails to compile as C# does not recognize the \e as a character escape sequence. So I tried to send it as a literal string and the terminal ends up just spitting it out to the client as a string instead of clearing the screen. Any other ideas?

Fails: Unknown escape sequence error due to \e not being recognized.
internal void ClearTerminal()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\e
internal void ClearTerminal()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\e[J2"));
}
catch
{
Disconnect();
}
}
[/code]

[b]Compiles[/b]: Sends content to terminal but the terminal prints the string to the user instead of processing it.
[code]internal void ClearTerminal()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes(@"\e[J2"));
}
catch
{
Disconnect();
}
}
[/code]

Any other suggestions?
14 Aug, 2010, kiasyn wrote in the 6th comment:
Votes: 0
\033 i think it is
14 Aug, 2010, quixadhal wrote in the 7th comment:
Votes: 0
Also note that this has NOTHING to do with the TELNET protocol. It is the magic byte sequence which makes VT100/ANSI compatible terminals clear their displays. Other terminal types, or non-compatible emulations, may not work or may produce garbage, or otherwise lock up the victim's terminal.

I throw this caution out because even though everyone tosses ANSI codes around with the assumption they always work, it's not correct to do so, even if you can usually get away with it. ;)
14 Aug, 2010, Cratylus wrote in the 8th comment:
Votes: 0
quixadhal said:
I throw this caution out because even though everyone tosses ANSI codes around with the assumption they always work,


umm….wat

are you suggesting people use clients that dont support the mud standards?
14 Aug, 2010, Scionwest wrote in the 9th comment:
Votes: 0
quixadhal said:
Also note that this has NOTHING to do with the TELNET protocol. It is the magic byte sequence which makes VT100/ANSI compatible terminals clear their displays. Other terminal types, or non-compatible emulations, may not work or may produce garbage, or otherwise lock up the victim's terminal.

I throw this caution out because even though everyone tosses ANSI codes around with the assumption they always work, it's not correct to do so, even if you can usually get away with it. ;)

Yeah, I found in my PuTTYtel preferences a Keyboard section that lets me choose what to use for function keys. ESC
Yeah, I found in my PuTTYtel preferences a Keyboard section that lets me choose what to use for function keys. ESC[n~, VT400 or VT100+ I tried to use VT100 but for some reason the terminal wouldn't save those settings, so I adjusted my C# code to send \033[n~ and it just spit the contents directly to the terminal screen.
14 Aug, 2010, Scionwest wrote in the 10th comment:
Votes: 0
kiasyn said:
\033 i think it is


I used that and it just sends the content to the terminal screen for users to read. The terminal doesn't use it and I'm pretty sure PuTTY supports that, is this an issue with .NET?

internal Socket client;
internal void FlushConsole()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\033internal Socket client;
internal void FlushConsole()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\033[J2"));
}
catch
{
Disconnect();
}
}[/code]
14 Aug, 2010, kiasyn wrote in the 11th comment:
Votes: 0
Scionwest said:
kiasyn said:
\033 i think it is


I used that and it just sends the content to the terminal screen for users to read. The terminal doesn't use it and I'm pretty sure PuTTY supports that, is this an issue with .NET?

internal Socket client;
internal void FlushConsole()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\033internal Socket client;
internal void FlushConsole()
{
try
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
client.Send(encoding.GetBytes("\033[J2"));
}
catch
{
Disconnect();
}
}[/code][/quote]

[code]
sam@shiny:~$ irb
irb(main):001:0> print "\033[2J"
[/code]

worked for me.
14 Aug, 2010, Scionwest wrote in the 12th comment:
Votes: 0
I think that .NET is transmitting the data in some manor that is messing this up. I try to use the \033I think that .NET is transmitting the data in some manor that is messing this up. I try to use the \033[2J and after entering the 'Clear' command in my terminal, all that happens is "33[2J" is printed to the screen. the \0 is missing, which must be happening on the server side. I'm not sure x_x I should not be seeing the "332J" at all, the terminal should clear the screen with that sequence, but I think it's arriving incomplete and so the terminal prints it to the user.
14 Aug, 2010, Tyche wrote in the 13th comment:
Votes: 0
Your \0 is recognized as the string literal escape for the NUL character.
C# doesn't recognize octal (\033) or hex (\x1b) string literal escapes.

Also C# strings are unicode. I have no idea whether they are encoded in UTF-8,16, or 32.
Anyway the only way to insert an escape character is using the unicode sequence, '\u001b'
14 Aug, 2010, Scandum wrote in the 14th comment:
Votes: 0
Can always try \x1BCan always try \x1B[2J though \033[2J ought to work for see sharp.

Edit: \033 isn't supported, but \x is supposed to be.
14 Aug, 2010, Scionwest wrote in the 15th comment:
Votes: 0
Scandum said:
Can always try \x1BCan always try \x1B[2J though \033[2J ought to work for see sharp. [/quote]
Thanks, that worked! You helped remove a large amount of frustration lol.

one last question, now that the terminal is cleared, my cursor is at the bottom of the screen. I used \x1B[H and my cursor moved to it's home, however it still appears to be one line down from the top of the terminal. I tried to force via \x1B[{0};{0}H but once again I'm faced with C# messing this up I believe as my terminal now prints 0};{0}H
Any suggestions for this?
14 Aug, 2010, quixadhal wrote in the 16th comment:
Votes: 0
I'd look for an ANSI terminal library for C#. If the language's default output mechanics make things so difficult to work with, someone else must have written a library to properly handle it by now.
14 Aug, 2010, Scionwest wrote in the 17th comment:
Votes: 0
quixadhal said:
I'd look for an ANSI terminal library for C#. If the language's default output mechanics make things so difficult to work with, someone else must have written a library to properly handle it by now.


I would but I'm wanting to learn to do it right myself, I've relied on 3rd party libraries in the past and my projects became a mess as I had a hard time going back through other people code and making it work with the other 3rd party libs I found. Perhaps I should take the the ANSI issue to the MSDN forums as well, Good idea
14 Aug, 2010, JohnnyStarr wrote in the 18th comment:
Votes: 0
Watcha doin' in C# friend?
14 Aug, 2010, Scionwest wrote in the 19th comment:
Votes: 0
The primary reason is the IDE's IntelliSense really helps me out. I've never really wrote anything completely in C++ either, but have 6 years of experience in C# so I decided that I'd stick with what I was familiar with on a project of this scale lol.
14 Aug, 2010, JohnnyStarr wrote in the 20th comment:
Votes: 0
A MUD project in C#? I've been working on a .net MudLib for the last 3 weeks. Quite fun. I also enjoy VS 2008 Class Diagrams.
0.0/28