NCM ONLINEMotorsports in Night City

DEVELOPER Developer infrastructure, not a player feature.

Architecture

            Cyberpunk 2077 + OPEN//77 client                         OPEN//77 dedicated server
 ┌────────────────────────────────────────────┐        ┌──────────────────────────────────────────────┐
 │ client Lua (resources/*/client)             │ events │ server Lua (resources/*/server)               │
 │  HUD, panels (WebUI), input, presentation   │◄──────►│  league, paddock, world, economy, week …      │
 │                                             │ state  │  the authority for money, ownership, results  │
 │ native plugins (RED4ext C++ + redscript)    │  bags  │                                               │
 │  Carrier · Rig Bridge · Gearbox · Pace ·    │        │ ncm-core (pure Lua, vendored into resources)  │
 │  Broadcast · Radio · Audio · Sky · Vision … │        │                                               │
 │  ↕ loopback page relay (127.0.0.1)          │        │ MariaDB (one schema, migrations in ncm_league)│
 └────────────────────────────────────────────┘        └──────────────────────────────────────────────┘

The layers

OPEN//77 resources (ncm/online/resources/<name>/). Each resource is a directory with an open77.lua manifest declaring its permissions, scripts and files. Server scripts run in OPEN//77's server Lua VM (no os, an instruction quota per tick). Client scripts run in each player's game. Resources talk to each other through events, exports and global state bags, never through shared globals.

The main resources:

Resource Role
ncm_league The league service: schema migrations (the single owner of the database schema), calendar, races and sessions, results, economy and settlement, market, exchange, graph/contacts.
ncm_world The world layer: driver identity, presence, garage, calling cars, fuel, vehicle condition, engineering server logic, Race Week clock, scars, the F6 panel and HUD.
ncm_paddock The NPC motorsport world: generated organisations and people, its race sim and live races, garages and days, Billie, NPC markets, the news tape.
ncm_engineering, ncm_workshop, ncm_build The F9 Engineering panel, the Workshop bench, the Build primitive.
ncm_broadcast, ncm_radio, ncm_observer, ncm_scanner Presentation: names and timing tower, Race Week Live, spectator mode, the Scanner.
ncm_speed, ncm_slipstream, ncm_audio, ncm_sky, ncm_universe, ncm_space, ncm_aero Race Week speed limits, aerodynamics, physical sound, and the experimental branches.
ncm_race_week_map, ncm_world_layer, ncm_build_kit, ncm_earth_underlay World content generated by NCWE (the project's world editor).

ncm-core (ncm/core/). Pure Lua modules (Core.define("paddock.talk", function(C) … end)) with no host API calls: scoring, eligibility, economy rules, the Paddock world model, Race Week maths, engineering, parts, life sim. ncm/core/MANIFEST.lua lists them. tools/ncm-build.ps1 vendors them into every resource whose manifest carries an -- ncm-core:begin/end block, as shared/core/**. Edit ncm/core/, never the vendored copies. The core must run under both Lua 5.4 and LuaJIT, and its tests run under both.

Native plugins (ncm/<name>/). RED4ext C++ DLLs plus redscript, each its own required mod, built by its own tools/build-<name>.ps1:

Plugin Role
Carrier (ncm/carrier) Physics, parts and telemetry: applies what installed parts do to the car.
Rig Bridge (ncm/rig_bridge) DirectInput wheels and rigs, force feedback, SDL3 gamepads.
Gearbox (ncm/gearbox) NCM's manual transmission.
Pace (ncm/pace) Drives live Paddock NPC race cars on the hosting player's client.
Broadcast, Radio, Audio, Sky, Vision, Radial Names and timing tower, the radio station, physical sound, the universe renderer, scanner render and reticle, the quick menu.

Natives in redscript files carry no module line: a native inside a module compiles, but RED4ext then blocks the game from starting.

Client ↔ native transport. Client Lua cannot call a DLL directly. Each plugin serves a tiny page on a loopback port. The resource opens it as a hidden WebUI surface, and the page relays messages over a local WebSocket. The plugin checks that its peer belongs to the game's own process tree.

Persistence. MariaDB 10.11. Every row carries a server_id. Migrations are numbered Lua files in ncm/online/resources/ncm_league/server/schema/ (001 to 081 at the time of writing), applied by ncm_league/server/migrations.lua. Other resources wait for the schema version they need.

Required mods. Native plugins and third-party loaders (ArchiveXL, TweakXL, Codeware) are declared as OPEN//77 required mods. The launcher installs them on join, with consent. An undeclared plugin is disabled when a player joins an Online server.

Principles that shape the code

Single player (NCM 3.0, on hold)

ncm/host and ncm/host_native are a native RED4ext host (Lua 5.4 plus SQLite) that runs the same server resources, unchanged, inside single-player Cyberpunk. ncm/host/sql/translate.lua translates the MariaDB SQL to SQLite, and ncm/host/api/headless.lua models the Open77 API. It is in development and currently on hold.