This backend application provides APIs for a pixel-based map game where users can place and view pixels on a map. It uses Flask for the web framework, Flask-Login for user authentication, and SQLite for the database. Users need to wait for a cooldown period between pixel placements.
- User registration and login with bcrypt for password hashing.
- Protected endpoints requiring user authentication.
- APIs to place pixels, view placed pixels, and get user statistics.
- Cooldown mechanism to prevent spamming pixel placements.
- CORS
- Python 3.9
- Docker (for containerization)
git clone https://github.com/JakeTurner616/map-pixel-backend
cd map-pixel-backend
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
python backend.py
The application should now be running on http://localhost:5000
.
-
Register:
POST /register
- Request Body:
{"username": "your_username", "password": "your_password"}
- Response:
{"message": "Registration successful"}
- Request Body:
-
Login:
POST /login
- Request Body:
{"username": "your_username", "password": "your_password"}
- Response:
{"message": "Login successful"}
- Request Body:
-
Logout:
POST /logout
- Response:
{"message": "Logout successful"}
- Response:
-
Place Pixel:
POST /api/update_pixels
- Request Body:
{"pixels": [{"lat": 51.505, "lng": -0.09, "color": "#ff0000"}]}
- Response:
{"status": "success", "user_id": 1, "next_allowed_time": "2024-07-02T14:00:00Z"}
- Request Body:
-
Get Map:
GET /api/get_map
- Response:
{"pixels": [{"lat": 51.505, "lng": -0.09, "color": "#ff0000", "user_id": 1, "placed_at": "2024-07-02T14:00:00Z", "username": "user1"}]}
- Response:
-
User Statistics:
GET /api/user_stats
- Response: User-specific and world statistics
-
Next Allowed Time:
GET /api/next_allowed_time
- Response:
{"next_allowed_time": "2024-07-02T14:00:00Z"}
- Response:
A Dockerfile is provided to containerize the application.
docker build -t map-pixel-backend .
docker run -p 50617:50617 map-pixel-backend
The application should now be accessible at http://localhost:50617
.
REACT_APP_BACKEND_URL
: URL of the backend server.REACT_APP_HCAPTCHA_SITE_KEY
: Site key for HCaptcha.
- Ensure you replace
"https://serverboi.org"
and"http://localhost:3000"
in the CORS setup with your actual frontend domains.
This project is licensed under the GNU GPL 3.0 License. See the License file for details.