RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

server/commands - Camera & Input Commandsge_utils - Game Engine Utility Functionsmain.lua - GE Lua Entry Point & Game Loopmap.lua - Navigation Graph (AI Road Map)screenshot.lua - Screenshot Systemserver/server - Level Loading & Game ServerserverConnection - Client-Server Connection Manager`setSpawnpoint` - Default Spawn Point Persistence`simTimeAuthority` - Simulation Time & Bullet Time Control`spawn` - Vehicle Spawning & Safe Placement`suspensionFrequencyTester` - Suspension Natural Frequency Analysis
C2 WebSocket Handler

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsc2

C2 WebSocket Handler

Core WebSocket server for the C2 (Command & Control) system. Provides a JSON message bus on localhost for external tools to communicate with the game engine.

Core WebSocket server for the C2 (Command & Control) system. Provides a JSON message bus on localhost for external tools to communicate with the game engine.


Overview

Creates a WebSocket server on port 8088 that receives JSON messages, supports ping/pong keepalive, dynamic extension loading, and routes all other messages to registered plugins via the onC2WebSocketHandlerMessage hook.


Public API

FunctionArgsReturnsDescription
M.onExtensionLoaded--Creates WebSocket server on 127.0.0.1:8088
M.onExtensionUnloaded--Destroys WebSocket server and cleans up
M.onUpdatedt-Polls server events, decodes JSON, routes messages

Built-in Message Types

Message TypeFieldsDescription
loadExtensionextensionNameDynamically loads a GE extension by name
ping (raw)-Responds with "pong" (keepalive)

All other JSON messages are broadcast via:

extensions.hook("onC2WebSocketHandlerMessage", {
  event   = evt,
  message = jsonData,
  server  = server
})

Hook Interface

Plugins implement onC2WebSocketHandlerMessage(args) to receive messages:

-- args structure:
-- args.event   - WebSocket event (has peerId, type, msg)
-- args.message - Decoded JSON table
-- args.server  - Server object for sending responses

-- Example plugin handler (not part of this extension):
local function onC2WebSocketHandlerMessage(args)
  local msg = args.message
  if msg.type == "myCommand" then
    args.server:sendData(args.event.peerId, jsonEncode({type = "response", data = "ok"}))
  end
end

Server Details

PropertyValue
Address127.0.0.1
Port8088
ProtocolWebSocket (JSON messages)
LibraryBNGWebWSServer via utils/wsUtils

Event Processing

-- Event types from server:getPeerEvents()
-- evt.type == "D" - Data message
-- evt.msg - Raw message string
-- evt.peerId - Unique peer identifier

-- Response pattern:
server:sendData(evt.peerId, jsonEncode({type = "info", msg = "..."}))

Notes

  • Server is localhost-only (127.0.0.1) - not accessible from network
  • Invalid JSON messages are logged as errors
  • Extension loading errors are caught with pcall and reported to the client
  • The wsUtils.createOrGetWS function reuses existing servers on the same port
  • Server updates (flush/receive) happen via server:update() each frame

See Also

  • C2 Tile Manager - Scene tile data plugin
  • C2 Vehicle Manager - Vehicle streaming plugin

`suspensionFrequencyTester` - Suspension Natural Frequency Analysis

Debug extension that measures suspension natural frequencies on the player vehicle's front and rear axles. Displays an ImGui window with frequency spectrum analysis and category matching (Luxury, Spor

C2 Tile Manager

Spatial hash tile index for scene objects, forest items, decals, road markings, and AI graph nodes. Provides tile-based scene queries with debug visualization and WebSocket data export.

On this page

OverviewPublic APIBuilt-in Message TypesHook InterfaceServer DetailsEvent ProcessingNotesSee Also