berconpy.protocol.ClientCommandPacket

class berconpy.protocol.ClientCommandPacket(sequence, command)

Bases: ClientPacket

The packet sent by the client issuing a command to the server.

Parameters:
  • sequence (int) – The sequence number identifying the packet.

  • command (bytes) – The command to send to the server.

Methods

assert_checksum(checksum)

Asserts that the packet has a given checksum.

from_bytes(cls, data, *, from_client)

Constructs a packet from the given data.

Attributes

data

checksum

The CRC32 checksum included in the header.

index

The zero-based index of the packet associated with a COMMAND server response.

login_success

A boolean indicating if the server authenticated the client.

message

The message that was sent to the client/server.

sequence

The sequence number of the COMMAND or MESSAGE packet.

total

The total number of packets associated with a COMMAND server response.

type

The packet's type defined in the protocol.

assert_checksum(checksum)

Asserts that the packet has a given checksum.

Returns:

The same packet object, helpful for method chaining.

Raises:

ValueError – The checksum was incorrect.

classmethod from_bytes(cls, data, *, from_client)

Constructs a packet from the given data.

Parameters:
  • data (bytes) – The data to parse.

  • from_client (bool) – Whether the packet came from the server or client. This is required for disambiguation of data.

Return type:

Packet

Returns:

The corresponding subclass of Packet.

Raises:

ValueError – The given data is malformed and does not match the packet specification.

property checksum: int

The CRC32 checksum included in the header.

property index: None

The zero-based index of the packet associated with a COMMAND server response.

If a sub-header is not provided with the response, this defaults to 0.

property login_success: None

A boolean indicating if the server authenticated the client.

property message: bytes

The message that was sent to the client/server.

While returned as bytes, this should be decodable as a UTF-8 string, with the exception of ServerMessagePacket objects which only need to be decodable when all of the messages are joined together.

For LOGIN, this would be the password sent to the server. For COMMAND, this would be the command string sent to the server. For MESSAGE, this would be the message sent to the client.

property sequence: int

The sequence number of the COMMAND or MESSAGE packet.

property total: None

The total number of packets associated with a COMMAND server response.

If a sub-header is not provided with the response, this defaults to 1.

property type: PacketType

The packet’s type defined in the protocol.

This property is computed from the data attribute of the packet which in typical cases should correspond with the type of the class itself.

See also

PacketType