I have a problem guyz!

I've just "made" a remote script, using mIRC-s TCP/IP socket support in scripts, but it doesn't seem to work well…

This small script "imitates" sock4 proxy functions (there is SOME difference, of course), but it works well ONLY if the connection bitween proxy (===) server can be made. But if the connection is not estabilished bitween Proxy&Server or, if it is estabilished, but only for a second or two (eg. Z-lines), it just doesn't work!

The remote script:

;initalises the script; listening at port 5555 for incoming
;connections. (does'nt check if port 5555 is free, because i
;dont use it for anything else…)

alias Fstart {
var %i $rand(0,3)
hmake -s Fc
while ( $sock($+(Fmulti,%Frand),1) !== $null ) { inc %i 1 }
socklisten $+(Fmulti,%i) 5555
echo 4 *** Listening to incoming connections sockname $+(Fmulti,%i)
}

;accepts the connection and gives it a name btw Firc0-Firc[big integer]
;depending on a random number rnd(0;3) (and depending on the
;names of existing connections)

on *:socklisten:Fmulti*: {
if ( $sockerr != 0 ) { echo 4 *** An Error occured at $sockname | return }
echo 4 *** Incoming connection. $sock($sockname,1).ip
var %i = $rand(0,3)
while ( $sock($+(Firc,%i),1) !== $null ) { inc %i 1 }
sockaccept $+(Firc,%i)
}

;a more complex part of the script. In case it gets a raw
;message starting with PASS[SPACE] it opens a sock at
;the server:port which was given as password.
;Afterwards it just log messages btw. client<->proxy<-
;>server (sends raw messages from client to server and
;from server to client, appends raw text to proxylog.txt)

on *:sockread:Firc*: {
if ( $sockerr != 0 ) { echo 4 *** An Error occured at $sockname | return }
sockread %Ftemp
write c:\extreme\proxylog.txt $timestamp $+(«,$sockname,») %Ftemp
if ( $sock($+(S,$sockname),1) == $null ) {
if ( $gettok(%Ftemp,1,32) !== PASS ) { luzer111 }
else { echo 4 *** $gettok(%Ftemp,2-,32) | sockopen $+(S,$sockname) $iif($chr(58) isin %Ftemp,$replace($gettok(%Ftemp,2-,32),$chr(58),$chr(32)), $gettok(%Ftemp,2-,32) 6667) | hadd -s Fc $+(o,$sockname) $true | hadd -s Fc $sockname 0 }
}
elseif ( $hget(Fc,$+(o,$sockname)) == $true ) { hinc -s Fc $sockname | hadd -s Fc $+($sockname,$hget(Fc,$sockname)) %Ftemp }
else { sockwrite -n $+(S,$sockname) %Ftemp }
}

on *:sockopen:SFirc*: {
while ($hget(Fc,$right($sockname,-1)) > 0) {
sockwrite -n $sockname $hget(Fc,$+($right($sockname,-1),$hget(Fc,$right($sockname,-1))))
hdec -s Fc $right($sockname,-1)
}
hdel -sw Fc *
}

on *:sockread:SFirc*: {
if ( $sockerr != 0 ) { echo 4 *** An Error occured at $sockname | return }
sockread %SFtemp
write c:\extreme\proxylog.txt $timestamp $+(«,$sockname,») %SFtemp
if ($sock($right($sockname,-1)) !== $null ) { sockwrite -n $right($sockname,-1) %SFtemp }
}

on *:sockwrite:SFirc*: {
if ( $sockerr !== 0 ) { echo -4 *** An error occured: $sock().wserr }
}

alias luzer111 { echo 4 *** An Error occured at $sockname | return }

Last edited by n3wb13; 19/09/03 04:29 PM.