<?php
require_once __DIR__ . '/../../_bootstrap.php';
require_once ROOT_PATH . '/includes/match_functions.php';
if ($_SERVER['REQUEST_METHOD']!=='POST') jsonResponse(['ok'=>false,'erro'=>'Método não permitido.'],405);
afValidarCsrfApi();
$u = afApiOuSessaoUsuario($pdo,'public_live');
$d = requestJson();
$token = preg_replace('/[^a-f0-9]/','',strtolower((string)($d['s'] ?? '')));
$p = afBuscarPartidaPublicaPorToken($pdo,$token,false,(int)$u['id']);
if ($p) afSairComoEspectador($pdo,(int)$p['id'],(int)$u['id']);
jsonResponse(['ok'=>true]);
