Author | Message | Time |
---|---|---|
Spilled[DW] | 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: [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 [/code] Anyone see the error? Thanks in advance! | January 14, 2006, 5:12 AM |
dRAgoN | [quote author=Spilled[DW] link=topic=13904.msg141765#msg141765 date=1137215565] 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: [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 [/code] Anyone see the error? Thanks in advance! [/quote] [code] '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 [/code] Sloppy quick write up, might give you an idea of the posable problem. | January 14, 2006, 5:24 AM |
Spilled[DW] | Let me see if im getting what your saying. Check if the tempBuff length is greather then 2 before i parse. Like this? [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, 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 [/code] Still going out of bounds. | January 14, 2006, 5:34 AM |
dRAgoN | no no lol check the temp buffer befor you try getting the pLen. | January 14, 2006, 5:36 AM |
Spilled[DW] | Same thing. [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, 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 [/code] Any more ideas? | January 14, 2006, 5:40 AM |
dRAgoN | [quote author=Spilled[DW] link=topic=13904.msg141772#msg141772 date=1137217207] Same thing. [chopped][/chopped] Any more ideas? [/quote] I would suggest maybe building an incoming buffer class so you could do your while loop like. [code] while class.dowehaveafullpacket() Parse(class.GetPacket()) end while [/code] Only thing I can think of right now is that your forgetting to store your temp buffer and add the previous data to it. | January 14, 2006, 6:02 AM |
Spilled[DW] | 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... [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, 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 [/code] 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: [code] 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 [/code] It raises the error right here... [code] RaiseEvent onError(Err.Description, Err.Number, dDate.Now) [/code] Any ideas guys? im lost... | January 14, 2006, 6:14 AM |
Spilled[DW] | 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... | January 16, 2006, 12:26 AM |