From 9a82c4c5c06420fbb20f0e138a78d3dfb97f5cee Mon Sep 17 00:00:00 2001 From: DehanLUO Date: Mon, 10 Jul 2023 01:48:48 -0400 Subject: [PATCH 1/2] Stop local echo when remote echo is on --- tabby-telnet/src/session.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tabby-telnet/src/session.ts b/tabby-telnet/src/session.ts index 9d5e819e..8c3b1e9b 100644 --- a/tabby-telnet/src/session.ts +++ b/tabby-telnet/src/session.ts @@ -66,6 +66,7 @@ export class TelnetSession extends BaseSession { private lastWidth = 0 private lastHeight = 0 private requestedOptions = new Set() + private telnetRemoteEcho = false constructor ( injector: Injector, @@ -159,7 +160,7 @@ export class TelnetSession extends BaseSession { data = data.slice(3) this.logger.debug('<', commandName || command, optionName || option) - if (command === TelnetCommands.WILL || command === TelnetCommands.WONT) { + if (command === TelnetCommands.WILL || command === TelnetCommands.WONT || command === TelnetCommands.DONT) { if (this.requestedOptions.has(option)) { this.requestedOptions.delete(option) continue @@ -172,6 +173,11 @@ export class TelnetSession extends BaseSession { TelnetOptions.ECHO, ].includes(option)) { this.emitTelnet(TelnetCommands.DO, option) + if (option === TelnetOptions.ECHO && this.streamProcessor.forceEcho) { + this.telnetRemoteEcho = true; + this.streamProcessor.forceEcho = false; + this.requestOption(TelnetCommands.WONT, option); + } } else { this.logger.debug('(!) Unhandled option') this.emitTelnet(TelnetCommands.DONT, option) @@ -182,8 +188,13 @@ export class TelnetSession extends BaseSession { this.emitTelnet(TelnetCommands.WILL, option) this.emitSize() } else if (option === TelnetOptions.ECHO) { - this.streamProcessor.forceEcho = true - this.emitTelnet(TelnetCommands.WILL, option) + if (this.telnetRemoteEcho) { + this.streamProcessor.forceEcho = false; + this.emitTelnet(TelnetCommands.WONT, option) + } else { + this.streamProcessor.forceEcho = true + this.emitTelnet(TelnetCommands.WILL, option) + } } else if (option === TelnetOptions.TERMINAL_TYPE) { this.emitTelnet(TelnetCommands.WILL, option) } else { @@ -197,7 +208,16 @@ export class TelnetSession extends BaseSession { this.emitTelnet(TelnetCommands.WONT, option) } else { this.logger.debug('(!) Unhandled option') - this.emitTelnet(TelnetCommands.WILL, option) + this.emitTelnet(TelnetCommands.WONT, option) + } + } + if (command === TelnetCommands.WONT) { + if (option === TelnetOptions.ECHO) { + this.telnetRemoteEcho = false; + this.emitTelnet(TelnetCommands.DONT, option) + } else { + this.logger.debug('(!) Unhandled option') + this.emitTelnet(TelnetCommands.DONT, option) } } if (command === TelnetCommands.SUBOPTION) { From fa50c7d9fae4b09b39e84d0cb6694fa4c9a50f23 Mon Sep 17 00:00:00 2001 From: DehanLUO Date: Mon, 10 Jul 2023 02:10:54 -0400 Subject: [PATCH 2/2] Stop local echo when remote echo is on --- tabby-telnet/src/session.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tabby-telnet/src/session.ts b/tabby-telnet/src/session.ts index 8c3b1e9b..e094032a 100644 --- a/tabby-telnet/src/session.ts +++ b/tabby-telnet/src/session.ts @@ -174,9 +174,9 @@ export class TelnetSession extends BaseSession { ].includes(option)) { this.emitTelnet(TelnetCommands.DO, option) if (option === TelnetOptions.ECHO && this.streamProcessor.forceEcho) { - this.telnetRemoteEcho = true; - this.streamProcessor.forceEcho = false; - this.requestOption(TelnetCommands.WONT, option); + this.telnetRemoteEcho = true + this.streamProcessor.forceEcho = false + this.requestOption(TelnetCommands.WONT, option) } } else { this.logger.debug('(!) Unhandled option') @@ -189,7 +189,7 @@ export class TelnetSession extends BaseSession { this.emitSize() } else if (option === TelnetOptions.ECHO) { if (this.telnetRemoteEcho) { - this.streamProcessor.forceEcho = false; + this.streamProcessor.forceEcho = false this.emitTelnet(TelnetCommands.WONT, option) } else { this.streamProcessor.forceEcho = true @@ -213,7 +213,7 @@ export class TelnetSession extends BaseSession { } if (command === TelnetCommands.WONT) { if (option === TelnetOptions.ECHO) { - this.telnetRemoteEcho = false; + this.telnetRemoteEcho = false this.emitTelnet(TelnetCommands.DONT, option) } else { this.logger.debug('(!) Unhandled option')