RCONClient
Inherits: RefCounted < Object
RCON client for connecting to and managing remote game servers.
Description
RCONClient provides a complete client implementation for connecting to RCON servers using either Source RCON (TCP) or BattlEye RCON (UDP) protocols. It handles authentication, command execution, and protocol-specific features like BattlEye keep-alive packets.
Availability: This class is available in:
Editor builds (all platforms, for testing/development)
Exported games without
dedicated_servercustom feature tag (all platforms)
It is not available in dedicated server builds with the dedicated_server feature tag.
The client runs network operations on a background thread and provides thread-safe access through the poll() method, which must be called regularly (typically in _process) to dispatch events and callbacks.
var client = RCONClient.new()
func _ready():
client.connected.connect(_on_connected)
client.connect_to_server("127.0.0.1", 27015, "password", RCONClient.PROTOCOL_SOURCE)
func _process(_delta):
client.poll() # Dispatch events
func _on_connected():
client.send_command("status", func(response):
print("Server: ", response)
)
Tutorials
Methods
connect_to_server(host: String, port: int, password: String, protocol: Protocol) |
|
void |
|
get_protocol() const |
|
get_state() const |
|
is_authenticated() const |
|
void |
poll() |
void |
send_command(command: String, callback: Callable = Callable()) |
send_command_sync(command: String, timeout: float = 5.0) |
|
void |
send_raw_packet(packet: PackedByteArray) |
Signals
authenticated() 🔗
Emitted when the client has successfully authenticated with the server. You can now send commands.
authentication_failed() 🔗
Emitted when authentication fails (incorrect password). The connection will be closed.
command_response(command: String, response: String) 🔗
Emitted when a command response is received from the server. The command parameter contains the original command that was sent, and response contains the server's response.
connected() 🔗
Emitted when the TCP/UDP connection is established. Authentication may still be in progress.
connection_error(error: String) 🔗
Emitted when a connection error occurs. The error parameter contains a description of the error.
disconnected() 🔗
Emitted when the client disconnects from the server (either intentionally or due to connection loss).
raw_packet_received(packet: PackedByteArray) 🔗
Emitted when a raw packet is received from the server. Useful for low-level protocol debugging or custom packet handling.
server_message(message: String) 🔗
Emitted when a server-pushed message is received (BattlEye RCON only). These are asynchronous messages from the server that are not responses to commands.
Enumerations
enum Protocol: 🔗
Protocol PROTOCOL_SOURCE = 0
Use Source RCON protocol (TCP-based).
Protocol PROTOCOL_BATTLEYE = 1
Use BattlEye RCON protocol (UDP-based).
enum State: 🔗
State STATE_DISCONNECTED = 0
Client is not connected to any server.
State STATE_CONNECTING = 1
Client is establishing a connection to the server.
State STATE_AUTHENTICATING = 2
Client is authenticating with the server.
State STATE_CONNECTED = 3
Client is connected and authenticated. Commands can be sent.
State STATE_ERROR = 4
An error occurred during connection or operation.
Method Descriptions
Error connect_to_server(host: String, port: int, password: String, protocol: Protocol) 🔗
Connects to an RCON server at the given host and port using the specified password and protocol.
Returns @GlobalScope.OK if the connection was initiated successfully. The actual connection and authentication happen asynchronously - use the connected and authenticated signals to know when the connection is ready.
var err = client.connect_to_server("127.0.0.1", 27015, "admin123", RCONClient.PROTOCOL_SOURCE)
if err != OK:
print("Failed to initiate connection: ", err)
void disconnect_from_server() 🔗
Disconnects from the RCON server and stops the network thread. Emits the disconnected signal.
client.disconnect_from_server()
Protocol get_protocol() const 🔗
Returns the protocol being used by this client (PROTOCOL_SOURCE or PROTOCOL_BATTLEYE).
Returns the current connection state. Possible values are:
STATE_DISCONNECTED: Not connected
STATE_CONNECTING: Connection in progress
STATE_AUTHENTICATING: Authenticating with server
STATE_CONNECTED: Connected and authenticated
STATE_ERROR: Connection error occurred
bool is_authenticated() const 🔗
Returns true if the client is connected and authenticated with the server.
void poll() 🔗
Processes pending events from the network thread and dispatches signals and callbacks. This method must be called regularly (typically in _process) for the client to function properly.
func _process(_delta):
client.poll()
void send_command(command: String, callback: Callable = Callable()) 🔗
Sends a command to the RCON server. The response will be provided via the command_response signal and the optional callback.
The callback should accept one String parameter (the response).
# With callback
client.send_command("status", func(response):
print("Status: ", response)
)
# Without callback (use signal instead)
client.send_command("players")
String send_command_sync(command: String, timeout: float = 5.0) 🔗
Sends a command and blocks until a response is received or the timeout expires. Returns the response string, or an empty string if the command times out.
Warning: This is a blocking call that will freeze your game until the response is received. Use send_command() with a callback for non-blocking operations.
var status = client.send_command_sync("status", 5.0)
print("Server status: ", status)
void send_raw_packet(packet: PackedByteArray) 🔗
Sends a raw packet to the server. Use RCONPacket methods to construct packets manually for low-level protocol control.
var packet = RCONPacket.create_source_command(1, "custom")
client.send_raw_packet(packet)