vb.nettcpprotocolstcpclient

Understanding Server Protocol


(I am specifically using VB.net, the protocol I am referring to is for a "Minecraft Server")

I have the following link for details on the protocol for a server I'm making.

Protocol

Now, according to this protocol, the first three bytes should specify the packet type. I checked the actual source code (in java) of the client that will be connecting to the server, and verified this to be true.

The problem is, the first three byte values should be the hex of the number of the packet.

The specific packet that I'm working with (The first verification packet sent by the client).

Protocol :: Client Server Handshake: (I don't have a high enough reputation level to post this second link, I will post it as plain text instead)

mc.kev009.com/wiki/Protocol#Client_to_Server_2

I can read the string supplied after the first three bytes that show the "username" send by the client. The problem is, I don't know how to identify the first three. It's not what I expected.

I assumed that after converting the entire results into a readable string, the first three characters would be something similar to 002 or 200. Instead I received characters with ASCII codes of "2," "0," and "8". I know the packet number is 2, why am I getting such an odd result?

Here is the code I am currently working with:

Code:

cWrite("Waiting for client initiated 'handshake'...")
    Dim HandshakePacket As String = PW.getTextPackets(clientStream)
    cWrite(HandshakePacket.Substring(3).Trim & " has requested the required 'handshake'...")
    Try
        Select Case Convert.ToInt32(HandshakePacket.Substring(0, 3), 16)
            Case 2
                cWrite("~HANDSHAKE PACKET~")
            Case Else
                cWrite("Packet id: " & Convert.ToInt32(HandshakePacket.Substring(0, 3), 16) & " not recognized!")
        End Select
    Catch ex As Exception
        '???
    End Try

-cWrite is a function that basically displays the information (a form of debugging output) -PW contains my classes for sending/receiving packets in both string and byte forms. -PW.getTextPackets returns the request sent by the packet already converted to ASCII from its default byte form -clientStream is just the underlying stream from the clientTcp

Could somebody provide me with details on what I am doing wrong?


Solution

  • The packet type is 1 byte, not 3 bytes. The description 3 bytes + length of strings refers to the 1-byte packet ID and the two-byte big-endian short value describing the length of the string. So the 02 00 08 you are reading indicates packet type 2, string length 8. The next 8 bytes will be the content of the string.