/connectfour-master-server

A REST API to connect all the Connect Four players together from all over the world

Primary LanguagePythonOtherNOASSERTION

Connect Four Master Server

A REST API to connect all the Connect Four players together from all over the world.

Features

  • Web-based game browser interface with filtering capabilities
    • Ability to view every single game ever played
    • IP / name / version / status
    • Which player has won if the game is finished
    • When the game has been created, started and finished
  • REST API used by the Connect Four game itself to advertise hosts and keep online game's data up-to-date

Prerequisites

  • Should work on any Python 3.x version. Feel free to test with another Python version and give me feedback
  • A uWSGI-capable web server (optional, but recommended)

Installation

  1. Clone this repo somewhere
  2. pip install -r requirements.txt
  3. export FLASK_APP=cfms.py (Windows users: set FLASK_APP=cfms.py)
  4. flask create_database (WARNING: don't re-run this command unless you want to start from scratch, it will wipe out all the data)

Configuration

Copy the config.example.py file to config.py and fill in the configuration parameters.

Available configuration parameters are:

  • SECRET_KEY Set this to a complex random value
  • DEBUG Enable/disable debug mode

More informations on the three above can be found here.

  • GAMES_TTL Grace time (or time to live), in minutes, of the games who don't have the FINISHED status

I'll let you search yourself about how to configure a web server along uWSGI.

Usage

  • Standalone

Run the internal web server, which will be accessible at http://localhost:8080:

python local.py

Edit this file and change the interface/port as needed.

  • uWSGI

The uWSGI file you'll have to set in your uWSGI configuration is uwsgi.py. The callable is app.

  • Others

You'll probably have to hack with this application to make it work with one of the solutions described here. Send me a pull request if you make it work.

A Flask command (flask clean) is used to clean the database. It removes old games with a status different from FINISHED which have their latest ping older than now minus 5 minutes (by default). It should be ran by a Cron or some task scheduler i.e every one minute, but this isn't mandatory.

API docs

Please navigate here for the full docs.

How it works

This project is mainly powered by Flask (Python) and Flask-RESTful using a small SQLite database to persist data. HTTP requests are used to maintain the games pool up-to-date.

For more information, I suggest you do dive into the code starting with the cfms.py file.

Credits

  • This project uses GeoLite2 data created by MaxMind, available from www.maxmind.com
  • Some good parts of the OpenRA Master Server inspired me
  • Connect Four™ is a trademark of Milton Bradley / Hasbro. This project isn't supported nor endorsed by Milton Bradley / Hasbro

End words

If you have questions or problems, you can submit an issue.

You can also submit pull requests. It's open-source man!