Skip to content

AnyaJain/multiplayer-tic-tac-toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Identity-Verified Multiplayer Arena

CS6.201 — Introduction to Software Systems, S26

A full-stack real-time multiplayer web application with biometric login. Players authenticate via facial recognition against scraped profile images, then enter a live lobby to challenge each other to Tic-Tac-Toe. Ratings update after every match using the Elo system.

Stack

Layer Technology
Backend FastAPI (Python)
Real-time WebSockets
Relational DB MySQL 8 (Docker)
Asset DB MongoDB Atlas
Facial Recognition face-recognition (dlib)
Containerisation Docker + Docker Compose

Project Structure

.
├── main.py                            # FastAPI app, all routes and WebSocket endpoints
├── db.py                              # MySQL + MongoDB connection helpers
├── scraper.py                         # One-time data harvesting script (Phase 1)
├── lobby_classes.py                   # WebSocket connection manager, Elo logic
├── mysql_schema.sql                   # MySQL schema (auto-run by Docker on first start)
├── batch_data.csv                     # Student uid, name, website_url data
├── docker-compose.yml
├── Dockerfile
├── utils/
│   ├── auth.py                        # Facial auth pipeline, session management
│   ├── facial_recognition_module.py   # Black-box module (do not modify)
│   └── face_recog_tester.py
├── login.html / login.css / login.js
├── lobby.html / lobby.css / lobby.js
├── leaderboard.html / leaderboard.css / leaderboard.js
└── styles.css                         # Shared styles

Database Schemas

MySQL — relational_data database

CREATE TABLE IF NOT EXISTS users (
    uid        VARCHAR(50)  PRIMARY KEY,
    name       VARCHAR(100) NOT NULL,
    elo_rating INT          DEFAULT 1200,
    is_online  BOOLEAN      DEFAULT FALSE
);

This table is automatically created by Docker on first startup via mysql_schema.sql. You do not need to run this manually.

MongoDB Atlas — ImgAssetStorage_DB database

Collection: results

{
  "uid":         "2025XXXXXX",
  "image_bytes": "<binary image data>"
}

No schema setup needed — MongoDB is schemaless. The scraper populates this collection.

Prerequisites

  • Docker + Docker Compose installed and running
  • A .env file in the project root (get this from a teammate — never committed to git)
  • MongoDB Atlas cluster with network access set to 0.0.0.0/0 (allow from anywhere)

.env format

connection_string=mongodb://username:password@cluster.mongodb.net/?authSource=admin
mysql_host=mysql
mysql_user=root
mysql_password=rootpassword
mysql_database=relational_data

Use mongodb:// not mongodb+srv:// — the SRV format causes connection issues in Docker.

Setup and Running

Step 1 — Build and start containers

docker compose up --build   # first time (takes 10–20 min due to dlib compilation)
docker compose up           # subsequent starts

Step 2 — Run the scraper (once only)

In a separate terminal while containers are running:

docker compose exec app python3 scraper.py

This scrapes profile images from each student's website, stores them in MongoDB, and inserts user metadata into MySQL. Only needs to be run once — data persists across restarts.

Step 3 — Access the app

# Find your local IP
ip addr show | grep "inet " | grep -v 127.0.0.1   # Linux
ipconfig getifaddr en0                              # Mac
  • You (host): http://localhost:8000
  • Other players (same WiFi): http://<your-local-ip>:8000
  • Remote access via ngrok: ./ngrok http 8000 then share the https:// URL

Note: First startup takes a few extra minutes — the server pre-computes face encodings for all students before accepting requests. Watch progress with docker compose logs app --follow and wait for CACHE BUILT before trying to log in.

Note: If hosting via ngrok, camera access works out of the box since ngrok provides HTTPS. For local network HTTP on Chrome, go to chrome://flags/#unsafely-treat-insecure-origin-as-secure, add your IP URL, set to Enabled, and relaunch. Firefox allows camera on local HTTP by default.

Common Commands

Command What it does
docker compose up --build First-time build and start
docker compose up Start normally
docker compose down Stop everything
docker compose logs app --follow Watch app logs live
docker compose exec app python3 scraper.py Run scraper (once only)
docker compose exec mysql mysql -u root -prootpassword relational_data -e "SELECT uid, name, is_online, elo_rating FROM users;" Inspect MySQL data

Common Pitfalls

  • Face not recognised at login: Check if the database has records. If empty, run docker compose exec app python3 scraper.py to populate it.
  • MongoDB timeout on startup: Your network may be blocking port 27017. Switch to mobile hotspot and try again. University/corporate WiFi often blocks this port.
  • Camera not working on Chrome over HTTP: Use the Chrome flag workaround above, or use ngrok for HTTPS.
  • Port 8000 not reachable from other devices: Run sudo firewall-cmd --add-port=8000/tcp --permanent && sudo firewall-cmd --reload on Linux.

Assumptions Made

  • All profile images are accessible at <website_url>/images/pfp.jpg
  • One person hosts the server; all players connect via browser
  • MongoDB Atlas network access is set to allow connections from anywhere (0.0.0.0/0)
  • The mongodb:// connection string format must be used instead of mongodb+srv:// due to Docker networking constraints
  • The facial recognition threshold is 0.7 as set in facial_recognition_module.py
  • Face encodings are pre-computed once at server startup via build_encodings_cache() — login is fast after startup, but first startup takes time proportional to the number of students in the database
  • Player Elo ratings start at 1200 (standard chess default)
  • A player who disconnects mid-game forfeits the match

Dependencies

Python packages (installed via Docker):

fastapi, uvicorn, pymongo, mysql-connector-python,
python-dotenv, face-recognition, numpy, pillow,
requests, jinja2, websockets

AI Usage

This project used generative AI tools (Claude and Gemini) for boilerplate generation, HTML/CSS styling, syntax debugging, and Docker configuration assistance. All system architecture, design decisions, and integration logic were independently developed by the team. Full chat logs with prompts and model outputs are attached as required per the AI usage policy.

Anya

Arnav (Gemini Student Pro)

Shevani

Initilly taken screenschots are on the google doc and some links are at the bottom of the doc

Mysql related

Mongobd altas setup

debugging

Leaderboard

Ngrok setup and more debugging

About

A multiplayer tic-tac-toe for students of my batch, login using facial recognition and play :)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors