Skip to content
/ samp-api Public

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

License

Notifications You must be signed in to change notification settings

xNewz/samp-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages