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
2 changed files with 22 additions and 10 deletions
Showing only changes of commit d52cbb9ac4 - Show all commits

View File

@ -62,6 +62,7 @@ interface IWsMsgFromClient {
nonce: number;
};
logout?: boolean;
sync_inventory?: boolean;
}
interface IWsMsgToClient {
@ -168,16 +169,24 @@ const wsOnConnect = (ws: WebSocket, req: http.IncomingMessage): void => {
}
if (data.logout) {
const accountId = (ws as IWsCustomData).accountId;
(ws as IWsCustomData).accountId = undefined;
await Account.updateOne(
{
_id: accountId,
ClientType: "webui"
},
{
Nonce: 0
}
);
if (accountId) {
(ws as IWsCustomData).accountId = undefined;
await Account.updateOne(
{
_id: accountId,
ClientType: "webui"
},
{
Nonce: 0
}
);
}
}
if (data.sync_inventory) {
const accountId = (ws as IWsCustomData).accountId;
if (accountId) {
sendWsBroadcastToGame(accountId, { sync_inventory: true });
}
}
} catch (e) {
logError(e as Error, `processing websocket message`);

View File

@ -2993,6 +2993,9 @@ function doUnlockAllFocusSchools() {
toast(loc("code_focusAllUnlocked"));
} else {
toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length));
if (ws_is_open) {
window.ws.send(JSON.stringify({ sync_inventory: true }));
}
}
});
});