RISHKARI

Breaking up packets and reading them.

3 posts in this topic

Hello forum users!

I am in need of a little bit of help to display packet data in a CUI script I have made.
I am receiving a packet which contains USERID: MESSAGEHERE
 

AA 55 2C 00 10 02 07 02 04 4B 69 6E 61 1E 00 48 65 6C 6C 6F 2C 20 74 68 69 73 20 69 73 20 61 20 74 65 73 74 20 6D 65 73 73 61 67 65 2E 06 00 00 55 AA AA 55 01 00 3D 55 AA

00 10 02  =  The message type, in this case it's private message
04 4B 69 6E 61 = The first byte '04' is the amount of bytes to follow. the next 4 is the USERID (Kina)
1E 00 = Length of the message, '1E'(30) is what I need to use and the '00' is pointless, padding I'd say.
48 65 6C 6C 6F 2C 20 74 68 69 73 20 69 73 20 61 20 74 65 73 74 20 6D 65 73 73 61 67 65 2E = Message data (Hello, this is a test message.)

The rest of it is just useless. One of the problems I am having is the packet itself can be added onto the end of another packet. It's strange...
I had made something small and very crappy to find the Message type then go from there. I was able to read message type and the USERID, after that I was never able to properly get the message data and I would just pull my hair out. Has been like this for days sadly.

Any help at all on this would be sweet!

Thanks.

Share this post


Link to post
Share on other sites



Still require help sorry.
This is what I have been trying to use, with no luck at all.

 

#include <Array.au3>
#include <String.au3>


$sReceived = "0xAA551A0010021D0104726173730B006920616D20736F7263657264000155AA"


Func splitter($string)
$strArray = StringSplit($string, "") ; No delimiter will separate all chars.
Global $strResult = ""
If IsEvenNumber($strArray[0]) Then
    For $i = 1 to $strArray[0] Step 2
        $strResult = $strResult & $strArray[$i] & $strArray[$i+1] & " "
    Next
;~     MsgBox(0, "Result", $strResult)
Else
;~     MsgBox(0, "Result", "String does not contain an even number of characters.")
EndIf
EndFunc

Func IsEvenNumber($num)
    Return Mod($num, 2) = 0
EndFunc
$name = ""
$shout = ""
splitter($sReceived)
$countchr = StringLen ( $sReceived )
Local $aArray1 = _StringExplode($strResult, " ", 0)
For $i = 1 to $countchr / 2
;~ ConsoleWrite($i&@CRLF)

If $aArray1[$i] = "AA" Then
;~  ConsoleWrite("AA"&@CRLF)
    If $aArray1[$i+1] = "55" Then
;~      ConsoleWrite("55"&@CRLF)
        If $aArray1[$i+3] = "00" Then
;~          ConsoleWrite("00"&@CRLF)
            If $aArray1[$i+4] = "10" Then
;~              ConsoleWrite("10"&@CRLF)
                If $aArray1[$i+5] = "02" Then ; 02 = PM 03 = Party 04 = Shout
                    ConsoleWrite("Whisper received!~~" &@CRLF)
;~                  $sHex1 = _HexToString($aArray1[$i+9])
;~                      ConsoleWrite($sHex1&@CRLF)
                    For $i = 1 to $aArray1[$i+8]
                        Global $sHex1 = _HexToString($aArray1[$i+9])
;~                      ConsoleWrite($sHex1)
                        $name = $name & $sHex1
                    Next
;~                  ConsoleWrite(" - "&@CRLF)
                    $hex2dec = Dec($aArray1[$i+9])
                    For $i = 1 to $hex2dec
;~                      ConsoleWrite($hex2dec&@CRLF)
                        Global $sHex1 = _HexToString($aArray1[$i+16])
;~                      ConsoleWrite($sHex1)
                        $shout = $shout & $sHex1
                    Next
;~                  ConsoleWrite(""&@CRLF)
                EndIf
            EndIf
        EndIf
    EndIf

;~  ConsoleWrite("DONEEEE")
EndIf


Next

ConsoleWrite("Whisper : "&$name&" - "&$shout&@CRLF)


 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Something like this should be close:

#include <Array.au3>
#include <String.au3>
$sReceived = "0xAA551A0010021D0104726173730B006920616D20736F7263657264000155AA"
$sReceived &= "0xAA552C0010020702044B696E611E0048656C6C6F2C207468697320697320612074657374206D6573736167652E06000055AAAA5501003D55AA"
; retrieve messages into an array
$aMessages = StringRegExp($sReceived, "(?i)AA55..0010(.*?)55AA", $STR_REGEXPARRAYGLOBALMATCH)
For $i = 0 To UBound($aMessages) - 1
    $mType = StringMid($aMessages[$i], 1, 2)
    $UidLen = Dec(StringMid($aMessages[$i], 7, 2)) * 2
    $UserId = _HexToString(StringMid($aMessages[$i], 9, $UidLen))
    $MsgLen = Dec(StringMid($aMessages[$i], 9 + $UidLen, 2)) * 2
    $Messages = _HexToString(StringMid($aMessages[$i], 13 + $UidLen, $MsgLen))
    ConsoleWrite("Type:" & $mType & " From: " & $UserId & "  Messages: " & $Messages & @CRLF)
Next

Jos :)

Ps. Make sure you read our forums rules too around game automation etc. 

Edited by Jos
Updated code a little

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now