kaddhelp bounce "Manages bounce relays from your ip. '/bounce 1111' will set up a bounce so that people can connect to your ip on port 1111 as a bounce proxy. '/bounce close ' closes all ports matching; '/bounce kill *' kills all bounce connections." "/bounce \[pass\], /bounce kill *, /bounce close " "Bounce Server" alias bounce { set port [lindex [args] 0] set pass [lindex [args] 1] if {$port == ""} {/help [event]} elseif {$port == "kill"} {bounce kill $port} elseif {$port == "close"} {bounce close $port} { if [catch {socket -server [list bounce new $port $pass] $port} socket] { echo "[kano] Error grabbing port '$port': $socket" } { set bncport($port) [list $socket 0] echo "[kano] Listening for bounces on port $port." } } complete } on unload {bounce kill *;bounce close *} proc bounce {cmd args} { global bncinfo bncport bncpass bncwait bncto bnclport if {[lsearch -exact {line new kill} $cmd] != -1} { set port [lindex $args 0] set pass [lindex $args 1] set sock [lindex $args 2] if [catch {lindex [fconfigure $sock -peername] 1} host] { set host [lindex $args 3] } } switch -- $cmd { new { fconfigure $sock -blocking 0 -buffering line -translation {lf lf} fileevent $sock readable [list bounce line $port $pass $sock] bounce puts $sock "NOTICE AUTH :*** Connected to [my_nick]'s bounce." bounce puts $sock "NOTICE AUTH :*** Type '/raw CONN ' to connect to a server." if {$pass != ""} { bounce puts $sock "NOTICE AUTH :*** This bounce is password-protected. Type '/raw PASS ' to log in." set bncpass($sock) 0 } {set bncpass($sock) 1} echo "[kano] [lindex [fconfigure $sock -peername] 1] connected to bounce on port '$port'" set bncport($port) [list [lindex $bncport($port) 0] [expr [lindex $bncport($port) 1] + 1]] set bncwait($sock) [list] set bncto($sock) [list] set bnclport($sock) $port } line { if [catch {gets $sock line}] {bounce kill $port $pass $sock;return} set line [split $line] set incmd [string tolower [lindex $line 0]] set inarg [string trimleft [join [lrange $line 1 end]] :] set inspl [split $inarg] switch -- $incmd { pass { if $bncpass($sock) { bounce puts $sock "NOTICE AUTH :*** You are already logged in. Type '/raw CONN ' to connect to a server." } { set inarg [string trim $inarg] if {$inarg != $pass && $pass != ""} { bounce puts $sock "NOTICE AUTH :*** Sorry, bad pass." echo "[kano] Bad bounce pass from $host on port '$port': $inarg" bounce kill $sock } { set bncpass($sock) 1 bounce puts $sock "NOTICE AUTH :*** Logged in." } } } conn { if $bncpass($sock) { if {[catch {socket -async [lindex $inspl 0] [FALC_port [lindex $inspl 1]]} new]} { bounce puts $sock "NOTICE AUTH :*** Usage: CONN " } { global bncopen set bncopen($new) 0 fileevent $new writable "[list set bncopen($new) 1];fileevent $new writable {}" vwait bncopen($new) set bncinfo($sock) [lrange [fconfigure $new -peername] 1 2] bounce puts $sock "NOTICE AUTH :*** Connected to [join $bncinfo($sock) :]" fconfigure $sock -buffering none -translation {binary binary} fconfigure $new -buffering none -blocking 0 -buffering line -translation {binary binary} puts -nonewline $new [join $bncwait($sock) \n]\n fileevent $sock readable [list bounce relay $sock $new] fileevent $new readable [list bounce relay $new $sock] set bncto($sock) $new echo "[kano] Bounce $host on port 'port' connected to [join $bncinfo($sock) :]" } } { bounce puts $sock "NOTICE AUTH :*** You are not logged in. Use '/raw PASS ' to log in." } } default { lappend bncwait($sock) [join $line] } } } puts { set sock [lindex $args 0] if [catch {puts $sock [lindex $args 1]}] { bounce kill $sock } } relay { set from [lindex $args 0] set to [lindex $args 1] if [catch {unsupported0 $from $to} er] { bounce kill $to bounce kill $from } } kill { set real [lindex $args 0] set ok [catch {close $real}] set sock [array names bncto $real] foreach i $sock { if [catch {fconfigure $i -peername} fs] {set fs [list]} if {![catch {close $i}] || !$ok} { echo "[kano] Disconnected [lindex $fs 1] from bounce on [lindex $bnclport($sock) 0]" } unset bncto($i) } } close { foreach i [array names bncport [lindex $args 0]] { if ![catch {close [lindex $bncport($i) 0]}] { echo "[kano] Closed port $i." } unset bncport($i) } } } }