Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 1.53 KB

File metadata and controls

72 lines (53 loc) · 1.53 KB

SA-MP Query/RCON API (Flask)

Small API project using Flask for reading SA-MP server info and sending RCON commands via UDP

Installation and Running

  1. Create a virtualenv (recommended)
python3 -m venv .venv
source .venv/bin/activate  # macOS/Linux or Windows: .venv\\Scripts\\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run in debug mode
python samp.py
# Will run at http://127.0.0.1:5000
  1. Run in production (example with gunicorn)
gunicorn -w 2 -b 0.0.0.0:8000 samp:app

Endpoints

  • POST /server/info
    • Request server info (hostname, gamemode, players, etc.)
    • Example
curl -X POST http://127.0.0.1:5000/server/info \
  -H "Content-Type: application/json" \
  -d '{
    "host": "127.0.0.1",
    "port": 7777
  }'
  • POST /server/rcon
    • Send RCON command to server (requires password)
    • Example
curl -X POST http://127.0.0.1:5000/server/rcon \
  -H "Content-Type: application/json" \
  -d '{
    "host": "127.0.0.1",
    "port": 7777,
    "password": "your_rcon_password",
    "command": "echo hello"
  }'

Important Files

  • samp.py : Main Flask API code
  • requirements.txt : List of required packages
  • .gitignore : List of files/folders to exclude from Git

Notes

  • This code sends/receives data via UDP directly to the SA-MP server. Please check your firewall and connection settings.
  • For production, it is recommended to run behind a WSGI server (such as gunicorn) and place it behind a reverse proxy (such as Nginx)