Skip to content

Yoshi-E/Python-BEC-RCon

Repository files navigation

API and Discord Module for BEC RCon

Install

Install via pip:

pip install git+https://github.com/Yoshi-E/Python-BEC-RCon.git

Alternatively you can download the python wheel and install it with:

pip install bec_rcon-0.1.0-py3-none-any.whl

Demo

Check out the full demo in api_example.py.
This short example connects to a RCon server and prints all server messages it receives.

def msg(args):
    message = args[0]
    print(message)

import bec_rcon
rcon_client = bec_rcon.ARC("192.168.0.1", "MyPassword", 2302)
rcon_client.add_Event("received_ServerMessage", msg)
rcon_client.loadMission("becti_0097_z1305.Altis") #Filename without .pbo!
rcon_client.addBan(player_id=1, reason="Rcon is watching!", time=0)

Known Issues:

Contact me:

Join my Discord: https://discordapp.com/invite/YhBUUSr
Bohemia Interactive Forum Thread: https://forums.bohemia.net/forums/topic/223835-api-bec-rcon-api-for-python-and-discord/

Discord:

A Discord module using this API can be found here: https://github.com/Yoshi-E/jmwBOT/tree/master/modules/rcon

Documentation

Event Handlers:

The passed functions can by async and can be class objects.

Event passed args
on_disconnect none
login_Sucess none
login_fail none
on_command_fail none
received_ServerMessage message: str
received_CommandMessage message: str

Variables:

  • rcon_client.serverMessage: Contains all recent messages (limit = 100) Format: [datetime: datetime, message: str]
  • rcon_client.serverCommandData: Contains all returned data from commands (limit = 10) Format: [datetime: datetime, data: str]
  • rcon_client.disconnected: When connected = False, else True
  • rcon_client.serverPort: ServerPort (int)
  • rcon_client.serverIP: ServerIP (str)
  • rcon_client.rconPassword: ServerPassword (str)
  • rcon_client.Events: List of all user added Event handlers Format: [str(event_name), function(custom_function)]

API Functions:

ARC = ARC(serverIP: str, RConPassword: str, serverPort = 2302, options = {})
  • serverIP: IPv4 adress in the format: 000.000.000.000 - 255.255.255.255
  • RConPassword: str your Rcon password
  • serverPort: int port Rcon is running on your server options is an diconatry for addional settings:
  • timeoutSec: int time in seconds a RCon command has to be executed within (Default: 5, Min: 0.2, Max: None)
  • autosaveBans: boolean Saves bans to file when ever a ban is added or removed (Default: False)
  • debug: boolean Prints additonal package and debug information into console (Default: False) This class constructor automatically connects to given server and attempts to maintain the connection.
ARC.disconnect()

Closed the connection to the server and fires the Event "on_disconnect".

ARC.connect()

Connects to the server.

ARC.reconnect()

Closes the connection and connects to the server.

ARC.authorize()

Authorizes the connection using the RConPassword

ARC.send(command: str)

Waits for an opportunity to send a command to the rcon server.
Only one send will be executed at a time. At most ARC.max_waiting_for_send (Defaut: 10) can be waiting.
Will raise the "Failed to send command!" exception if it failed to send the command within the timeout limit.
ARC.activeSend tracks how many commands are trying to be send at the same time.

ARC.add_Event(event_name: str, function: function)

Events are: "on_command_fail", "on_disconnect", "login_Sucess", "login_fail", "received_ServerMessage" and "received_CommandMessage".
Function can be class function and can be asynchronous.
Addtional, custom parameters however can not be passed.

RCon Commands:

See rcon.py for details

  • command
  • kickPlayer
  • sayGlobal
  • sayPlayer
  • loadScripts
  • maxPing
  • changePassword
  • loadBans
  • getPlayers
  • getPlayersArray
  • getAdmins
  • getAdminsArray
  • getMissions
  • loadMission
  • banPlayer
  • addBan
  • removeBan
  • getBansArray
  • getBans
  • writeBans
  • getBEServerVersion

Arma 3 Commands

See https://community.bistudio.com/wiki/Multiplayer_Server_Commands for details

  • lock
  • unlock
  • shutdown
  • restart
  • restartServer
  • restartserveraftermission
  • shutdownserveraftermission
  • reassign
  • monitords
  • goVote

Donate

paypal

About

Python API and Discord module for BEC RCon

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages