berconpy.RCONClientProtocol

class berconpy.RCONClientProtocol(*, message_check=None)

Bases: RCONGenericProtocol

Implements the client-side portion of the protocol.

Parameters:

message_check (Optional[Check[ServerMessagePacket]]) – A Check that determines if a ServerMessageEvent should be dispatched when a ServerMessagePacket is received. If None, defaults to NonceCheck(5).

Methods

authenticate(password)

Returns the payload needed to authenticate with the server.

events_received()

Retrieves all events that have been parsed since this was last called.

invalidate_command(sequence)

Invalidates any messages received for a response to a given command.

packets_to_send()

Returns a list of payloads that should be sent to the remote computer.

receive_datagram(data)

Handles a packet received by the server.

reset()

Resets the protocol to the beginning state.

send_command(command)

Returns a payload for sending a command.

Attributes

state

The current state of the protocol.

authenticate(password)

Returns the payload needed to authenticate with the server.

Raises:

InvalidStateError – This method can only be called during authentication.

Return type:

ClientLoginPacket

events_received()

Retrieves all events that have been parsed since this was last called.

Return type:

list[ClientEvent]

invalidate_command(sequence)

Invalidates any messages received for a response to a given command.

This should be called whenever a command times out.

If the command sequence was not queued before, this is a no-op.

Raises:

InvalidStateError – This method can only be called after being logged in.

Return type:

None

packets_to_send()

Returns a list of payloads that should be sent to the remote computer.

Return type:

list[ClientPacket]

receive_datagram(data)

Handles a packet received by the server.

Raises:
Return type:

ServerPacket

reset()

Resets the protocol to the beginning state.

This method should be invoked when the connection has timed out, meaning the client has either not sent a command within the last 45 seconds, or the client has failed to acknowledge 5 repeats of the same message within 10 seconds.

Return type:

None

send_command(command)

Returns a payload for sending a command.

Each invocation of this method increments an internal sequence counter. When retrying a command, it is recommended to re-use the same payload to avoid triggering the same command multiple times.

Raises:

InvalidStateError – This method can only be called after being logged in.

Return type:

ClientCommandPacket

state: ClientState

The current state of the protocol.