Actualizar sistema de admin y mejoras en lobby

This commit is contained in:
2025-08-15 12:04:12 -06:00
parent e14bdddc62
commit 232c159baf
6 changed files with 385 additions and 0 deletions

View File

@@ -82,6 +82,13 @@
<div class="control-group">
<h3>Player Management</h3>
<div class="control-buttons">
<button
@click="shufflePlayers"
class="btn btn-shuffle"
:disabled="isLoadingGlobal"
>
🎲 Shuffle Players
</button>
<button
@click="sendAllToLobby"
class="btn btn-lobby-all"
@@ -386,6 +393,30 @@ async function changeGlobalVariant() {
}
}
async function shufflePlayers() {
if (!confirm('Are you sure you want to SHUFFLE all players? This will randomly redistribute players between rooms and assign new roles!')) return;
isLoadingGlobal.value = true;
try {
const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3000/api'}/admin/shuffle-players`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
if (!response.ok) throw new Error('Failed to shuffle players');
const result = await response.json();
console.log('Players shuffled successfully:', result.message);
alert(`Shuffle completed! ${result.message}`);
await fetchData();
} catch (error) {
console.error('Failed to shuffle players:', error);
alert('Failed to shuffle players. Check console for details.');
} finally {
isLoadingGlobal.value = false;
}
}
async function sendAllToLobby() {
if (!confirm('Are you sure you want to send ALL players back to the lobby? This will end all active games!')) return;
@@ -683,6 +714,11 @@ const selectedRoom = computed(() => {
color: white;
}
.btn-shuffle {
background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
color: white;
}
.btn-lobby-all {
background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
color: white;

View File

@@ -211,6 +211,23 @@ onMounted(() => {
// Handle room closure/disconnection
room.onLeave((code) => {
console.log('[DemoGame] Room disconnected with code:', code);
// Handle shuffle disconnection specially
if (code === 1002) {
console.log('[DemoGame] Disconnected for player shuffle - will redirect to lobby');
try {
if (typeof window !== 'undefined') {
window.localStorage.removeItem('snatch.game.roomId');
window.localStorage.removeItem('snatch.game.sessionId');
}
} catch {}
// Redirect to lobby and let it handle the shuffle redirect
router.push('/');
return;
}
// Normal disconnection handling
// Always clean up local storage when room closes
try {
if (typeof window !== 'undefined') {