diff --git a/docs/source/usage.rst b/docs/source/usage.rst index e518fb0..b08789f 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -1,28 +1,57 @@ Usage ===== -For usage in code, there is the class :py:class:`rcon.Client`. +Source RCON +----------- +To connect to a server using the Source RCON protocol, use :py:class:`rcon.source.Client`. .. code-block:: python - from rcon import Client + from rcon.source import Client with Client('127.0.0.1', 5000, passwd='mysecretpassword') as client: response = client.run('some_command', 'with', 'some', 'arguments') print(response) -Async support +BattlEye RCon ------------- -If you want to use RCOn in an asynchronous environment, use :py:func:`rcon.rcon`. +To connecto to a server using the BattlEye RCon protocol, use :py:class:`rcon.battleye.Client`. .. code-block:: python - from rcon import rcon + from rcon.battleye import Client + + with Client('127.0.0.1', 5000, passwd='mysecretpassword') as client: + response = client.run('some_command', 'with', 'some', 'arguments') - response = await rcon('some_command', 'with', 'some', 'arguments', - host='127.0.0.1', port=5000, passwd='mysecretpassword') print(response) +Handling server messages +~~~~~~~~~~~~~~~~~~~~~~~~ +Since the BattlEye RCon server will also send server messages to the client +alongside command responses, you can register an event handler to process +those messages: + +.. code-block:: python + + from rcon.battleye import Client + from rcon.battleye.proto import ServerMessage + + def my_message_handler(server_message: ServerMessage) -> None: + """Print server messages.""" + + print('Server message:', server_message) + + with Client( + '127.0.0.1', + 5000, + passwd='mysecretpassword', + message_handler=my_message_handler + ) as client: + response = client.run('some_command', 'with', 'some', 'arguments') + + print('Response:', response) + Configuration ------------- `rconclt` servers can be configured in :file:`/etc/rcon.conf`.