Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77e512be5b |
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirección si el usuario no ha iniciado sesión
|
||||||
|
if (!isset($_SESSION['idUsuario'])) {
|
||||||
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
||||||
|
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
||||||
|
?>
|
||||||
+8
-63
@@ -3,43 +3,6 @@ let usuarioYaEstaEnEquipo = false;
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
comprobarSalaUsuario();
|
comprobarSalaUsuario();
|
||||||
});
|
});
|
||||||
// ==========================================================================
|
|
||||||
// DETECTOR DE INICIO DE PARTIDA PARA JUGADORES INVITADOS (1 VS 1)
|
|
||||||
// ==========================================================================
|
|
||||||
$(document).ready(function () {
|
|
||||||
// Solo activamos el vigilante si estamos en la página del buscador de salas
|
|
||||||
if (window.location.pathname.includes("buscadorSala.php")) {
|
|
||||||
setInterval(function () {
|
|
||||||
// 1. Preguntamos al servidor en qué partida está metido el usuario actual
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorEquipoxUsuario.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: { orden: "obtenerSalaUsuario" },
|
|
||||||
success: function (sala) {
|
|
||||||
// Si el usuario está metido en una sala/partida activa...
|
|
||||||
if (sala.asociado && sala.idPartida) {
|
|
||||||
// 2. Comprobamos si el anfitrión ya ha iniciado esa partida concreta
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorPartida.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: { orden: "buscar", idPartida: sala.idPartida },
|
|
||||||
success: function (partida) {
|
|
||||||
// Si 'fechaInicio' ya no es null, significa que el host le dio a "Jugar"
|
|
||||||
if (partida && partida.fechaInicio !== null) {
|
|
||||||
// Redirigimos instantáneamente al invitado a la pantalla del juego
|
|
||||||
window.location.href =
|
|
||||||
"juego.php?idPartida=" + sala.idPartida;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}, 2000); // Comprueba el estado de la partida automáticamente cada 2 segundos
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
||||||
function comprobarSalaUsuario() {
|
function comprobarSalaUsuario() {
|
||||||
@@ -216,11 +179,11 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
|
|
||||||
// Solo el host puede iniciar la partida
|
// Solo el host puede iniciar la partida
|
||||||
if (esHost) {
|
if (esHost) {
|
||||||
// Así debe renderizarse el botón del host dentro de tu función mostrarSala() para que el AJAX funcione:
|
|
||||||
botonIniciarHTML = `
|
botonIniciarHTML = `
|
||||||
<button type="button" id="btnInicioJuego" data-id-partida="${partida.idPartida}" class="btn btn-success btn-lg px-4">
|
<a href="juego.php?idPartida=${partida.idPartida}"
|
||||||
|
class="btn btn-success btn-lg px-4">
|
||||||
<i class="bi bi-controller"></i> ¡Iniciar Partida!
|
<i class="bi bi-controller"></i> ¡Iniciar Partida!
|
||||||
</button>
|
</a>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,8 +266,7 @@ let botonAbandonarReferencia = null;
|
|||||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||||
botonAbandonarReferencia = $(this);
|
botonAbandonarReferencia = $(this);
|
||||||
|
|
||||||
const esHost =
|
const esHost = $(this).data("es-host") === true || $(this).data("es-host") === "true";
|
||||||
$(this).data("es-host") === true || $(this).data("es-host") === "true";
|
|
||||||
const titulo = $("#modalAbandonarSalaLabel");
|
const titulo = $("#modalAbandonarSalaLabel");
|
||||||
const mensaje = $("#modalAbandonarSalaMensaje");
|
const mensaje = $("#modalAbandonarSalaMensaje");
|
||||||
const botonConfirmar = $("#btnConfirmarAbandonar");
|
const botonConfirmar = $("#btnConfirmarAbandonar");
|
||||||
@@ -317,7 +279,9 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
botonConfirmar.text("Sí, abandonar");
|
botonConfirmar.text("Sí, abandonar");
|
||||||
} else {
|
} else {
|
||||||
titulo.text("¿Abandonar la sala?");
|
titulo.text("¿Abandonar la sala?");
|
||||||
mensaje.text("Si sales de la sala, perderás tu lugar en el equipo.");
|
mensaje.text(
|
||||||
|
"Si sales de la sala, perderás tu lugar en el equipo.",
|
||||||
|
);
|
||||||
botonConfirmar.text("Sí, salir");
|
botonConfirmar.text("Sí, salir");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,6 +292,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
modal.show();
|
modal.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||||
const modalEl = document.getElementById("modalAbandonarSala");
|
const modalEl = document.getElementById("modalAbandonarSala");
|
||||||
@@ -438,7 +403,6 @@ $("#btnCrearSala").on("click", function () {
|
|||||||
|
|
||||||
if (respuesta.exito) {
|
if (respuesta.exito) {
|
||||||
$("#modalCrearSala").modal("hide");
|
$("#modalCrearSala").modal("hide");
|
||||||
|
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -469,22 +433,3 @@ $(document).on("input", ".input-kahoot", function () {
|
|||||||
$(this).removeClass("is-invalid");
|
$(this).removeClass("is-invalid");
|
||||||
$(this).next(".mensaje-error-sala").remove();
|
$(this).next(".mensaje-error-sala").remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("click", "#btnInicioJuego", function () {
|
|
||||||
// 1. Capturamos el id de la partida de forma dinámica desde el botón que se ha pulsado
|
|
||||||
const idPartida = $(this).data("id-partida");
|
|
||||||
|
|
||||||
// 2. Enviamos la petición AJAX adecuada con TODOS los datos que el controlador espera recibir
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorPartida.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: {
|
|
||||||
orden: "iniciar",
|
|
||||||
idPartida: idPartida,
|
|
||||||
},
|
|
||||||
error: function (error) {
|
|
||||||
console.error("Error al iniciar el juego por AJAX:", error);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
+2
-12
@@ -1,17 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
require_once '/controladores/controladorPerfil.php';
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirección si el usuario no ha iniciado sesión
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
|
||||||
header('Location: login.php');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
|
||||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user