MAD MATCHUPS: A Multiplayer Game Server for Real-Time Matchmaking!

Our hackathon submission is a Flask-based server for real-time multiplayer game matchmaking and game management. Designed with scalability and modularity in mind, this system provides a seamless experience for users waiting for an opponent and joining gameplay sessions. Here's how it works:

🎮 Overview The project is a backend server that handles player matchmaking, game creation, and state management through efficient polling and routing. Users join a waiting queue and are paired for a game session, where they can take turns making moves until a winner is determined.

🔑 Key Components Flask for Web Server and Routing:

We chose Flask to handle HTTP requests and sessions, allowing quick setup and an easy-to-manage codebase. The routes provide endpoints for both frontend rendering and API access. Environment Variables:

Sensitive data like SECRET_KEY is loaded using dotenv for secure and efficient configuration management. Session Management:

Flask sessions are used to retain player information (such as usernames) between requests. Real-Time Queue and Game Management:

We use a queue to manage players waiting to be paired for a game. Dictionary Mapping associates each username with an active game_id, allowing quick access and game retrieval. Gameplay API Integration:

This server interacts with an external gameplay_api service (on http://127.0.0.1:5001), which manages game states, player turns, and game setup. Using API requests, we retrieve game IDs, set up games, and poll game states, making it easy to swap out or extend the gameplay_api service as needed.

🚀 Key Functional Routes /join: Adds a player to the queue. /waiting: Waiting room where players stay until they’re matched. /game/: Dynamic page where users can interact with their game.

API Endpoints: /join_queue: Adds a player to the queue via API. /check_for_game: Polls to see if a user is assigned a game. /poll_game_state/: Checks the current game state. /poll_turn/: Verifies if it’s the player’s turn. /submit_move: Submits the player’s move to the server.

🧠 Intelligent Pairing and Background Threading The pairing mechanism runs continuously in a background thread. When at least two players are in the queue, they’re paired and assigned a new game. Error handling checks to ensure a game ID is retrieved before starting the game.

🛠️ Tech Stack and Design Choices Flask: Lightweight and ideal for rapid development. Threading: Ensures pairing operates in the background without blocking the main application. Session-Based User Management: Maintains a simple, scalable approach to user sessions. Modular Gameplay API: Supports easy integration with other services or game APIs, making the system flexible and extensible.

🏆 Why This Project? This server architecture is designed for easy scaling and integration, supporting dynamic multiplayer matchmaking and game state management. By decoupling game mechanics and matchmaking logic, it’s adaptable to different game types and APIs. This makes it an excellent framework for future multiplayer applications or integrating more complex games.

Share this project:

Updates