RCONPacket
Inherits: RefCounted < Object
Low-level packet utility for RCON protocol handling.
Description
RCONPacket provides static methods for creating and parsing RCON packets for both Source RCON (TCP) and BattlEye RCON (UDP) protocols. This class is useful for advanced users who need direct control over packet construction and parsing.
For most use cases, RCONServer and RCONClient provide higher-level abstractions that handle packets automatically.
Note: This class only provides static utility methods and does not need to be instantiated.
Tutorials
Methods
create_battleye_command(seq: int, command: String) static |
|
create_battleye_login(password: String) static |
|
create_battleye_message_ack(seq: int) static |
|
create_source_auth(id: int, password: String) static |
|
create_source_command(id: int, command: String) static |
|
parse_battleye_packet(data: PackedByteArray) static |
|
parse_source_packet(data: PackedByteArray) static |
|
verify_battleye_crc32(packet: PackedByteArray) static |
Enumerations
enum SourcePacketType: 🔗
SourcePacketType SOURCE_SERVERDATA_AUTH = 3
Source RCON authentication request packet type.
SourcePacketType SOURCE_SERVERDATA_AUTH_RESPONSE = 2
Source RCON authentication response packet type. Also used for command execution packets.
SourcePacketType SOURCE_SERVERDATA_EXECCOMMAND = 2
Source RCON command execution packet type. Shares the same value as AUTH_RESPONSE.
SourcePacketType SOURCE_SERVERDATA_RESPONSE_VALUE = 0
Source RCON response value packet type (server response to commands).
enum BattlEyePacketType: 🔗
BattlEyePacketType BATTLEYE_LOGIN = 0
BattlEye RCON login/authentication packet type.
BattlEyePacketType BATTLEYE_COMMAND = 1
BattlEye RCON command packet type (both request and response).
BattlEyePacketType BATTLEYE_MESSAGE = 2
BattlEye RCON server message packet type (server-pushed messages).
Method Descriptions
PackedByteArray create_battleye_command(seq: int, command: String) static 🔗
Creates a BattlEye RCON command packet with the given sequence number and command string. The packet includes proper header, CRC32 checksum, and payload formatting.
The seq value should increment for each command (0-255, wrapping around).
var packet = RCONPacket.create_battleye_command(5, "players")
# Send packet via UDP
PackedByteArray create_battleye_login(password: String) static 🔗
Creates a BattlEye RCON login packet with the given password. This packet must be sent first to authenticate with a BattlEye RCON server.
var packet = RCONPacket.create_battleye_login("mypassword")
# Send packet via UDP
PackedByteArray create_battleye_message_ack(seq: int) static 🔗
Creates a BattlEye RCON server message acknowledgment packet. When the server sends a message, clients must acknowledge it within 10 seconds or risk disconnection.
The seq value should match the sequence number from the server message.
# When receiving server message with seq=3
var ack = RCONPacket.create_battleye_message_ack(3)
# Send acknowledgment
PackedByteArray create_source_auth(id: int, password: String) static 🔗
Creates a Source RCON authentication packet with the given request ID and password. This packet must be sent first to authenticate with a Source RCON server.
The id should be a unique identifier (typically 0 for auth packets).
var packet = RCONPacket.create_source_auth(0, "admin123")
# Send packet via TCP
PackedByteArray create_source_command(id: int, command: String) static 🔗
Creates a Source RCON command execution packet with the given request ID and command string. The server will echo the id in its response, allowing you to match responses to requests.
var packet = RCONPacket.create_source_command(1, "status")
# Send packet via TCP
Dictionary parse_battleye_packet(data: PackedByteArray) static 🔗
Parses a BattlEye RCON packet and returns a Dictionary with the packet contents. Returns a Dictionary with valid set to false if the packet is malformed or has an invalid CRC32.
The returned Dictionary contains:
valid: bool - Whether the packet is validtype: int - Packet type (BATTLEYE_LOGIN, BATTLEYE_COMMAND, or BATTLEYE_MESSAGE)seq: int - Sequence number (for commands and messages)data: String - Command response datamessage: String - Server message (for MESSAGE packets)success: bool - Authentication result (for LOGIN responses)multi_packet: bool - Whether this is part of a multi-packet responsetotal_packets: int - Total packets in multi-packet responsepacket_index: int - Index of this packet in multi-packet response
var parsed = RCONPacket.parse_battleye_packet(received_data)
if parsed.valid:
print("Type: ", parsed.type)
print("Data: ", parsed.get("data", ""))
Dictionary parse_source_packet(data: PackedByteArray) static 🔗
Parses a Source RCON packet and returns a Dictionary with the packet contents. Returns a Dictionary with valid set to false if the packet is malformed.
The returned Dictionary contains:
valid: bool - Whether the packet is validsize: int - Packet sizeid: int - Request IDtype: int - Packet type (SOURCE_SERVERDATA_AUTH, SOURCE_SERVERDATA_EXECCOMMAND, etc.)body: String - Packet body/payload
var parsed = RCONPacket.parse_source_packet(received_data)
if parsed.valid:
print("ID: ", parsed.id)
print("Body: ", parsed.body)
bool verify_battleye_crc32(packet: PackedByteArray) static 🔗
Verifies the CRC32 checksum of a BattlEye RCON packet. Returns true if the checksum is valid, false otherwise.
This is automatically checked by parse_battleye_packet(), but can be used separately for validation.
if RCONPacket.verify_battleye_crc32(packet):
print("Packet checksum valid")
else:
print("Corrupted packet!")