A small Rust cdylib component showing the full player lifecycle using the
open.mp C API:
- registers
onPlayerConnectandonPlayerDisconnect - loads or creates player state from SQLite on connect
- applies saved state to the live player
- snapshots live player state and saves it on disconnect
- keeps unsafe C API access isolated behind a thin wrapper
This is intentionally an example/skeleton. The C API is callback-oriented and fairly new, so keep the unsafe edge small and verify against your target open.mp build.
include/ompcapi.h vendored single-header C API
build.rs bindgen-based Rust FFI generation
src/lib.rs component entrypoint and event registration
src/openmp.rs unsafe open.mp wrapper helpers
src/lifecycle.rs connect/disconnect orchestration
src/store.rs SQLite persistence and tests
cargo build --releaseThe shared library will be at:
target/release/libopenmp_rust_sqlite_lifecycle.so
Copy/rename it into your open.mp components/ directory according to your
server's component loading convention.
By default the database is created at:
scriptfiles/players.sqlite3
Override it with:
OPENMP_PLAYER_DB=/path/to/players.sqlite3 ./omp-serverThe sample schema stores:
- name
- score
- money
- health / armor
- skin
- x/y/z position and facing angle
- interior
- virtual world
- timestamps
- SQLite uses
COLLATE NOCASEon player names soDananddanmap to the same row. - The example uses synchronous SQLite calls inside event callbacks for clarity. For heavy production workloads, queue saves to a worker thread and avoid blocking the server hot path.
rusqliteis built with bundled SQLite for easy deployment.