Browse Source

fix reset options between telnet sessions

master
Julian Noble 9 months ago
parent
commit
17e82df5d9
  1. 22
      src/modules/punk/basictelnet-999999.0a1.0.tm

22
src/modules/punk/basictelnet-999999.0a1.0.tm

@ -211,10 +211,18 @@ namespace eval punk::basictelnet {
#not all these will make sense as a boolean? review.
#we use this also to support the Status option
#this structure doesn't retain which side initiated - but it appears from the nature of the protocol that isn't always determinable or of importance.
dict for {k _v} $optioncodes {
dict set server_option_state $k 0 ;#DO from our perspective
dict set client_option_state $k 0 ;#WILL from our perspective
proc reset_option_states {} {
variable optioncodes
variable server_option_state
variable client_option_state
dict for {k _v} $optioncodes {
dict set server_option_state $k 0 ;#DO from our perspective
dict set client_option_state $k 0 ;#WILL from our perspective
}
}
reset_option_states ;#initialise to NVT - all off
# -----------------------------------
# A rudimentary hardcoded configuration for options/negotiation
@ -373,6 +381,8 @@ namespace eval punk::basictelnet {
}
proc telnet {{server localhost} {port telnet}} {
#todo - allow telnet with channels other than stdin/stdout - and multiple sessions - per session option_states
reset_option_states
set sock [socket $server $port]
#fconfigure $sock -buffering none -blocking 0 -encoding binary -translation crlf -eofchar {}
fconfigure $sock -buffering none -blocking 0 -encoding binary -translation binary -eofchar {}
@ -847,6 +857,7 @@ namespace eval punk::basictelnet {
if {[dict get $server_option_state $opdec]} {
#already known DO
} else {
append debug_info ">>>responding to server WILL declaration. DO $opdec [dict get $optioncodes $opdec]" \n
puts -nonewline $sock \xff\xfd$byte ;#respond DO
dict set server_option_state $opdec 1
}
@ -858,6 +869,7 @@ namespace eval punk::basictelnet {
incr idx
}
fc {# WON'T - 252
#todo
dict set server_option_state $opdec 0
incr idx
}
@ -868,14 +880,14 @@ namespace eval punk::basictelnet {
if {[dict get $client_option_state $opdec]} {
#already stored WILL
} else {
append debug_info ">>>responding to DO. WILL $opdec [dict get $optioncodes $opdec]" \n
append debug_info ">>>responding to server DO request. WILL $opdec [dict get $optioncodes $opdec]" \n
puts -nonewline $sock \xff\xfb$byte ;#respond WILL
dict set client_option_state $opdec 1
#immediate followup for NAWS (negotiate about window size)
flush $sock
if {$opdec == 31} {
#IAC SB NAWS c1 c2 r1 r2 IAC SE - where c1 c2 are 2 bytes for cols, r1 r2 are 2 bytes for rows - (unless any of the bytes is \xFF in which case it's doubled-up as per telnet protocol)
append debug_info ">>> sending window_size $::punk::basictelnet::window_cols $::punk::basictelnet::window_rows"
append debug_info ">>> sending window_size $::punk::basictelnet::window_cols $::punk::basictelnet::window_rows <<<\n"
sb_send_window_size $sock $::punk::basictelnet::window_cols $::punk::basictelnet::window_rows
}
}

Loading…
Cancel
Save