alias bncsetup { dialog -mv bnc bnc } alias bnc { if (!$portfree($bnc.port)) { echo -a $bnc.port not available, aborting. | return } if ($sock(bnc.listen)) { echo -a socket unavailable. | return } socklisten bnc.listen $bnc.port bnc.log @bnc *** Bouncer standing by on port $bnc.port echo -s *** Bouncer standing by on port $bnc.port } alias bnc.close { sockclose bnc.* var %i = 1 | while ($hget(%i)) { if ($ifmatch iswm bnc?) hfree $ifmatch | inc %i } }
on *:socklisten:bnc.listen:{ if ($bnc.number >= $bnc.max) return
var %number = $calc($bnc.number + 1), %table = $+(bnc,%number), %win = $+(@bnc,%number), %sock = $bnc.client(%number) sockaccept %sock if ($dialog(bnc)) { did -a bnc 11 %table | if (!$did(bnc,11)) did -c bnc 11 1 }
if ($hget(%table)) hfree %table hmake %table 10 hadd %table connected 0 hadd %table identified 0
bnc.log @bnc *** Incoming connection from $sock(%sock).ip on %table }
on *:sockread:bnc.client.*:{ if ($sockerr) return var %read, %number = $gettok($sockname,3,46), %table = $+(bnc,%number), %win = $+(@bnc,%number) sockread %read while ($sockbr) { ;bnc.log %win client: %read if ($gettok(%read,1,32) == NICK) { hadd %table nick $gettok(%read,2,32) | bnc.log %win NICK $gettok(%read,2,32) } if (!$bnc.sendToServer(%number,%read)) { bnc.doCommand %number %read } if (!$sock($sockname)) return sockread %read } } on *:sockclose:bnc.client.*:{ bnc.closeOne $gettok($sockname,3,46) }
on *:sockopen:bnc.server.*:{ var %number = $gettok($sockname,3,46), %table = $+(bnc,%number), %win = $+(@bnc,%number) if ($sockerr) { bnc.send %number Failed connection | return }
bnc.log %win *** Connection to server established. ;bnc.log %win bouncer: NICK $hget(%table,nick) ;bnc.log %win bouncer: USER $hget(%table,user) hadd %table connected 1 sockwrite -n $sockname NICK $hget(%table,nick) sockwrite -n $sockname USER $hget(%table,user) } on *:sockread:bnc.server.*:{ var %read, %number = $gettok($sockname,3,46), %table = $+(bnc,%number), %win = $+(@bnc,%number) sockread %read while ($sockbr) { ;bnc.log %win server: %read if (!$bnc.sendToClient(%number,%read)) { bnc.closeOne %number } if (!$sock($sockname)) return sockread %read } } on *:sockclose:bnc.server.*:{ bnc.closeOne $gettok($sockname,3,46) }
alias bnc.sendToServer { if ($sock($bnc.server($1)).status != active) return $false sockwrite -n $bnc.server($1) $2 return $true }
alias bnc.sendToClient { if ($sock($bnc.client($1)).status != active) return $false sockwrite -n $bnc.client($1) $2 return $true }
alias bnc.doCommand { var %number = $1, %table = $+(bnc,%number), %win = $+(@bnc,%number) tokenize 32 $2-
if ($1 == NICK) { } elseif (($1 == USER) && (!$hget(%table,user))) { hadd %table user $2- | if (!$hget(%table,identified)) bnc.send %number You need to say /quote PASS } elseif ($1 == PASS) { if ($bnc.checkPass($2)) bnc.id %number | else bnc.closeOne %number } elseif ((!$hget(%table,nick)) || (!$hget(%table,user))) { sockwrite -n $bnc.client(%number) Register first } elseif (!$hget(%table,identified)) { return } elseif ($1 == conn) { bnc.send %number $bnc.reality(%number,$2,$iif($3,$3,$bnc.defaultPort)) } }
alias bnc.reality { var %number = $1, %table = $+(bnc,%number), %win = $+(@bnc,%number) if (!$2) return bnc.log %win *** Connecting to $2- sockopen $bnc.server($1) $2 $3 hadd $+(bnc,$1) server $2 return Making reality through $2 port $3 }
alias bnc.id { var %number = $1, %table = $+(bnc,%number), %win = $+(@bnc,%number) hadd %table identified 1 bnc.log %win identified
bnc.send $1 Welcome to mIRC bnc, irc proxy bnc.send $1 Level two, lets connect to something real now bnc.send $1 type /quote conn [port] to connect ;bnc.send $1 type /quote help for basic list of commands and usage }
alias bnc.closeOne { if ($sock($+(bnc.client.,$1))) sockclose $ifmatch if ($sock($+(bnc.server.,$1))) sockclose $ifmatch if ($hget($+(bnc,$1))) hfree $ifmatch linesep $+(@bnc,$1) if ($dialog(bnc)) { did -d bnc 11 $didwm(bnc,11,$+(bnc,$1)) | if (!$did(bnc,11)) did -c bnc 11 1 | bnc.stats } }
alias bnc.log { if (!$readini($bnc.file,n,settings,statuswin)) return | if (!$window($1)) window $1 | echo -t $1 $2- } alias bnc.amsg { var %i = 1 | while ($sock(bnc.*,%i)) { if (bnc.client.? iswm $ifmatch) bnc.send $right($sock(bnc.*,%i),1) $1- | inc %i } } alias bnc.send { sockwrite -n $bnc.client($1) NOTICE AUTH $+(:,$2-) |;bnc.log $+(@bnc,$1) bouncer: $2- } alias bnc.checkpass { if ($1 === $readini($bnc.file,n,settings,pass)) return $true | return $false } alias bnc.number { var %i = 1 | while ($sock($+(bnc.client.,%i))) { inc %i } | return %i } alias bnc.max { return $readini($bnc.file,n,settings,users) } alias bnc.server { return $+(bnc.server.,$1) } alias bnc.client { return $+(bnc.client.,$1) } alias bnc.defaultPort { return 6667 } alias bnc.port { return $iif($readini(bnc.ini,n,settings,port),$ifmatch,6667) }
on *:input:@bnc:{ sockwrite bnc.client.1 $1- }
dialog bnc { title "bnc" size -1 -1 220 110 option dbu
box "", 1, 1 0 109 108 box "", 2, 110 0 109 108
check "Show status win", 3, 5 10 50 7
text "Port:", 4, 5 25 20 7 edit "", 5, 40 23 20 10 text "Max Users", 6, 5 35 30 7 edit "", 7, 40 33 20 10 text "Password:", 8, 5 45 30 7 edit "", 9, 40 43 50 10, autohs
text "Show Stats:", 10, 5 60 30 7 combo 11, 40 58 50 100, drop vsbar
button "Send Announcement", 13, 5 75 65 11
text "IP:", 51, 115 15 25 7, right disable text "", 52, 150 15 60 7 text "Nick:", 53, 115 25 25 7, right disable text "", 54, 150 25 60 7 text "Server:", 55, 115 35 25 7, right disable text "", 56, 150 35 60 7 text "Identified:", 57, 115 45 25 7, right disable text "", 58, 150 45 20 7
button "Message", 59, 115 75 30 11, disable button "Kick", 60, 150 75 30 11, disable button "Refresh", 61, 185 75 30 11, disable
button "OK", 97, 5 93 30 11, ok button "Cancel", 98, 40 93 30 11, cancel button "Apply", 99, 75 93 30 11 }
on *:dialog:bnc:init:0:{ var %i = 1 | while ($sock(bnc.*,%i)) { if (bnc.client.? iswm $ifmatch) did -a $dname 11 $+(bnc,$right($sock(bnc.*,%i),1)) | inc %i } if ($readini($bnc.file,n,settings,statuswin)) did -c $dname 3 if ($readini($bnc.file,n,settings,port)) did -a $dname 5 $ifmatch if ($readini($bnc.file,n,settings,users)) did -a $dname 7 $ifmatch if ($readini($bnc.file,n,settings,pass)) did -a $dname 9 $ifmatch did -c $dname 11 1 bnc.stats }
on *:dialog:bnc:sclick:97:{ bnc.save } on *:dialog:bnc:sclick:99:{ bnc.save } on *:dialog:bnc:sclick:13:{ bnc.amsg Announcement: $$input(Enter message,1,Send Announcement) } on *:dialog:bnc:sclick:11:{ bnc.stats } on *:dialog:bnc:sclick:59:{ bnc.send $right($did(11).seltext,1) $input(Enter message,1,Message User) } on *:dialog:bnc:sclick:60:{ var %number = $right($did(11).seltext,-3) var %reason = $input(Enter reason,1,Kick user) bnc.send %number Closing connection $+($chr(40),%reason,$chr(41)) bnc.closeOne %number } on *:dialog:bnc:sclick:61:{ bnc.stats }
alias bnc.save { if ($did(3)) writeini $bnc.file settings statuswin $did(3).state if ($did(5)) writeini $bnc.file settings port $did(5) if ($did(7)) writeini $bnc.file settings users $did(7) if ($did(9)) writeini $bnc.file settings pass $did(9) if (($sock(bnc.listen)) && ($sock(bnc.listen).port != $did(5))) { sockclose bnc.listen | bnc } }
alias bnc.stats { if (!$did(bnc,11)) { did -b bnc 51,53,55,57,59,60,61 | did -r bnc 52,54,56,58 | return } var %number = $right($did(bnc,11).seltext,1), %table = $+(bnc,%number) did -e bnc 51,53,55,57,59,60,61 did -ra bnc 52 $sock($bnc.client(%number)).ip did -ra bnc 54 $hget(%table,nick) did -ra bnc 56 $iif($hget(%table,connected),$hget(%table,server),N/A) did -ra bnc 58 $iif($hget(%table,identified),yes,no) }
alias bnc.file return bnc.ini
|