feat: support websocket connections from game client #2735
@ -62,6 +62,7 @@ interface IWsMsgFromClient {
 | 
				
			|||||||
        nonce: number;
 | 
					        nonce: number;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    logout?: boolean;
 | 
					    logout?: boolean;
 | 
				
			||||||
 | 
					    sync_inventory?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IWsMsgToClient {
 | 
					interface IWsMsgToClient {
 | 
				
			||||||
@ -168,16 +169,24 @@ const wsOnConnect = (ws: WebSocket, req: http.IncomingMessage): void => {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            if (data.logout) {
 | 
					            if (data.logout) {
 | 
				
			||||||
                const accountId = (ws as IWsCustomData).accountId;
 | 
					                const accountId = (ws as IWsCustomData).accountId;
 | 
				
			||||||
                (ws as IWsCustomData).accountId = undefined;
 | 
					                if (accountId) {
 | 
				
			||||||
                await Account.updateOne(
 | 
					                    (ws as IWsCustomData).accountId = undefined;
 | 
				
			||||||
                    {
 | 
					                    await Account.updateOne(
 | 
				
			||||||
                        _id: accountId,
 | 
					                        {
 | 
				
			||||||
                        ClientType: "webui"
 | 
					                            _id: accountId,
 | 
				
			||||||
                    },
 | 
					                            ClientType: "webui"
 | 
				
			||||||
                    {
 | 
					                        },
 | 
				
			||||||
                        Nonce: 0
 | 
					                        {
 | 
				
			||||||
                    }
 | 
					                            Nonce: 0
 | 
				
			||||||
                );
 | 
					                        }
 | 
				
			||||||
 | 
					                    );
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (data.sync_inventory) {
 | 
				
			||||||
 | 
					                const accountId = (ws as IWsCustomData).accountId;
 | 
				
			||||||
 | 
					                if (accountId) {
 | 
				
			||||||
 | 
					                    sendWsBroadcastToGame(accountId, { sync_inventory: true });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } catch (e) {
 | 
					        } catch (e) {
 | 
				
			||||||
            logError(e as Error, `processing websocket message`);
 | 
					            logError(e as Error, `processing websocket message`);
 | 
				
			||||||
 | 
				
			|||||||
@ -2993,6 +2993,9 @@ function doUnlockAllFocusSchools() {
 | 
				
			|||||||
                toast(loc("code_focusAllUnlocked"));
 | 
					                toast(loc("code_focusAllUnlocked"));
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length));
 | 
					                toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length));
 | 
				
			||||||
 | 
					                if (ws_is_open) {
 | 
				
			||||||
 | 
					                    window.ws.send(JSON.stringify({ sync_inventory: true }));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user