berconpy.RCONServerProtocol

class berconpy.RCONServerProtocol(*, command_check=None, password, response_chunk_size=512)

Bases: RCONGenericProtocol

A Sans-IO implementation of the server RCON protocol for one client.

Parameters:
  • command_check (Optional[Check[ClientCommandPacket]]) – A Check that determines if a ClientCommandEvent should be dispatched when a ClientCommandPacket is received. If None, defaults to NonceCheck(5).

  • password (str) – The password to compare against when the client is authenticating. The protocol recommends this should be an ASCII-compatible string.

  • response_chunk_size (int) – Sets the size to use when chunking a command response into one or more packets to be returned by respond_to_command().

Methods

events_received()

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

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.

respond_to_command(sequence, response)

Returns a list of payloads for responding to the client's command.

send_message(message)

Returns a payload for sending a message.

try_authenticate(password)

Attempts to authenticate the client with the given password.

Attributes

state

The current state of the protocol.

events_received()

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

Return type:

list[ServerEvent]

packets_to_send()

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

Return type:

list[ServerPacket]

receive_datagram(data)

Handles a packet received by the server.

Raises:
  • InvalidStateError – The given packet cannot be handled in the current state.

  • ValueError – Handling failed due to a malformed packet.

Return type:

ClientPacket

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

respond_to_command(sequence, response)

Returns a list of payloads for responding to the client’s command.

Return type:

list[ServerCommandPacket]

send_message(message)

Returns a payload for sending a message.

Each invocation of this method increments an internal sequence counter. When retrying a message, it is recommended to re-use the same payload to avoid having the client interpret each attempt as a new message.

Raises:

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

Return type:

ServerMessagePacket

try_authenticate(password)

Attempts to authenticate the client with the given password.

Return type:

ServerLoginPacket

Returns:

The payload indicating if the client is authenticated.

Raises:

InvalidStateError – This method can only be called during authentication.

state: ServerState

The current state of the protocol.