berconpy.RCONServerProtocol¶
- class berconpy.RCONServerProtocol(*, command_check=None, password, response_chunk_size=512)¶
Bases:
RCONGenericProtocolA Sans-IO implementation of the server RCON protocol for one client.
- Parameters:
command_check (
Optional[Check[ClientCommandPacket]]) – ACheckthat determines if aClientCommandEventshould be dispatched when aClientCommandPacketis received. IfNone, defaults toNonceCheck(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 byrespond_to_command().
Methods
Retrieves all events that have been parsed since this was last called.
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
The current state of the protocol.
- events_received()¶
Retrieves all events that have been parsed since this was last called.
- Return type:
- packets_to_send()¶
Returns a list of payloads that should be sent to the remote computer.
- Return type:
- 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:
- 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:
- respond_to_command(sequence, response)¶
Returns a list of payloads for responding to the client’s command.
- Return type:
- 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:
- try_authenticate(password)¶
Attempts to authenticate the client with the given password.
- Return type:
- 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.