samp.directory
← Scripts and libraries

NullSablex/env-samp

Rust plugin for SA-MP and Open Multiplayer that loads a .env file at startup and exposes the values to Pawn through a single typed Env() native (string, int, float, bool). Universal .so/.dll, no hardcoded credentials, strongly-typed API, UTF-8-safe.

Plugin★ 1updated 4 days agoAGPL-3.0Rust
Open on GitHub
Try it in the Pawn compiler →

Adds its include files, with the libraries it depends on, to the Pawn compiler in your browser, ready to include in a script.

README.md

env_samp

Environment variables (.env) plugin for SA-MP and Open Multiplayer, written in Rust. Loads a .env file at startup and exposes the values to Pawn through a single typed native.

Designed to eliminate hardcoded credentials in Pawn code, keeping secrets out of version control and centralized in a single configuration file.

The same .so / .dll runs on SA-MP and on Open Multiplayer — natively as a component (recommended) or via legacy mode.

Documentation

Full documentation lives at https://env-samp.nullsablex.com/:

The Markdown sources are in docs/ — uv tool run --from "$(cat requirements-docs.txt)" zensical serve from the repo root for a local preview.

Examples

  • examples/example.pwn — minimal gamemode using Env for string/int/float/bool and EnvCount.
  • examples/env — annotated .env covering every syntax feature the parser accepts (quoting, escapes, inline comments, duplicates, etc.). Copy it to .env at the server root and edit the values.

Quick start

#include <a_samp>
#include <env_samp>

public OnGameModeInit()
{
    new host[64];
    if (Env("MYSQL_HOST", host))
    {
        printf("[env_samp] MYSQL_HOST=%s", host);
    }

    new port;
    if (Env("MYSQL_PORT", port, ENV_INT))
    {
        printf("[env_samp] MYSQL_PORT=%d", port);
    }

    return 1;
}

Run the example .env alongside your server and call this from OnGameModeInit.

Build

Requires Rust stable with the 32-bit targets installed. On Linux:

./scripts/build-linux.sh   # builds .so + .dll into dist/

On Windows (Git Bash):

./scripts/build-windows.sh

Both scripts read PLUGIN_NAME from Cargo.toml, install missing rustup targets and produce dist/env_samp.so and dist/env_samp.dll.

Security

  • The .env is read once at startup. No runtime reload.
  • Values are never logged. Only error/warning messages about the file itself are emitted.
  • Files larger than 1 MiB are rejected.
  • Add .env to .gitignore. Never commit credentials.
  • Use examples/env as a public template without real values.

License

This project is distributed under the GNU Affero General Public License v3.0 or later.

You can use, modify and redistribute it freely, provided that derivative works are released under the same license with source code available. Because it is AGPL, modifications used on servers accessible over the network must also have their source offered to the users interacting with that instance.

dotenvenvironment-variablesopen-mpopen-multiplayerpawnrustsa-mpsampsamp-plugin

This page is built from what GitHub publishes about the repository. samp.directory does not host the code. Report a problem with this listing

NullSablex/env-samp: SA-MP Plugin | samp.directory