usuarios pre configurados
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Room, Client, matchMaker } from "colyseus";
|
||||
import { LobbyState, AvailableRoom } from "./schemas/LobbyState";
|
||||
import { NameManager } from "../utils/nameManager";
|
||||
import { isUuidAllowed } from "../utils/uuidRegistry";
|
||||
|
||||
export class LobbyRoom extends Room<LobbyState> {
|
||||
private updateInterval?: NodeJS.Timeout;
|
||||
@@ -33,6 +34,12 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
|
||||
onJoin(client: Client, options: any) {
|
||||
console.log(`[LobbyRoom] ${client.sessionId} joined lobby with UUID: ${options.uuid}`);
|
||||
// Enforce UUID presence and allowlist (if configured)
|
||||
if (!options.uuid || !isUuidAllowed(options.uuid)) {
|
||||
try { client.send("error", { message: "UUID inválido o faltante" }); } catch {}
|
||||
try { client.leave(1000); } catch {}
|
||||
return;
|
||||
}
|
||||
|
||||
// Store UUID mapping if provided
|
||||
if (options.uuid) {
|
||||
@@ -47,6 +54,11 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
// Add player temporarily to lobby state
|
||||
const existingName = NameManager.getInstance().getPlayerName(options.uuid);
|
||||
this.state.addPlayer(client.sessionId, existingName || "");
|
||||
const existingColor = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (existingColor) {
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) p.color = existingColor;
|
||||
}
|
||||
|
||||
// Send welcome first
|
||||
client.send("welcome", {
|
||||
@@ -68,19 +80,17 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
// Check if this UUID already has a name
|
||||
const existingName = NameManager.getInstance().getPlayerName(options.uuid);
|
||||
this.state.addPlayer(client.sessionId, existingName || "");
|
||||
const existingColor = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (existingColor) {
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) p.color = existingColor;
|
||||
}
|
||||
|
||||
client.send("welcome", {
|
||||
sessionId: client.sessionId,
|
||||
name: existingName || "",
|
||||
color: this.state.players.get(client.sessionId)?.color || "#667eea"
|
||||
});
|
||||
} else {
|
||||
// Fallback for clients without UUID (shouldn't happen in normal flow)
|
||||
this.state.addPlayer(client.sessionId, "");
|
||||
client.send("welcome", {
|
||||
sessionId: client.sessionId,
|
||||
color: this.state.players.get(client.sessionId)?.color || "#667eea"
|
||||
});
|
||||
}
|
||||
|
||||
this.updateAvailableRooms();
|
||||
@@ -116,7 +126,7 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
}
|
||||
|
||||
const uuid = this.sessionToUuid.get(client.sessionId) || client.sessionId;
|
||||
const uniqueName = NameManager.getInstance().generateUniquePlayerName(data.name, uuid);
|
||||
const uniqueName = NameManager.getInstance().setPlayerName(uuid, data.name);
|
||||
|
||||
currentPlayer.name = uniqueName;
|
||||
|
||||
@@ -134,6 +144,8 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
return;
|
||||
}
|
||||
currentPlayer.color = sanitized;
|
||||
const uuid = this.sessionToUuid.get(client.sessionId) || client.sessionId;
|
||||
NameManager.getInstance().setPlayerColor(uuid, sanitized);
|
||||
client.send("colorUpdated", { color: sanitized });
|
||||
}
|
||||
|
||||
@@ -233,4 +245,4 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
console.error("[LobbyRoom] Error updating available rooms:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user