feat: support websocket connections from game client #2735

Merged
Sainan merged 19 commits from client-ws into main 2025-09-10 00:00:10 -07:00
Showing only changes of commit b03096d180 - Show all commits

View File

@ -6,7 +6,7 @@ import { Account } from "../models/loginModel.ts";
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService.ts"; import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService.ts";
import type { IDatabaseAccountJson } from "../types/loginTypes.ts"; import type { IDatabaseAccountJson } from "../types/loginTypes.ts";
import type { HydratedDocument } from "mongoose"; import type { HydratedDocument } from "mongoose";
import { logError } from "../utils/logger.ts"; import { logError, logger } from "../utils/logger.ts";
let wsServer: WebSocketServer | undefined; let wsServer: WebSocketServer | undefined;
let wssServer: WebSocketServer | undefined; let wssServer: WebSocketServer | undefined;
@ -158,6 +158,7 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
}); });
if (account) { if (account) {
(ws as IWsCustomData).accountId = account.id; (ws as IWsCustomData).accountId = account.id;
logger.debug(`got bootstrapper connection for ${account.id}`);
} }
} }
} }
@ -180,6 +181,7 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
}); });
ws.on("close", () => { ws.on("close", () => {
if ((ws as IWsCustomData).isGame && (ws as IWsCustomData).accountId) { if ((ws as IWsCustomData).isGame && (ws as IWsCustomData).accountId) {
logger.debug(`lost bootstrapper connection for ${(ws as IWsCustomData).accountId}`);
void Account.updateOne( void Account.updateOne(
{ {
_id: (ws as IWsCustomData).accountId _id: (ws as IWsCustomData).accountId