mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 3
W
weezy Offline OP
Self-satisified door
OP Offline
Self-satisified door
W
Joined: Aug 2004
Posts: 3
I am trying to create a socket DCC emulation for a bot I am making, and although I have been able to do it in the past I have forgot 1 key bit of information.

I know that after every packet is received that the receiver must send an ack to the sender of the total filesize already downloaded. I can't remember, however, what format this filesize is sent in. iirc, it was $longip(blah) and to do with a binvar but I'm really at a loss here.

------

Well, looks like I replied to my own thread without anyone even viewing it!

In case anyone cared (?), here is the code:

bset &size 1 $replace($longip($file(<local filename>).size),$chr(46),$chr(32))
sockwrite $sockname &size

Last edited by weezy; 31/08/04 07:02 PM.
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
Sending via Sock, would be SOMETHING like the following, although sending to yourself, may or may not break this code, since the $sock().queue may exceed, but sending to others should work just fine.

The below code is the alias that starts everything, /socksend nickname C:\directory\to\file.exe, note there is NO verification or checking in these, you can add them (if this is what your after) yourself.

What it does is basically send the info needed to start it all off, basically the NOTICE and the MSG line, where the syntax is:

NOTICE nickname DCC Send filename.exe (your.ip.address)

MSG nickname $chr(1) $+ DCC SEND filename.exe $longip(your.ip.address) port filesize $+ $chr(1)

It picks a RANDOM port between 1024 and 5000, again there is no verification to see if hte port is already open ($portfree) it then listens on that port and saves the filename in "sockmark".

In case your wondering, in DCC send, the other person OPENs the socket to you, not vice-a-versa.

alias socksend {
if ($1) {
NOTICE $1 DCC Send $nopath($2-) ( $+ $ip $+ )
var %p = $rand(1024,5000)
MSG $1 $+($chr(1),DCC) SEND $nopath($2-) $longip($ip) %p $+($file($2-),$chr(1))
sockclose $+(tmpsocksend.,%p)
socklisten $+(tmpsocksend.,%p) %p
sockmark $+(tmpsocksend.,%p) $+(",$2-,")
}
}

The following detects the recieving user connecting to you and accepts the socket and begins sending the first few bytes of the file.

On *:Socklisten:tmpsocksend.*:{
sockaccept $remove($sockname,tmp)
sockmark $remove($sockname,tmp) $sock($sockname).mark
echo -s Accepted.
sock.sendfile $remove($sockname,tmp) $sock($sockname).mark
sockclose $sockname
}

The following alias is the alias used to "start" the dcc send, by sending the first 8192 bytes of the file and storing a variable againest the amount in bytes have been sent already.

alias sock.sendfile {
echo -s Starting DCC Send. ( $+ $1 $+ / $+ $2- $+ )
set $+(%,$1) 0
bread $2- $eval($+(%,$1),2) 8192 $+(&,$1)
sockwrite $1 $+(&,$1)
inc $+(%,$1) 8192
}

This triggers AFTER you have /sockwrite'd (everytime you send part of the time), and basically sends the next part.

On *:Sockwrite:socksend.*:{
if ($file($sock($sockname).mark) >= $eval($+(%,$sockname),2)) {
bread $sock($sockname).mark $eval($+(%,$sockname),2) 8192 $+(&,$sockname)
sockwrite $sockname $+(&,$sockname)
inc $+(%,$sockname) 8192
echo -a Sent, $eval($+(%,$sockname),2) Bytes. ( $+ $sockname $+ / $+ $sock($sockname).mark $+ )
}
}

Eamonn.

Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
For the purpose of completing this should anyone else wish to use it, the following will receive a file with mIRCs help.

The coding directly below simply acknowledges the DCC send request, this is done with ctcp, however if your using the code for a sockbot, obviously this would be checked inside on sockread instead.

ctcp ^*:*:*:{
if ($1-2 == DCC SEND) {
sockclose $+(sockrcvd.,$3)
sockopen $+(sockrcvd.,$3) $longip($4) $5
sockmark $+(sockrcvd.,$3) $6
haltdef
}
}

The following basically just recieves the file and write it to $getdir with the given filename, again there is no vertification/validation.

On *:Sockread:sockrcvd.*:{
var %f = $+(",$getdir,$gettok($sockname,2-,46),")
if (!$isfile(%f)) { write -c %f }
sockread $+(&,$sockname)
bwrite %f -1 -1 $+(&,$sockname)
echo Receiving; $file(%f)) of, $sock($sockname).mark Bytes.
}

Eamonn.

Joined: Aug 2004
Posts: 3
W
weezy Offline OP
Self-satisified door
OP Offline
Self-satisified door
W
Joined: Aug 2004
Posts: 3
I did edit my post several minutes after I made it, but seeing as I didn't delete it...

The reason that script overflows is because it doesn't require a ACK to keep on sending. The ACK is what I was asking for help with, if you see my first post I have added there how to send an ACK to avoid a buffer overflow, you can reverse translate that so that you don't get an overflow for your script as well.

Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
The single line you pasted doesnt really help any, paste the few lines either side.

Eamonn.

Joined: Aug 2004
Posts: 3
W
weezy Offline OP
Self-satisified door
OP Offline
Self-satisified door
W
Joined: Aug 2004
Posts: 3
Try writing a script to receive files without putting that line in there, you'll end up in tears.


Link Copied to Clipboard