mIRC Home    About    Download    Register    News    Help

Topic Options
#98275 - 22/09/04 03:21 AM Sockets and Dcc chat
QbMaster Offline
Bowl of petunias

Registered: 22/09/04
Posts: 2
Hi, I need to know if there is any way that I can get a dcc chat session to be accepted, and can chat through that dcc session all through mIRC sockets. I have quite a bit of knowledge on mirc's sockets, but it seems that to get the socket to be accepted, I need the name of the socket...which is not available in a dcc chat.

Also I'm trying to do the reverse and start a dcc chat with somebody through sockets as well.

Anybody have any ideas?

Top
#98276 - 22/09/04 06:44 AM Re: Sockets and Dcc chat
Armada Offline
Fjord artisan

Registered: 26/03/04
Posts: 540
You doing DCC on the other end? other wise Id use udp packets to and from for a external chatting session

Top
#98277 - 22/09/04 07:11 AM Re: Sockets and Dcc chat
Coolkill Offline
Hoopy frood

Registered: 09/12/02
Posts: 788
Loc: Wales, United Kingdom.
You can do it pretty simply.

How it works, basically

Basically, it works in the following simple steps.

1. You send a message to nick with your IP and a free Port number.

2. You listen on that port number for a connection.

3. nick connects to that port.

4. You accept the connection.

..and thats it.

Opening a DCC Chat

[color:orange]; The main alias, syntax; /opensockdcc [color:red]nickname
[/color]
alias opensockdcc {
; variable to record number of port finding retries
var %r = 10
; while the port isnt free, and %r > 0, prevents flood.
while ((!$portfree(%p)) && (%r)) {
; get port number between X-Y, that are given in your mirc settings (def; 1024-5000)
var %p = $rand($gettok($readini($mircini,options,n4),13,44),$gettok($readini($mircini,options,n4),26,44))
; decrease the number of retries
dec %r
; end while loop
}
; if %r < 0, then we couldnt find free port, exit.
if (!%r) { echo -s FAILED; Could not assign port. | return }
; create sock name in var
var %s = $+(lis.sockdcc.,$1,.,%p)
; send DCC Chat protocol to $1
.notice $1 DCC CHAT ( $+ $ip $+ )
.msg $1 $+($chr(1),DCC CHAT chat,$chr(32),$longip($ip) %p)
; open the free port to listen for connection.
socklisten %s %p
; end alias
}
[/color]
Accepting the incoming response

[color:orange]; listen for incoming connection

On *:Socklisten:lis.sockdcc.*:{
; accept the connection
sockaccept $remove($sockname,lis.)
; echo to confirm
echo - Connected to DCC session.
; end sock listen
}
[/color]
Getting what they type.

[color:orange]; wait for sockread to trigger

On *:Sockread:sockdcc.*:{
; save content to variable
sockread %sockread
; output variable
echo Recieved: %sockread
; end sockread
}
[/color]
Typing back

[color:orange]; alias to send message, syntax, /sockmsg [color:red]nickname message
[/color]
alias sockmsg {
; complete the sockname (search for it)
var %s = $sock($+(sockdcc.,$1,.*),1)
; if doesnt exist, exit
if (!%s) { echo Cannot find chat. }
; otherwise, send your message to it.
else { sockwrite -n %s $2- }
; end alias
}
[/color]
End Session

[color:orange]; alias to end session, syntax, /sockend [color:red]nickname
[/color]
alias sockmsg {
; complete the sockname (search for it)
var %s = $sock($+(sockdcc.,$1,.*),1)
; if doesnt exist, exit
if (!%s) { echo Cannot find chat. }
; otherwise, close it.
else { sockclose %s }
; end alias
}
[/color]
/opendccsock [color:red]nickname[/color]

Eamonn.

Top
#98278 - 22/09/04 07:36 AM Re: Sockets and Dcc chat
Coolkill Offline
Hoopy frood

Registered: 09/12/02
Posts: 788
Loc: Wales, United Kingdom.
Then, to RECIEVE a DCC Chat, via sockets, and not using mIRCs default window/ect.

How it works

1. You recieve DCC request, that contains PORT/IP.

2. You connect to IP/Port.

3. ..thats it.

Recieving the DCC Request

The request comes in the form of a CTCP, so lets monitor them.

[color:orange]; monitor all ctcps.

ctcp *:*:*:{
; identify if its a dcc chat
if ($1-3 == DCC CHAT chat) {
; if so dream up a socket name.
var %s = $+(sockrcv.,$nick,.,$5)
; open that socket to the given ip/port.
sockopen %s $longip($4) $5
; stops mirc from responding by default
haltdef
; end if.
}
; end ctcp event.
}
[/color]
Receiving what was said..

[color:orange]; monitor incoming data from that socket

On *:Sockread:sockrcv.*:{
; save to variable
sockread %sockread
; output it.
echo -> $gettok($sockname,2,46) $+ ; %sockread
; end sockread
}
[/color]
With minor adjustments these both will work together without duplication of events being required, i.e. to close a socket, or send data..

Hope these help.

Eamonn.

Top