# rcon package

## Submodules

## rcon.asyncio module

## rcon.client module

Synchronous client.

class rcon.client.Client(host: str, port: int, *, timeout: Optional[float] = None, passwd: Optional[str] = None)

  Bases: `object`

  An RCON client.

  close() → None

    Closes the socket connection.

  communicate(packet: rcon.proto.Packet) → rcon.proto.Packet

    Sends and receives a packet.

  connect(login: bool = False) → None

    Connects the socket and attempts a login if wanted and a password is set.

  host
  login(passwd: str, *, encoding: str = 'utf-8') → bool

    Performs a login.

  passwd
  port
  read() → rcon.proto.Packet

    Reads a packet.

  run(command: str, *args: str, encoding: str = 'utf-8') → str

    Runs a command.

  property timeout: float

    Returns the socket timeout.

## rcon.config module

RCON server configuration.

class rcon.config.Config(host: str, port: int, passwd: Optional[str] = None)

  Bases: `NamedTuple`

  Represents server configuration.

  classmethod from_config_section(section: configparser.SectionProxy) → rcon.config.Config

    Creates a credentials tuple from the respective config section.

  classmethod from_string(string: str) → rcon.config.Config

    Reads the credentials from the given string.

  host: str

    Alias for field number 0

  passwd: Optional[str]

    Alias for field number 2

  port: int

    Alias for field number 1

rcon.config.from_args(args: argparse.Namespace) → rcon.config.Config

  Get the credentials for a server from the respective arguments.

## rcon.console module

An interactive console.

rcon.console.rconcmd(host: str, port: int, passwd: str, *, prompt: str = 'RCON {host}:{port}> ')

  Initializes the console.

## rcon.errorhandler module

Common errors handler.

class rcon.errorhandler.ErrorHandler(logger: logging.Logger)

  Bases: `object`

  Handles common errors and exits.

  exit_code
  logger

## rcon.exceptions module

RCON exceptions.

exception rcon.exceptions.ConfigReadError

  Bases: `Exception`

  Indicates an error while reading the configuration.

exception rcon.exceptions.RequestIdMismatch(sent: int, received: int)

  Bases: `Exception`

  Indicates a mismatch in request IDs.

exception rcon.exceptions.UserAbort

  Bases: `Exception`

  Indicates that a required action has been aborted by the user.

exception rcon.exceptions.WrongPassword

  Bases: `Exception`

  Indicates a wrong password.

## rcon.gui module

## rcon.proto module

Low-level protocol stuff.

class rcon.proto.LittleEndianSignedInt32(*_)

  Bases: `int`

  A little-endian, signed int32.

  MAX = 2147483647
  MIN = -2147483648
  async classmethod aread(reader: asyncio.streams.StreamReader) → rcon.proto.LittleEndianSignedInt32

    Reads the integer from an asynchronous file-like object.

  classmethod read(file: IO) → rcon.proto.LittleEndianSignedInt32

    Reads the integer from a file-like object.

class rcon.proto.Packet(id: LittleEndianSignedInt32, type: Type, payload: bytes, terminator: bytes = b'\x00\x00')

  Bases: `NamedTuple`

  An RCON packet.

  async classmethod aread(reader: asyncio.streams.StreamReader) → rcon.proto.Packet

    Reads a packet from an asynchronous file-like object.

  id: rcon.proto.LittleEndianSignedInt32

    Alias for field number 0

  classmethod make_command(*args: str, encoding: str = 'utf-8') → rcon.proto.Packet

    Creates a command packet.

  classmethod make_login(passwd: str, *, encoding: str = 'utf-8') → rcon.proto.Packet

    Creates a login packet.

  payload: bytes

    Alias for field number 2

  classmethod read(file: IO) → rcon.proto.Packet

    Reads a packet from a file-like object.

  terminator: bytes

    Alias for field number 3

  type: rcon.proto.Type

    Alias for field number 1

class rcon.proto.Type(value)

  Bases: `enum.Enum`

  RCON packet types.

  SERVERDATA_AUTH = 3
  SERVERDATA_AUTH_RESPONSE = 2
  SERVERDATA_EXECCOMMAND = 2
  SERVERDATA_RESPONSE_VALUE = 0
  async classmethod aread(reader: asyncio.streams.StreamReader) → rcon.proto.Type

    Reads the type from an asynchronous file-like object.

  classmethod read(file: IO) → rcon.proto.Type

    Reads the type from a file-like object.

rcon.proto.random_request_id() → rcon.proto.LittleEndianSignedInt32

  Generates a random request ID.

## rcon.rconclt module

RCON client CLI.

rcon.rconclt.main() → int

  Runs the main script with exceptions handled.

## rcon.rconshell module

An interactive RCON shell.

rcon.rconshell.get_args() → argparse.Namespace

  Parses and returns the CLI arguments.

rcon.rconshell.main() → int

  Runs the main script with exceptions handled.

## rcon.readline module

Wrapper for readline support.

class rcon.readline.CommandHistory(logger: logging.Logger)

  Bases: `object`

  Context manager for the command line history.

  logger

## Module contents

RCON client library.

class rcon.Client(host: str, port: int, *, timeout: Optional[float] = None, passwd: Optional[str] = None)

  Bases: `object`

  An RCON client.

  close() → None

    Closes the socket connection.

  communicate(packet: rcon.proto.Packet) → rcon.proto.Packet

    Sends and receives a packet.

  connect(login: bool = False) → None

    Connects the socket and attempts a login if wanted and a password is set.

  host
  login(passwd: str, *, encoding: str = 'utf-8') → bool

    Performs a login.

  passwd
  port
  read() → rcon.proto.Packet

    Reads a packet.

  run(command: str, *args: str, encoding: str = 'utf-8') → str

    Runs a command.

  property timeout: float

    Returns the socket timeout.

exception rcon.RequestIdMismatch(sent: int, received: int)

  Bases: `Exception`

  Indicates a mismatch in request IDs.

exception rcon.WrongPassword

  Bases: `Exception`

  Indicates a wrong password.

async rcon.rcon(command: str, *arguments: str, host: str, port: int, passwd: str, encoding: str = 'utf-8') → str

  Runs a command asynchronously.