if {![info exists ownfullname]} { set ownfullname "here to Help" }
set ownmailaddr blight@chiark.greenend.org.uk
+set musthaveping_ms 10000
set out_maxburst 6
set out_interval 2100
set out_lag_lag 5000
set out_lag_very 25000
-if {![info exists out_queue]} {
- set out_creditms [expr {$out_maxburst*$out_interval}]
- set out_creditat [clock seconds]
- set out_queue {}
- set out_lag_reported 0
- set out_lag_reportwhen $out_creditat
-}
-
-if {![info exists globalsecret]} {
- set gsfile [open /dev/urandom r]
- fconfigure $gsfile -translation binary
- set globalsecret [read $gsfile 32]
- binary scan $globalsecret H* globalsecret
- close $gsfile
- unset gsfile
-}
-
proc manyset {list args} {
foreach val $list var $args {
upvar 1 $var my
proc onread {args} {
global sock nick calling_nick errorInfo errorCode
- if {[gets $sock line] == -1} { set terminate 1; return }
+ if {[gets $sock line] == -1} { fail "EOF/error on input" }
regsub -all "\[^ -\176\240-\376\]" $line ? line
set org $line
}
proc msg_PING {p c s1} {
+ global musthaveping_after
prefix_none
sendout PONG $s1
+ if {[info exists musthaveping_after]} { after cancel $musthaveping_after] }
}
proc check_nick {n} {
ucmdr {} $rstr
}
-if {![info exists sock]} {
+proc ensure_globalsecret {} {
+ global globalsecret
+
+ if {[info exists globalsecret]} return
+ set gsfile [open /dev/urandom r]
+ fconfigure $gsfile -translation binary
+ set globalsecret [read $gsfile 32]
+ binary scan $globalsecret H* globalsecret
+ close $gsfile
+ unset gsfile
+}
+
+proc ensure_outqueue {} {
+ out__vars
+ if {[info exists out_queue]} return
+ set out_creditms [expr {$out_maxburst*$out_interval}]
+ set out_creditat [clock seconds]
+ set out_queue {}
+ set out_lag_reported 0
+ set out_lag_reportwhen $out_creditat
+}
+
+proc fail {msg} {
+ logerror "failing: $msg"
+ exit 1
+}
+
+proc ensure_connecting {} {
+ global sock ownfullname host port nick
+ global musthaveping_ms musthaveping_after
+
+ if {[info exists sock]} return
set sock [socket $host $port]
fconfigure $sock -buffering line
- #fconfigure $sock -translation binary
fconfigure $sock -translation crlf
sendout USER blight 0 * $ownfullname
sendout NICK $nick
fileevent $sock readable onread
+
+ set musthaveping_after [after $musthaveping_ms \
+ {fail "no ping within timeout"}]
}
+ensure_globalsecret
+ensure_outqueue
loadhelp
+ensure_connecting
#if {![regexp {tclsh} $argv0]} {
# vwait terminate