Skip to content

forjd-hermes-bot/openmp-rust-sqlite-lifecycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

open.mp Rust SQLite Lifecycle Example

A small Rust cdylib component showing the full player lifecycle using the open.mp C API:

  • registers onPlayerConnect and onPlayerDisconnect
  • 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.

Layout

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

Build

cargo build --release

The 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.

Runtime config

By default the database is created at:

scriptfiles/players.sqlite3

Override it with:

OPENMP_PLAYER_DB=/path/to/players.sqlite3 ./omp-server

What gets persisted

The sample schema stores:

  • name
  • score
  • money
  • health / armor
  • skin
  • x/y/z position and facing angle
  • interior
  • virtual world
  • timestamps

Notes

  • SQLite uses COLLATE NOCASE on player names so Dan and dan map 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.
  • rusqlite is built with bundled SQLite for easy deployment.

About

Example open.mp C API Rust component with SQLite-backed player lifecycle state

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors