Well in my DataArrival on my bot it seems to be having a problem splitting the packets that are sent combined or when i reach &HF chat packet and was seeing if anyone could see where it may be going out of bounds?
Dunno if this is the right forum or not but I thought it would be the best since it's dealing with Battle.net Packets
Heres the Code:
Private Sub wSock_onDataArrival(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles wSock.onDataArrival
Dim tempBuff(iTotalBytes - 1) As Byte, pLen As Integer
Array.Copy(sData, 0, tempBuff, 0, iTotalBytes)
pLen = tempBuff(2)
While pLen > 4
Dim p1(pLen - 1) As Byte
Array.Copy(tempBuff, 0, p1, 0, pLen)
Parsep(wSock, p1)
Array.Copy(tempBuff, pLen, tempBuff, 0, tempBuff.Length)
pLen = tempBuff(2)
End While
End Sub
Anyone see the error? Thanks in advance!
Quote from: Spilled[DW] on January 13, 2006, 11:12 PM
Well in my DataArrival on my bot it seems to be having a problem splitting the packets that are sent combined or when i reach &HF chat packet and was seeing if anyone could see where it may be going out of bounds?
Dunno if this is the right forum or not but I thought it would be the best since it's dealing with Battle.net Packets
Heres the Code:
Private Sub wSock_onDataArrival(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles wSock.onDataArrival
Dim tempBuff(iTotalBytes - 1) As Byte, pLen As Integer
Array.Copy(sData, 0, tempBuff, 0, iTotalBytes)
pLen = tempBuff(2)
While pLen > 4
Dim p1(pLen - 1) As Byte
Array.Copy(tempBuff, 0, p1, 0, pLen)
Parsep(wSock, p1)
Array.Copy(tempBuff, pLen, tempBuff, 0, tempBuff.Length)
pLen = tempBuff(2)
End While
End Sub
Anyone see the error? Thanks in advance!
'check the temp buffer and see if you have more then 2 bytes..
if TempBuff.Length > 2 then
'get your packet length and test the rest
if pLen > TempBuff.Length then
'your packet is not all in the buffer yet wait for the rest of it
else
'you have the packet, process it.
end if
else
'your packet is incomplete wait for the rest of it.
end if
Sloppy quick write up, might give you an idea of the posable problem.
Let me see if im getting what your saying. Check if the tempBuff length is greather then 2 before i parse.
Like this?
Private Sub wSock_onDataArrival(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles wSock.onDataArrival
Dim tempBuff(iTotalBytes - 1) As Byte, pLen As Integer, used As Integer
Array.Copy(sData, 0, tempBuff, 0, iTotalBytes)
pLen = tempBuff(2)
While pLen > 4
If tempBuff.Length > 2 Then
Dim p1(pLen - 1) As Byte
Array.Copy(tempBuff, 0, p1, 0, pLen)
Parsep(wSock, p1)
Array.Copy(tempBuff, pLen, tempBuff, 0, tempBuff.Length)
pLen = tempBuff(2)
End If
End While
End Sub
Still going out of bounds.
no no lol check the temp buffer befor you try getting the pLen.
Same thing.
Private Sub wSock_onDataArrival(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles wSock.onDataArrival
Dim tempBuff(iTotalBytes - 1) As Byte, pLen As Integer, used As Integer
Array.Copy(sData, 0, tempBuff, 0, iTotalBytes)
If tempBuff.Length > 2 Then
pLen = tempBuff(2)
While pLen > 4
If tempBuff.Length > 2 Then
Dim p1(pLen - 1) As Byte
Array.Copy(tempBuff, 0, p1, 0, pLen)
Parsep(wSock, p1)
Array.Copy(tempBuff, pLen, tempBuff, 0, tempBuff.Length)
pLen = tempBuff(2)
End If
End While
End If
End Sub
Any more ideas?
Quote from: Spilled[DW] on January 13, 2006, 11:40 PM
Same thing.
[chopped][/chopped]
Any more ideas?
I would suggest maybe building an incoming buffer class so you could do your while loop like.
while class.dowehaveafullpacket()
Parse(class.GetPacket())
end while
Only thing I can think of right now is that your forgetting to store your temp buffer and add the previous data to it.
hrmm... but is a incoming buffer class really needed? if i can get this while loop working it would be much less code and just as efficient =\
Edit:
I have re-written my dataarrival and I still seem to be getting an error...
Private Sub wSock_onDataArrival(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles wSock.onDataArrival
Dim tempBuff(iTotalBytes - 1) As Byte, pLen As Integer, used As Integer
used = 0
Array.Copy(sData, 0, tempBuff, 0, iTotalBytes)
pLen = tempBuff(2)
While used <> iTotalBytes
Dim p1(pLen - 1) As Byte
Array.Copy(tempBuff, used, p1, 0, pLen)
Parsep(wSock, p1)
used = used + pLen
If used <> iTotalBytes Then
pLen = used + 2
End If
End While
End Sub
I use the Step-Into Debugger to follow it, it exits the loop when used = itotalbytes and getings to 'End Sub' then errors...
Heres my DataArrival for my System.net.Socket:
Private Sub sockDataArrival(ByVal ar As IAsyncResult)
Dim bytesRead As Integer
Try
bytesRead = tcpClient.EndReceive(ar)
Catch
Exit Sub
End Try
Try
Dim Data() As Byte = sBuffer
If bytesRead = 0 Then
tcpClient.Shutdown(SocketShutdown.Both)
tcpClient.Close()
RaiseEvent onDisconnect(dDate.Now)
Exit Sub
End If
ReDim sBuffer(256)
tcpClient.BeginReceive(sBuffer, 0, iBuffer, 0, AddressOf sockDataArrival, tcpClient)
RaiseEvent onDataArrival(Data, bytesRead, dDate.Now)
Catch
RaiseEvent onError(Err.Description, Err.Number, dDate.Now)
Exit Sub
End Try
End Sub
It raises the error right here...
RaiseEvent onError(Err.Description, Err.Number, dDate.Now)
Any ideas guys? im lost...
Sorry about the double post but coudl this have something to do with a Thread ending? I got an error message about a thread stopping but I dont remember to full error...