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

chore(webui): don't refresh inventory for sell on the tab that issued it (#2506)

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

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

代码差异

4 个文件 +17 -11
Modified src/controllers/api/sellController.ts +2 -2
@@ -15,7 +15,7 @@ import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
15 15 import { ExportDojoRecipes } from "warframe-public-export-plus";
16 16 import { IInventoryChanges } from "@/src/types/purchaseTypes";
17 17 import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
18 import { sendWsBroadcastTo } from "@/src/services/wsService";
18 import { sendWsBroadcastEx } from "@/src/services/wsService";
19 19
20 20 export const sellController: RequestHandler = async (req, res) => {
21 21 const payload = JSON.parse(String(req.body)) as ISellRequest;
@@ -295,7 +295,7 @@ export const sellController: RequestHandler = async (req, res) => {
295 295 res.json({
296 296 inventoryChanges: inventoryChanges // "inventoryChanges" for this response instead of the usual "InventoryChanges"
297 297 });
298 sendWsBroadcastTo(accountId, { update_inventory: true });
298 sendWsBroadcastEx({ update_inventory: true }, accountId, parseInt(String(req.query.wsid)));
299 299 };
300 300
301 301 interface ISellRequest {
Modified src/controllers/custom/configController.ts +2 -2
@@ -2,7 +2,7 @@ import { RequestHandler } from "express";
2 2 import { config, syncConfigWithDatabase } from "@/src/services/configService";
3 3 import { getAccountForRequest, isAdministrator } from "@/src/services/loginService";
4 4 import { saveConfig } from "@/src/services/configWriterService";
5 import { sendWsBroadcastExcept } from "@/src/services/wsService";
5 import { sendWsBroadcastEx } from "@/src/services/wsService";
6 6
7 7 export const getConfigController: RequestHandler = async (req, res) => {
8 8 const account = await getAccountForRequest(req);
@@ -25,7 +25,7 @@ export const setConfigController: RequestHandler = async (req, res) => {
25 25 const [obj, idx] = configIdToIndexable(id);
26 26 obj[idx] = value;
27 27 }
28 sendWsBroadcastExcept(parseInt(String(req.query.wsid)), { config_reloaded: true });
28 sendWsBroadcastEx({ config_reloaded: true }, undefined, parseInt(String(req.query.wsid)));
29 29 syncConfigWithDatabase();
30 30 await saveConfig();
31 31 res.end();
Modified src/services/wsService.ts +10 -4
@@ -43,7 +43,7 @@ export const stopWsServers = (promises: Promise<void>[]): void => {
43 43 let lastWsid: number = 0;
44 44
45 45 interface IWsCustomData extends ws {
46 id?: number;
46 id: number;
47 47 accountId?: string;
48 48 }
49 49
@@ -181,18 +181,24 @@ export const sendWsBroadcastTo = (accountId: string, data: IWsMsgToClient): void
181 181 }
182 182 };
183 183
184 export const sendWsBroadcastExcept = (wsid: number | undefined, data: IWsMsgToClient): void => {
184 export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excludeWsid?: number): void => {
185 185 const msg = JSON.stringify(data);
186 186 if (wsServer) {
187 187 for (const client of wsServer.clients) {
188 if ((client as IWsCustomData).id != wsid) {
188 if (
189 (!accountId || (client as IWsCustomData).accountId == accountId) &&
190 (client as IWsCustomData).id != excludeWsid
191 ) {
189 192 client.send(msg);
190 193 }
191 194 }
192 195 }
193 196 if (wssServer) {
194 197 for (const client of wssServer.clients) {
195 if ((client as IWsCustomData).id != wsid) {
198 if (
199 (!accountId || (client as IWsCustomData).accountId == accountId) &&
200 (client as IWsCustomData).id != excludeWsid
201 ) {
196 202 client.send(msg);
197 203 }
198 204 }
Modified static/webui/script.js +3 -3
@@ -1746,7 +1746,7 @@ function disposeOfGear(category, oid) {
1746 1746 ];
1747 1747 revalidateAuthz().then(() => {
1748 1748 $.post({
1749 url: "/api/sell.php?" + window.authz,
1749 url: "/api/sell.php?" + window.authz + "&wsid=" + wsid,
1750 1750 contentType: "text/plain",
1751 1751 data: JSON.stringify(data)
1752 1752 });
@@ -1768,7 +1768,7 @@ function disposeOfItems(category, type, count) {
1768 1768 ];
1769 1769 revalidateAuthz().then(() => {
1770 1770 $.post({
1771 url: "/api/sell.php?" + window.authz,
1771 url: "/api/sell.php?" + window.authz + "&wsid=" + wsid,
1772 1772 contentType: "text/plain",
1773 1773 data: JSON.stringify(data)
1774 1774 });
@@ -2202,7 +2202,7 @@ function doRemoveUnrankedMods() {
2202 2202 req.done(inventory => {
2203 2203 window.itemListPromise.then(itemMap => {
2204 2204 $.post({
2205 url: "/api/sell.php?" + window.authz,
2205 url: "/api/sell.php?" + window.authz + "&wsid=" + wsid,
2206 2206 contentType: "text/plain",
2207 2207 data: JSON.stringify({
2208 2208 SellCurrency: "SC_RegularCredits",