• Welcome to Valhalla Legends Archive.
 

Hanging on Connection (Winsock)

Started by Dark-Feanor, December 25, 2003, 01:05 AM

Previous topic - Next topic

Dark-Feanor

When I am connecting to battle.net, it seems like the packets are queued and dataarrival is not called. Sometimes it connects all the way. Sometimes it does not. Once I send a chat packet to battle.net (during the hanging) my client reads the next packet, although I am then IPbanned for sending chat during the connection sequence. Here is an example of what would happen.
Quote
BNET: Connecting....
BNET: Connected
(hangs)
<username> randomtext!
BNET: 0x51 Recieved
I have no idea what is causing this and why dataarrival does not seem to be called.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

You've given us nothing to go by in assisting you.  But I suspect your winsock control usage is not solid.  Show me your DataArrival?  Are you buffering the data to a queue, then processing it separately?

Dark-Feanor

#2
My data arrival sub looks something like this:


Private Sub sckbnet_DataArrival(ByVal bytesTotal As Long)
   Static strBuffer As String
   Dim strTemp As String, lngLen As Long
      strBuffer = strBuffer & strTemp
      While Len(strBuffer) > 4
        lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
        If Len(strBuffer) < lngLen Then Exit Sub
           Bnet.parseBNET (Left(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
           strBuffer = Mid(strBuffer, lngLen + 1)
       Wend
end sub

iform is the index of the form sending the parse request.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

Obviously you don't really want help.

Post your real DataArrival, unmodified, or don't post at all.

CupHead

One of the more crucial parts you are missing, edited out or not, is sckbnet.GetData strTemp

Other than that, I'll have to agree with what Grok said.

TheMinistered

#5
I would assume that he did not edit out the call to GetData.  Why would I say this?  Simple, what we he have to loose by posting a call to GetData?  It simply reveals no secrets whatsoever.  I am a mindreader! woohoo!

So, my suggestion is you add the call to GetData to your code... it helps a bunch!

Dark-Feanor

#6
I edited out some stuff, because it has to do with proxy connection and the problem is not in the proxy code at all, but whatever here is the entire thing:

Private Sub sckbnet_DataArrival(ByVal bytesTotal As Long)
   Static strBuffer As String
   Dim strTemp As String, lngLen As Long
   sckbnet.GetData strTemp, vbString
   If proxyuse = True Then
       If sock5use = False Then
           If connected = False Then
               Select Case Mid(strTemp, 1, 2)
                   Case Chr(0) & Chr(&H5A)
                       connected = True
                       addchat3 iform, vbGreen, "SOCK4: Request Granted"
                       AddChat2 vbGreen, "SOCK4: Request Granted"
                       sckbnet.SendData Chr(1)
                       BNLS.p0x50 iform, product
                       Exit Sub
                   Case Chr(0) & Chr(&H5B)
                       addchat3 iform, vbRed, "SOCK4: Request Rejected Or Failed"
                       AddChat2 vbRed, "SOCK4: Request Rejected Or Failed"
                       BNLS.recon (iform)
                       Exit Sub
                   Case Chr(0) & Chr(&H5C)
                       addchat3 iform, vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
                       AddChat2 vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
                       Call BNLS.recon(iform)
                       Exit Sub
                   Case Chr(0) & Chr(&H5D)
                       addchat2 vbRed, "SOCK4: Request Rejected Because the Client Program and the ID Report Different User-IDs"
                       AddChat2 vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
                       Call BNLS.recon(iform)
                       Exit Sub
                   Case Else
                       addchat3 iform, vbYellow, "SOCK: Proxy Detected as SOCK5, Switching Connection Sequence"
                        sckbnet.Close
                        Call sock5
                        Exit Sub
               End Select
           End If
       Else
               Select Case Mid(strTemp, 1, 5)
               Case Chr(0) & Chr(&H5)
                   Dim splt() As String, str As String, i As Integer
                   server = LCase(server)
                   splt = Split(server, ".")
                   For i = 0 To UBound(splt)
                       str = str & Chr(CStr(splt(i)))
                   Next i
                   sckbnet.SendData Chr(5) & Chr(1) & Chr(0) & Chr(1) & str & Chr(&H17) & Chr(&HE0)
                   Exit Sub
               Case Chr(5) & Chr(0) & Chr(0) & Chr(1) & Chr(&HC8)
                   addchat3 iform, vbGreen, "SOCK5: Request Granted"
                   AddChat2 vbGreen, "SOCK5: Request Granted"
                   sckbnet.SendData Chr(1)
                   BNLS.p0x50 iform, product
                   Exit Sub
           End Select
       End If
   strBuffer = strBuffer & strTemp
   While Len(strBuffer) > 4
       lngLen = Val("&H" & StrToHex(StrReverse(Mid$(strBuffer, 3, 2))))
       If Len(strBuffer) < lngLen Then Exit Sub
           bnet.parseBNET (Left$(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
           strBuffer = Mid$(strBuffer, lngLen + 1)
       Wend
   Else
      strBuffer = strBuffer & strTemp
      While Len(strBuffer) > 4
        lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
        If Len(strBuffer) < lngLen Then Exit Sub
           bnet.parseBNET (Left(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
           strBuffer = Mid(strBuffer, lngLen + 1)
       Wend
   End If
End Sub

I have been running through my code a few times with the debugger, and I think that it is just not called at all. I will try what theministered said and call this function somewhere in the code where it is hanging and see what happens.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

Trying to step through this in a debugger will continue to mess with your mind.  Add a logging function, use the ubiquous DebugOutput, or something else, to create a dump log.  Don't try to interfere with Visual Basic receiving data or you'll miss DataArrival events.  When you miss those (because you're already in DataArrival), they don't happen again.  Therefore, you get out of sync with the server.

Try troubleshooting your connection in runtime by examining logs of SND/RCV.  Much easier.

Grok

First problem I saw was your indenting.  Fix the indenting.

From a code manageability viewpoint, I noticed in your DataArrival you are including business logic and transmitting more data.  Both of those should have their own routines.  You can't be receiving data while simultaneously figuring out what to do with it, and sending out more data.  You can, but it gets hard to manage.

Rearrange it so DataArrival does nothing but buffer the data received.  It's not necessary for you to respond to it so suddenly.

Rearrange your sending so there's only one function that can send data over the winsock control.  That function will only do one thing, and that's send the data in the packet buffer.  The send function would be using the proxyuse, socks5use, and connected booleans to decide how to transmit, exactly.

Once you've separated the network from the transport, and that from the presentation and application, it gets pretty easy to see what's going on.

Spht

Quote from: DaRk-FeAnOr on December 25, 2003, 02:04 AM

      While Len(strBuffer) > 4


It seems here that if Battle.net sends you a packet with no content (just 4 bytes which is the header), the message will be put into your buffer and unprocessed until another message is received.

Dark-Feanor

#10
I have tried a lot of different things and the best idea that I have is that battle.net might not be sending the packet back to me, but queueing it server side. This hanging only happense on packet 0x51 (and sometimes 0x3A) when I send multiple 0x51 packets within a short time period. What I did is that i make sure that every 0x51 / 0x3A that is sent is 150 ms apart from the last, and it all works. Hurray :) Thanks for all the help.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

I don't agree.  Blizzard isn't picking on you in particular in how it responds, so any problem is in your implementation.