Fixing "as any" usages
This commit is contained in:
parent
2dae5b7b17
commit
570d9024ab
@ -725,9 +725,9 @@ const getSession = (game: Game, id: string): Session => {
|
||||
return game.sessions[id]!;
|
||||
};
|
||||
|
||||
const loadGame = async (id: string) => {
|
||||
const loadGame = async (id: string): Promise<Game> => {
|
||||
if (/^\.|\//.exec(id)) {
|
||||
return undefined;
|
||||
throw Error("Invalid game ID");
|
||||
}
|
||||
|
||||
if (id in games) {
|
||||
@ -4376,7 +4376,7 @@ router.ws("/ws/:id", async (ws, req) => {
|
||||
if (game.state === "winner") {
|
||||
let dead = true;
|
||||
for (let id in game.sessions) {
|
||||
if (game.sessions[id].live && game.sessions[id].name) {
|
||||
if (game.sessions[id]!.live && game.sessions[id]!.name) {
|
||||
dead = false;
|
||||
}
|
||||
}
|
||||
@ -4387,11 +4387,11 @@ router.ws("/ws/:id", async (ws, req) => {
|
||||
chat: game.chat,
|
||||
});
|
||||
for (let id in game.sessions) {
|
||||
if (game.sessions[id].ws) {
|
||||
if (game.sessions[id]!.ws) {
|
||||
try {
|
||||
console.log(`${short}: Removing game - closing session ${id} socket (game removal cleanup)`);
|
||||
console.log(`${short}: Closing socket stack:`, new Error().stack);
|
||||
game.sessions[id].ws.close();
|
||||
game.sessions[id]!.ws.close();
|
||||
} catch (e) {
|
||||
console.warn(`${short}: error closing session socket during game removal:`, e);
|
||||
}
|
||||
@ -4643,8 +4643,6 @@ router.ws("/ws/:id", async (ws, req) => {
|
||||
case "robber":
|
||||
case "robberName":
|
||||
case "pips":
|
||||
case "pipsOrder":
|
||||
case "borders":
|
||||
case "tileOrder":
|
||||
case "active":
|
||||
case "largestArmy":
|
||||
@ -4685,12 +4683,15 @@ router.ws("/ws/:id", async (ws, req) => {
|
||||
batchedUpdate.timestamp = Date.now();
|
||||
break;
|
||||
default:
|
||||
if (field in game) {
|
||||
function hasKey<T>(obj: T, key: PropertyKey): key is keyof T {
|
||||
return key in (obj as unknown as Record<string, unknown>);
|
||||
}
|
||||
if (hasKey(game, field)) {
|
||||
console.warn(`${short}: WARNING: Requested GET not-privatized/sanitized field: ${field}`);
|
||||
batchedUpdate[String(field)] = (game as any)[String(field)];
|
||||
} else if (field in session) {
|
||||
batchedUpdate[field] = game[field];
|
||||
} else if (hasKey(session, field)) {
|
||||
console.warn(`${short}: WARNING: Requested GET not-sanitized session field: ${field}`);
|
||||
batchedUpdate[String(field)] = (session as any)[String(field)];
|
||||
batchedUpdate[field as keyof typeof game] = session[field];
|
||||
} else {
|
||||
console.warn(`${short}: WARNING: Requested GET unsupported field: ${field}`);
|
||||
}
|
||||
@ -4866,9 +4867,9 @@ router.ws("/ws/:id", async (ws, req) => {
|
||||
} else {
|
||||
for (let key in game.sessions) {
|
||||
const tmp = game.sessions[key];
|
||||
if (tmp.player) {
|
||||
if (tmp!.player) {
|
||||
sendUpdateToPlayer(game, tmp, {
|
||||
private: tmp.player,
|
||||
private: tmp!.player,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,7 @@ export interface Game {
|
||||
animationSeeds?: number[];
|
||||
startTime?: number;
|
||||
direction?: "forward" | "backward";
|
||||
winner?: string | false;
|
||||
}
|
||||
|
||||
export type IncomingMessage = { type: string | null; data: any };
|
||||
|
Loading…
x
Reference in New Issue
Block a user