feat: auto delete server if it is inactive for more than 5 minutes, minor fix

This commit is contained in:
2025-07-18 20:34:11 +05:00
parent 7e4e2c0bad
commit 259e3c373b
7 changed files with 126 additions and 5 deletions

View File

@ -2,6 +2,8 @@ from fastapi import APIRouter
from app.services.server.command import CommandService
from app.services.server.event import EventService
from app.models.server.command import ServerCommand
from datetime import datetime
import uuid
router = APIRouter(
prefix="/api/server",
@ -10,12 +12,29 @@ router = APIRouter(
@router.post("/events")
async def receive_server_event(event_data: dict):
# Обновляем активность сервера
server_ip = event_data.get("server_ip")
if server_ip:
await update_server_activity(server_ip)
return await EventService().process_event(event_data)
@router.post("/commands")
async def add_server_command(command_data: ServerCommand):
# Обновляем last_activity для сервера
await CommandService()._update_server_activity(command_data.server_ip)
return await CommandService().add_command(command_data)
@router.get("/commands")
async def get_server_commands(server_ip: str):
return await CommandService().get_commands(server_ip)
async def update_server_activity(server_ip):
"""Обновляет время последней активности сервера"""
from app.db.database import db
game_servers_collection = db.game_servers
await game_servers_collection.update_one(
{"ip": server_ip},
{"$set": {"last_activity": datetime.utcnow()}},
upsert=False
)

View File

@ -54,3 +54,8 @@ async def get_user_purchased_capes(username: str):
async def activate_purchased_cape(username: str, cape_id: str):
"""Активация приобретенного плаща"""
return await store_cape_service.activate_purchased_cape(username, cape_id)
@router.post("/user/{username}/capes/deactivate/{cape_id}")
async def deactivate_purchased_cape(username: str, cape_id: str):
"""Деактивация приобретенного плаща"""
return await store_cape_service.deactivate_purchased_cape(username, cape_id)