Spaces:
Sleeping
Sleeping
Update main.py
Browse files18 unmodified lines192021222322232624252629 unmodified lines565758625960616662636465667273676869454 unmodified lines52452552653452718 unmodified lines await pool.stop()
app = FastAPI(title="Deepcastle Engine API", lifespan=lifespan)
# βββ Multiplaying / Challenge Manager ββββββββββββββββββββββββββββββββββββββββββclass ConnectionManager: def __init__(self): # match_id -> list of websockets self.active_connections: Dict[str, List[WebSocket]] = {}
async def connect(self, websocket: WebSocket, match_id: str):29 unmodified lines try: while True: data = await websocket.receive_text() # Relay the message (move, etc.) to others in the same room await manager.broadcast(data, match_id, exclude=websocket) except WebSocketDisconnect: manager.disconnect(websocket, match_id) # Notify remaining players that opponent disconnected β they win await manager.broadcast(json.dumps({"type": "opponent_disconnected"}), match_id) except Exception: manager.disconnect(websocket, match_id) await manager.broadcast(json.dumps({"type": "opponent_disconnected"}), match_id)
# Allow ALL for easy testing (we can restrict this later if needed)app.add_middleware( CORSMiddleware, allow_origins=["*"],454 unmodified lines
if __name__ == "__main__": import uvicorn # Hugging Face Spaces port is 7860 uvicorn.run(app, host="0.0.0.0", port=7860)main.py-8