mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2003
Posts: 6
N
n3wb13 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Sep 2003
Posts: 6
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.
Joined: Sep 2003
Posts: 6
N
n3wb13 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Sep 2003
Posts: 6
Anyone able to recommend a possible soultion to this problem?

(If it's not clear, how the script is supposed to work ask & i will explain the unclear parts in details)

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
You should add a $sockerr check to the Sockopen event of SFirc*, to detect whether there was an error connecting the server and either inform the client or disconnect it from your proxy.

Also, add an on Sockclose event for both server and client connections, where you will disconnect the other side as well from your proxy.

If you're interested, here's a similar script I made a while ago. Just type /bnc <port> to listen for incoming connections, and /server <your ip> <port> <server ip>:<port> to use it for a remote connection.

Joined: Sep 2003
Posts: 6
N
n3wb13 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Sep 2003
Posts: 6
Thanks! That's more than what I requested :-)

The only small difference btw. the two versions (apart from that your's is a lot clearer, more logical, and thanks to the use of local variables, parses faster), that mine can handle multiple connections at a time (there must be at least 10-15 seconds btw the estabilishment of these connections, though - because of the way it adds-deletes hash table items), which was crucial for my purpose smile

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Yea, a decent IRC Proxy must be able to handle multiple connections, though this one was written for a friend whose ISP was banned from DALnet and only needed someone to connect through.


Link Copied to Clipboard