• Welcome to Valhalla Legends Archive.
 

Local D2 Proxy

Started by pianka, August 05, 2008, 08:15 PM

Previous topic - Next topic

pianka

I know this has been done before.  I searched through everything I could before posting here but I can't find any other problems with these symptoms.  So this is just a few sockets that receive a connection to Battle.net (I plan to use for Diablo II obviously), connect to Battle.net and relay data between the two. Simple.

I wrote the code in like 5 minutes, it logged on and worked fine the first few times.  So I started adding support for the MCP and D2GS servers, still pretty simple.  Periodically the BNCS connection from Diablo II would stop the login sequence after 0x50 (never sent 0x51), I'd have to reset the sockets and it would work again.  The frequency of it randomly not working increased dramatically to the point where it doesn't work at all any more.  Remember, it originally worked flawlessly.

So to make sure I wasn't crazy, I set up really really basic code to test it out:

(Two sockets on a form named sin and sout)

Private Sub Form_Load()
    sout.Connect "useast.battle.net", 6112
   
    With sin
        .Close
        .LocalPort = 6112
        .Listen
    End With
End Sub

Private Sub sin_ConnectionRequest(ByVal requestID As Long)
    sin.Close
    sin.Accept requestID
End Sub

Private Sub sin_DataArrival(ByVal bytesTotal As Long)
    Dim temp As String
   
    sin.GetData temp, vbString
    sout.SendData temp
End Sub

Private Sub sout_DataArrival(ByVal bytesTotal As Long)
    Dim temp As String
   
    sout.GetData temp, vbString
    sin.SendData temp
End Sub


This code has the exact same result with the Diablo II client and with the Starcraft client.  However, if I connect my chat bot to 127.0.0.1, it's flawless.  I'm at a complete loss right now, I have no idea what could be causing this.  I tried switching the sockets over to API instead of the ActiveX control and that didn't work either.

Additionally there are programs that do the same thing I'm trying to do like RedVex.  I downloaded and set up RedVex...and it worked.  So my Diablo II client is fine, the concept of a local d2 proxy is fine, and my code correctly relays data.  Still doesn't work.

So my question is, has anybody encountered this before, or is anybody aware of something implemented to disallow someone to proxy the game client connections?

Thanks in advance.

Barabajagal

Uh... for D2GS and MCP... the server IP the game connects to is sent in a packet... I don't see any code for finding and modifying that.

pianka

#2
I didn't post my whole original source, I just posted the most basic way of setting up what it's supposed to be doing and it's not working.  I'm not going to have to worry about MCP and D2GS until the Diablo II client does something after receiving an affirmation on 0x50.  If there's anything that I could post that would give you a better idea of what's going on, I'll throw it up here.

Ringo

Didn't read the thread, mainly just the code, but its clear where you will encounter a problem.
You must wait for bnet to accept before you can send data to it, and its safe to say the client will have sent you the protocol byte and its 1st packet(s) before that time.


Private sinData as string

Private Sub Form_Load()
    sout.Connect "useast.battle.net", 6112
    sinData=vbnullstring
    With sin
        .Close
        .LocalPort = 6112
        .Listen
    End With
End Sub

Private Sub sin_ConnectionRequest(ByVal requestID As Long)
    sin.Close
    sin.Accept requestID
End Sub

Private Sub sin_DataArrival(ByVal bytesTotal As Long)
    Dim temp As String
   
    sin.GetData temp, vbString
    if sout.state=sckconnected then
        sout.SendData temp
    else
        sinData = sinData & temp
    end if
End Sub

Private Sub sout_connect()
    if len(sinData) then
        sout.SendData sinData
        sinData=vbnullstring
    end if
End Sub

Private Sub sout_DataArrival(ByVal bytesTotal As Long)
    Dim temp As String
   
    sout.GetData temp, vbString
    sin.SendData temp
End Sub


hope this helps.

pianka

I do, that's why Battle.net connects first, and then I listen on port 6112.  Once it's connected to Battle.net, I connect my D2 client.  Remember what I said, the code works with a bot.

Ringo

#5
Quote from: PiaNKA on August 07, 2008, 05:55 PM
I do, that's why Battle.net connects first, and then I listen on port 6112.  Once it's connected to Battle.net, I connect my D2 client.  Remember what I said, the code works with a bot.
Ah, I didn't know you're test code worked the same as you're orginal code, since I brushed over this:
Quote
So to make sure I wasn't crazy, I set up really really basic code to test it out:

Reading the whole thread, I'm still unsure exacly what the problem is.
Is it, you get no responce from battle.net after fawarding the clients 0x50 message?
Quote
This code has the exact same result with the Diablo II client and with the Starcraft client.  However, if I connect my chat bot to 127.0.0.1, it's flawless.
Do you also connect D2/SC to the lan address, or you're internet address?
Because it sounds like it's a problem with the winsock's send method its self.
I have found the .senddata() sub in the winsock control, for TCP, is crap.
Have you tryed useing the send() API? because if data is getting stuck on the winsocks buffer, like .senddata() is good at doing, that could be why you don't get a responce from bnet.
But I notice you also say:
Quote
I tried switching the sockets over to API instead of the ActiveX control and that didn't work either.
So i'm not sure.
Do you check for connection closes and error's from bnet, and close the clients sockets and vise verser?
Could be, bnet is disconnecting you.
But, the most logical reassion, would be the client is trying to connect to you're gateway with the FTP protocol, to download a checkrevision mpq, but since you closed the server socket to accept the game clients connection, it will get no answer, hence will never beable to fire off an 0x51.
If thats the case, and probly is, then you need to have a socket array, socket(0) always listens, then on a connection request, load socket(ubound+1) or look up an avalible offline socket, and accept the connection with it.
Does the chat bot you use, support FTP file downloading? I'm guessing, it doesnt, hence has no issue.

If its none of them things you're going to have to explain what you're doing and greater detail of the effects of the symptom's. Other wise, it's just going to be a guessing game.

If data is bufferd or can't be lost between the connection process, the next thing I would look into is if FTP connection requests are being blocked due to no socket listening for them, failing that, the .senddata() issue.

I wrote one of the very 1st D2/Realm/Game proxys years ago, but never once encounterd a problem like this that wasn't fixed with the above.

pianka

I receive a 0x50 response, confirming that it worked, the client just never sends 0x51.  Like you said, I did try switching all of the socket code over to the API without any improvement.  I had not considered the FTP issue...my bot does have FTP support though it doesnt require it.  I have a feeling that this is most likely the issue, although I'm not sure why it would have worked originally.  Do the checkrevision MPQs expire, causing the client to redownload them?

Ringo

Quote from: PiaNKA on August 11, 2008, 03:17 PM
I receive a 0x50 response, confirming that it worked, the client just never sends 0x51.  Like you said, I did try switching all of the socket code over to the API without any improvement.  I had not considered the FTP issue...my bot does have FTP support though it doesnt require it.  I have a feeling that this is most likely the issue, although I'm not sure why it would have worked originally.  Do the checkrevision MPQs expire, causing the client to redownload them?

The bnet server will select a checkrevision mpq at random for an 0x50,0x51 logon, so it would make sence, since you're client probly only has a few of them mpq's.
You could add support for FTP or just connect alot to some random bnet server like asia untill you feel the client has all the mpqs in its cache.
I advise adding ftp support tho, since if you're useing d2 loader (or in some cases just normal d2) it will download files it already has.

With out them mpqs, the client can't do checkrevision.

pianka

Added a bnftp socket and it works, thanks Ringo :).