RLBot Sockets Specification
Data Types
Bold items indicate the messages that bots/scripts/etc. can recieved from RLBot.
- None
- Aka the disconnect request. This can be sent to indicate that you want to disconnect, and this message will be sent back as confirmation of the disconnect. Ideally your bot only disconnects after this message is sent. If anything else happens, an error should be put out.
- GamePacket
- Received by sessions at a high rate according to tick rate
- FieldInfo
- Received by a session after it sends
ConnectionSettings
.
- Received by a session after it sends
- StartCommand
- Starts a new match after reading the given config file.
- MatchConfiguration
- Received by a session after it sends
ConnectionSettings
. - Can be sent by sessions to start a new match.
- Received by a session after it sends
- PlayerInput
- Sent by sessions to control their cars.
- DesiredGameState
- Sent by sessions to change the game state.
- Ignored if state setting was disabled in the match settings.
- RenderGroup
- Sent by sessions to render lines & text in the game.
- Ignored if render setting was disabled in the match settings.
- RemoveRenderGroup
- Sent by sessions to remove a render group.
- Ignored if render setting was disabled in the match settings.
- MatchComm
- A copy is received by sessions when another session sends the message.
- Messages may not be received if the message was filtered due to
team_only
being requested in the message. - Only received if enabled in
ConnectionSettings
.
- BallPrediction
- Received by sessions right before every
GamePacket
if enabled inConnectionSettings
.
- Received by sessions right before every
- ConnectionSettings
- Sessions send this immediately after connecting.
- Tells the server what kind of data it wants to receive.
- StopCommand
- Ends the current match, and optionally tells
RLBotServer.exe
to shut itself down.
- Ends the current match, and optionally tells
- SetLoadout
- Sent by sessions to change the loadout of their cars.
- Will always work if a loadout was not specified in match settings and when sent before
InitComplete
. - Ignored if state setting was disabled in the match settings, and a loadout was set in match settings.
- InitComplete
- Indicates that the session has finished all initialization and is ready to start receiving game messages without delay.
- The match will not start until all sessions have sent this message.
- There is no data associated with this message.
- ControllableTeamInfo
- Contains information about the cars that the client can control.
- Received by a session after it sends
ConnectionSettings
. - There may be more than one car in case the bot is a hivemind.
Connecting to RLBotServer
- Read the environment variable
RLBOT_SERVER_IP
and default to127.0.0.1
- Read the environment variable
RLBOT_SERVER_PORT
and default to23234
- Connect to the given IP/port via TCP.
Message format
This project uses flatbuffers as the data format, prefixed with a 2 32-bit unsigned integer. All messages should be big endian.
- Read the first 32-bit unsigned integer. This is the data type.
- Read the second 32-bit unsigned integer. This is
n
, the length of the flatbuffer in bytes. - Read
n
bytes, and deserialize this into the correct flatbuffer according to the data type.
Replace "read" with "write" to send a message.
Connection handshake
After connecting to RLBotServer via TCP, bots and scripts must perform a handshake to get access to game data. If this is not performed, then various functionality will be limited, for example, all player inputs will be rejected by the server.
- Send a
ConnectionSettings
- The environment variable
RLBOT_AGENT_ID
will be set by RLBotServer before launching your process. This can be passed asAgentId
, or a hardcoded default can be used if the environment variable was not present. A hardcoded default is useful during development when the process may be getting started manually. - For bots & scripts,
CloseBetweenMatches
should always betrue
with no alternate option.
- The environment variable
- Recieve match information - In no guarenteed order, wait for all of the following to arrive:
MatchConfiguration
FieldInfo
ControllableTeamInfo
- sent for bots & scripts. IfAgentId
was invalid or blank, this will be empty. If this was intentional, continue as normal.
- Parse
ControllableTeamInfo
for yourteam
,index
(s), andspawnId
(s). There will be multiple if this is a bot that was designated as a hivemind.- If
team
is0
or1
:index
will be the index of your bot inGamePacket
- If
team
is2
:index
will be the index of your script inMatchConfiguration
- If
spawnId
can be used to find your bot/scripts's name inMatchConfiguration
.- DO NOT USE
index
FOR BOTS, they are not in the correct order inMatchConfiguration
. Usingindex
is ok for scripts butspawnId
can be used for both.
- DO NOT USE
- Perform heavy initialization.
- At this point, most information needed for bots to initialize most of their variables is known. Have some kind of callback that lets developers do this now. RLBotServer will load the map but won't start the match while bots are initializing.
- Send
InitComplete
. This is a message with no content, and signifies to RLBotServer that the match can be started. - Done, enter main control loop
Main control loop
Requires the connection handshake to have been performed first. Depending on what was sent in ConnectionSettings
, some of the following packets may not be sent.
- Every tick,
BallPrediction
will always be sent beforeGamePacket
. - If
BallPrediction
is not sent, it's because it was disabled inConnectionSettings
MatchComm
will arrive in between ticks. The sending of these messages can be disabled inConnectionSettings