1
0

Building but users still not listing

This commit is contained in:
James Ketr 2025-10-07 18:23:07 -07:00
parent 61ecb175aa
commit abdd6bca83
2 changed files with 14 additions and 7 deletions

View File

@ -674,7 +674,7 @@ const loadGame = async (id: string) => {
// so that a newly attached websocket will receive the consolidated
// initial snapshot. This is important for long-running dev servers
// where the in-memory cache may persist between reconnects.
const cached = games[id];
const cached = games[id]!;
for (let sid in cached.sessions) {
if (cached.sessions[sid] && cached.sessions[sid]._initialSnapshotSent) {
delete cached.sessions[sid]._initialSnapshotSent;
@ -1044,7 +1044,7 @@ const adminCommands = (game: Game, action: string, value: string, query: any): a
if (game.state !== "lobby") {
return `Game already started.`;
}
if (game.active < 2) {
if (!game.active || game.active < 2) {
return `Not enough players in game to start.`;
}
game.state = "game-order";
@ -1052,7 +1052,8 @@ const adminCommands = (game: Game, action: string, value: string, query: any): a
* code that would otherwise have to filter out players by checking
* the 'Not active' state of player.status */
for (let key in game.players) {
if (game.players[key].status !== "Active") {
const p = game.players[key];
if (!p || p.status !== "Active") {
delete game.players[key];
}
}
@ -1084,11 +1085,11 @@ const setPlayerName = (game: Game, session: Session, name: string): string | und
let rejoin = false;
for (let id in game.sessions) {
const tmp = game.sessions[id];
if (tmp === session || !tmp.name) {
if (!tmp || tmp === session || !tmp.name) {
continue;
}
if (tmp.name.toLowerCase() === name.toLowerCase()) {
if (!tmp.player || Date.now() - tmp.player.lastActive > 60000) {
if (!tmp.player || Date.now() - (tmp.player.lastActive || 0) > 60000) {
rejoin = true;
/* Update the session object from tmp, but retain websocket
* from active session */
@ -1150,8 +1151,10 @@ const setPlayerName = (game: Game, session: Session, name: string): string | und
}
game.unselected = [];
for (let id in game.sessions) {
if (!game.sessions[id].color && game.sessions[id].name) {
game.unselected.push(game.sessions[id]);
const s = game.sessions[id];
if (!s) continue;
if (!s.color && s.name) {
game.unselected.push(s);
}
}

View File

@ -86,6 +86,10 @@ export interface Session {
lastActive?: number;
keepAlive?: any;
connected?: boolean;
hasAudio?: boolean;
audio?: any;
video?: any;
ping?: number;
_initialSnapshotSent?: boolean;
_getBatch?: { fields: Set<string>; timer?: any };
_pendingMessage?: any;