XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

fix: handle nonce invalidation during possession (#3771)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3771 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

a0ed554c
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +6 -4
Modified src/services/wsService.ts +6 -4
@@ -200,6 +200,7 @@ const wsOnConnect = (ws: WebSocket, req: http.IncomingMessage): void => {
200 200 const account = await getAccountForQuery({ ...data.auth_game, ct: "WS" }, "WS");
201 201 const accountId = account._id.toString();
202 202 (ws as IWsCustomData).accountId = accountId;
203 (ws as IWsCustomData).realAccountId = accountId;
203 204 logger.debug(`got bootstrapper connection for ${accountId}`);
204 205 sendWsBroadcastToWebui({ have_game_ws: true }, accountId);
205 206 } catch (e) {
@@ -207,9 +208,10 @@ const wsOnConnect = (ws: WebSocket, req: http.IncomingMessage): void => {
207 208 }
208 209 }
209 210 if (data.logout) {
210 const accountId = (ws as IWsCustomData).accountId;
211 const accountId = (ws as IWsCustomData).realAccountId;
211 212 if (accountId && !(ws as IWsCustomData).isGame) {
212 213 (ws as IWsCustomData).accountId = undefined;
214 (ws as IWsCustomData).realAccountId = undefined;
213 215
214 216 const stat = await Account.updateOne(
215 217 {
@@ -335,12 +337,12 @@ export const broadcastInventoryUpdate = (req: Request): void => {
335 337
336 338 export const handleNonceInvalidation = (accountId: string): void => {
337 339 forEachWsClient(client => {
338 if (client.accountId == accountId) {
340 if (client.realAccountId == accountId) {
339 341 if (client.isGame) {
340 342 client.accountId = undefined; // prevent processing of the close event
341 343 client.close();
342 344 } else {
343 client.send(JSON.stringify({ nonce_updated: true, have_game_ws: false } satisfies IWsMsgToClient));
345 client.send(JSON.stringify({ nonce_updated: true, have_game_ws: false } satisfies IWsMsgToClientWebui));
344 346 }
345 347 }
346 348 });
@@ -349,7 +351,7 @@ export const handleNonceInvalidation = (accountId: string): void => {
349 351 export const bootNonAdminsFromWebui = (): void => {
350 352 forEachWsClient(client => {
351 353 if (client.accountId && !client.isGame) {
352 void Account.findById(client.realAccountId ?? client.accountId).then(account => {
354 void Account.findById(client.realAccountId).then(account => {
353 355 if (!account || !isAdministrator(account)) {
354 356 client.send(JSON.stringify({ logged_out: true } satisfies IWsMsgToClientWebui));
355 357 client.close();