• Welcome to Valhalla Legends Archive.
 

Data Arrival Help..

Started by BaDDBLooD, August 23, 2004, 09:52 PM

Previous topic - Next topic

BaDDBLooD

This is darn wierd!

I am using the Winsock API Socket class, i'm sure some of you have used this.  It includes mSocketSupprt, and cSocket.  My problem is in the BNET Data Arrival.  i have a Parse sub, and whenever i try and parse the packet's i get a error.

For example:



Public Sub ParseBNCS(ByVal Data As String)
Dim PacketID As Byte

PacketID = Asc(Mid(Data, 2, 1))
Select Case PacketID
   Case &H0
       MsgBox "0x00"
   Case &H25
       MsgBox "0x25"
   Case &H50
       MsgBox "0x50"
End Select
End Sub



This code works, however this code gives me the error: Run-time error '5':
Invalid Procedure call or argument



Public Sub ParseBNCS(ByVal Data As String)
Dim PacketID As Byte

PacketID = Asc(Mid(Data, 2, 1))
Select Case PacketID
   Case &H0
       With Buffer
           .SendPacket frmMain.sckBNCS, BNCS, &H0
       End With
   Case &H25
       With Buffer
           .InsertNonNTString Mid(Data, 5, 4)
           .SendPacket frmMain.sckBNCS, BNCS, &H25
       End With
   Case &H50
       Dim ExeHash As String, MpqName As String
       ServerToken = Val("&h" & StrToHex(StrReverse(Mid(Data, 9, 4))))
       ExeHash = Mid(Data, 38, Len(Data) - 2)
       MpqName = Mid(Data, 25, 12)
       MpqName = Val(Mid(MpqName, 8, 1))
       AddText frmMain.rtbChat, vbYellow, ExeHash
       AddText frmMain.rtbChat, vbYellow, MpqName
       With Buffer
           .InsertDWORD GetBNLSByte()
           .InsertDWORD CLng(MpqName)
           .InsertNTString ExeHash
           .SendPacket frmMain.sckBNLS, BNLS, &H9
       End With
End Select
End Sub



Data Arrival as requested by Chronic



Private Sub sckBNCS_OnDataArrival(ByVal bytesTotal As Long)
Static Buffer As String, Data As String, Length As Long

sckBNCS.GetData Data, vbString
Buffer = Buffer & Data
While Len(Buffer) > 4
   Length = Val("&H" & StrToHex(StrReverse(Mid(Buffer, 3, 2))))
   If Len(Buffer) < Length Then: Exit Sub
   ParseBNCS (Left(Buffer, Length))
   Buffer = Mid(Buffer, Length + 1)
Wend
End Sub



When i debug the Environment the string "Data" is Empty.

When i debug the Data Arrival, and step through the parse sub i don't get any error at all.

Any Help will be Apreciated.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

K

Well that makes sense.


PacketID = Asc(Mid(Data, 2, 1))


If Data is empty, how can you access the second character in it?
You need to only call your Parse function when you receive a complete packet.

BaDDBLooD

#2
Yes i know i can't do that.  If you read my statement at the top it WORKS when i just have a Message box, whenever i implement any real code it doesn't work!

EDIT: i uploaded the source code to my webhost if anyone wanted a more in depth look at the problem.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Kp

Quote from: BaDDBLooD on August 23, 2004, 10:26 PMYes i know i can't do that.  If you read my statement at the top it WORKS when i just have a Message box, whenever i implement any real code it doesn't work!

Probably because the extra delay imposed by the message box allows the other messages to be fully delivered, so you receive them fine.  Perhaps you should try following K's suggestion, and only parse complete messages.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

BaDDBLooD

#4
I don't know how to fix this so imma screw it.

Thanks for everyone's help, it's much apreciated.

EDIT: Ok Nevermind, i did fix it.

my String To Hex Function was totally screwed over.  Along with a few other small problems.  The problem was ( After i debugged a whole lot ) i recieve 0x25, 0x50, than the broken str to hex function gave me a whole assload of nothing.

Thanks again to everyone for there help.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.