Skip to content

Commit

Permalink
Merge pull request #8677 from DehanLUO/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jul 10, 2023
2 parents 77b74ad + fa50c7d commit 57da067
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tabby-telnet/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class TelnetSession extends BaseSession {
private lastWidth = 0
private lastHeight = 0
private requestedOptions = new Set<number>()
private telnetRemoteEcho = false

constructor (
injector: Injector,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 57da067

Please sign in to comment.