berconpy.ArmaClient

class berconpy.ArmaClient(*, cache=None, dispatch=None, protocol=None)

Bases: RCONClient

An RCONClient subclass that adds more methods for handling Arma 3 RCON.

Methods

add_listener(event, func)

A shorthand for the EventDispatcher.add_listener() method.

ban(addr[, duration, reason])

Bans a given player ID, GUID, or IP address (without port).

close()

Closes the connection.

connect(ip, port, password)

Returns an asynchronous context manager for logging into the given IP and port with password.

fetch_admins()

Requests a list of RCON admins connected to the server, ordered by admin ID and IP address with port.

fetch_bans()

Requests a list of bans on the server.

fetch_missions()

Requests a list of mission files on the server.

fetch_players()

Requests a list of players from the server.

get_player(player_id)

A shorthand for ArmaCache.get_player().

is_connected()

Indicates if the client has a currently active connection with the server.

is_logged_in()

Indicates if the client is currently authenticated with the server.

is_running()

Indicates if the client is running.

kick(player_id[, reason])

Kicks a player with the given ID from the server with an optional reason.

listen([event])

A shorthand for the EventDispatcher.listen() decorator.

lock_server()

Locks the server and prevents new players from joining.

remove_listener(event, func)

A shorthand for the EventDispatcher.remove_listener() method.

restart_and_reassign()

Restarts the mission and reassigns player roles.

restart_mission()

Restarts the currently running mission.

restart_server()

Tells the server to restart.

select_mission(mission[, difficulty])

Selects a new mission for the server to load.

send(message)

Sends a message to all players in the server.

send_command(command)

Sends a command to the server and waits for a response.

shutdown_server()

Tells the server to shut down.

unban(ban_id)

Removes the ban with the given ID from the server.

unlock_server()

Unlocks the server and allows new players to join.

wait_for(event, *[, check, timeout])

A shorthand for EventDispatcher.wait_for().

whisper(player_id, message)

Sends a message to the player with the given ID.

Attributes

admin_id

A shorthand for ArmaCache.admin_id.

cache

The cache used by the client.

players

A shorthand for ArmaCache.players.

add_listener(event, func)

A shorthand for the EventDispatcher.add_listener() method.

See the EventDispatcher for a list of supported events.

Parameters:
  • event (str) – The event to listen for.

  • func (Callable) – The function to dispatch when the event is received.

Return type:

None

async ban(addr, duration=None, reason='')

Bans a given player ID, GUID, or IP address (without port).

Note that the player ID cannot be used to ban players that are no longer in the server; a GUID or IP address must be provided.

Player.ban_ip() and Player.ban_guid() should be shorthands for calling this method.

Parameters:
  • addr (int | str) – The ID, GUID, or IP address to ban.

  • duration (Optional[int]) – The duration of the ban in minutes. If None, the ban will be permanent.

  • reason (str) – An optional reason to include with the ban.

Return type:

str

Returns:

The response from the server, if any.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

close()

Closes the connection.

This method is idempotent and can be called multiple times consecutively.

Changed in version 1.1: This method no longer causes the current task to be cancelled.

connect(ip, port, password)

Returns an asynchronous context manager for logging into the given IP and port with password.

Example usage:

client = berconpy.RCONClient()
async with client.connect(ip, port, password):
    print("Connected!")
print("Disconnected!")

If an unexpected error occurs after successfully logging in, the current task that the context manager is used in will be cancelled to prevent the script being stuck in an infinite loop.

Raises:
  • LoginFailure – The client failed to log into the server.

  • RuntimeError – This method was called while the client is already connected.

async fetch_admins()

Requests a list of RCON admins connected to the server, ordered by admin ID and IP address with port.

Return type:

list[tuple[int, str]]

async fetch_bans()

Requests a list of bans on the server.

Return type:

list[Ban]

async fetch_missions()

Requests a list of mission files on the server.

Return type:

list[str]

async fetch_players()

Requests a list of players from the server.

This method also updates the player cache.

Return type:

list[Player]

get_player(player_id)

A shorthand for ArmaCache.get_player().

Return type:

Player | None

is_connected()

Indicates if the client has a currently active connection with the server.

Return type:

bool

is_logged_in()

Indicates if the client is currently authenticated with the server.

Return type:

bool | None

Returns:

True if authenticated or None if no response has been received from the server.

Raises:

LoginFailure – The client failed to log into the server.

is_running()

Indicates if the client is running. This may not necessarily mean that the client is connected.

Return type:

bool

async kick(player_id, reason='')

Kicks a player with the given ID from the server with an optional reason.

Player.kick() is a shorthand for calling this method.

Parameters:
  • player_id (int) – The ID of the player.

  • reason (str) – An optional reason to show when kicking.

Return type:

str

Returns:

The response from the server, if any.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

listen(event=None)

A shorthand for the EventDispatcher.listen() decorator.

Example usage:

>>> client = RCONClient()
>>> @client.listen()
... async def on_login():
...     print("We have logged in!")
Parameters:

event (Optional[str]) – The event to listen for. If None, the function name is used as the event name.

Return type:

Callable[[TypeVar(T)], TypeVar(T)]

async lock_server()

Locks the server and prevents new players from joining.

Return type:

str

remove_listener(event, func)

A shorthand for the EventDispatcher.remove_listener() method.

This method should be a no-op if the given event and function does not match any registered listener.

Parameters:
  • event (str) – The event used by the listener.

  • func (Callable) – The function used by the listener.

Return type:

None

async restart_and_reassign()

Restarts the mission and reassigns player roles.

Return type:

str

async restart_mission()

Restarts the currently running mission.

Return type:

str

async restart_server()

Tells the server to restart. :rtype: str

Note

The client does not automatically close after this command is sent. If you need to prevent the client from indefinitely attempting to reconnect, you should call the close() method.

async select_mission(mission, difficulty='')

Selects a new mission for the server to load.

Parameters:
  • mission (str) – The name of the mission to load without the file extension (e.g. "MP_Bootcamp_01.Altis").

  • difficulty (str) – The new difficulty to use on the server (e.g. Recruit, Regular, Veteran, Custom). If not provided, the current difficulty is reused.

Return type:

str

async send(message)

Sends a message to all players in the server.

Parameters:

message (str) – The message to send.

Return type:

str

Returns:

The response from the server, if any.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

async send_command(command)

Sends a command to the server and waits for a response.

Parameters:

command (str) – The command to send.

Return type:

str

Returns:

The server’s response as a string.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

async shutdown_server()

Tells the server to shut down. :rtype: str

Note

The client does not automatically close after this command is sent. If you need to prevent the client from indefinitely attempting to reconnect, you should call the close() method.

async unban(ban_id)

Removes the ban with the given ID from the server.

Parameters:

ban_id (int) – The ID of the ban to remove.

Return type:

str

Returns:

The response from the server, if any.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

async unlock_server()

Unlocks the server and allows new players to join.

Return type:

str

async wait_for(event, *, check=None, timeout=None)

A shorthand for EventDispatcher.wait_for().

async whisper(player_id, message)

Sends a message to the player with the given ID.

Player.send() is a shorthand for calling this method.

Parameters:
  • player_id (int) – The ID of the player to send to.

  • message (str) – The message to send.

Return type:

str

Returns:

The response from the server, if any.

Raises:
  • RCONCommandError – The server has either disabled this command or failed to respond to our command.

  • RuntimeError – The client is either not connected or the server could/would not respond to the command.

property admin_id: int | None

A shorthand for ArmaCache.admin_id.

property cache: ArmaCache

The cache used by the client.

property players: list[Player]

A shorthand for ArmaCache.players.