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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

improve(webui): Handle nonce being invalidated by client logging in (#239)

5f2adb7b
Sainan <sainan@calamity.gg>
提交于

代码差异

1 个文件 +130 -97
Modified static/webui/script.js +130 -97
@@ -6,6 +6,24 @@ function doLogin() {
6 6 }
7 7
8 8 function loginFromLocalStorage() {
9 doLoginRequest(
10 data => {
11 if (single.getCurrentPath() == "/webui/") {
12 single.loadRoute("/webui/inventory");
13 }
14 $(".displayname").text(data.DisplayName);
15 window.accountId = data.id;
16 window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
17 updateInventory();
18 },
19 () => {
20 logout();
21 alert("Login failed");
22 }
23 );
24 }
25
26 function doLoginRequest(succ_cb, fail_cb) {
9 27 const req = $.post({
10 28 url: "/api/login.php",
11 29 contentType: "text/plain",
@@ -20,19 +38,22 @@ function loginFromLocalStorage() {
20 38 PS: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==" // anti-cheat data
21 39 })
22 40 });
23 req.done(data => {
24 if (single.getCurrentPath() == "/webui/") {
25 single.loadRoute("/webui/inventory");
41 req.done(succ_cb);
42 req.fail(fail_cb);
43 }
44
45 function revalidateAuthz(succ_cb) {
46 return doLoginRequest(
47 data => {
48 window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
49 succ_cb();
50 },
51 () => {
52 logout();
53 alert("Your credentials are no longer valid.");
54 single.loadRoute("/webui/"); // Show login screen
26 55 }
27 $(".displayname").text(data.DisplayName);
28 window.accountId = data.id;
29 window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
30 updateInventory();
31 });
32 req.fail(() => {
33 logout();
34 alert("Login failed");
35 });
56 );
36 57 }
37 58
38 59 function logout() {
@@ -176,18 +197,20 @@ function doAcquireWarframe() {
176 197 $("#warframe-to-acquire").addClass("is-invalid").focus();
177 198 return;
178 199 }
179 const req = $.post({
180 url: "/custom/addItem",
181 contentType: "application/json",
182 data: JSON.stringify({
183 type: "Powersuit",
184 internalName: uniqueName,
185 accountId: window.accountId
186 })
187 });
188 req.done(() => {
189 document.getElementById("warframe-to-acquire").value = "";
190 updateInventory();
200 revalidateAuthz(() => {
201 const req = $.post({
202 url: "/custom/addItem",
203 contentType: "application/json",
204 data: JSON.stringify({
205 type: "Powersuit",
206 internalName: uniqueName,
207 accountId: window.accountId
208 })
209 });
210 req.done(() => {
211 document.getElementById("warframe-to-acquire").value = "";
212 updateInventory();
213 });
191 214 });
192 215 }
193 216
@@ -201,18 +224,20 @@ function doAcquireWeapon() {
201 224 $("#weapon-to-acquire").addClass("is-invalid").focus();
202 225 return;
203 226 }
204 const req = $.post({
205 url: "/custom/addItem",
206 contentType: "application/json",
207 data: JSON.stringify({
208 type: "Weapon",
209 internalName: uniqueName,
210 accountId: window.accountId
211 })
212 });
213 req.done(() => {
214 document.getElementById("weapon-to-acquire").value = "";
215 updateInventory();
227 revalidateAuthz(() => {
228 const req = $.post({
229 url: "/custom/addItem",
230 contentType: "application/json",
231 data: JSON.stringify({
232 type: "Weapon",
233 internalName: uniqueName,
234 accountId: window.accountId
235 })
236 });
237 req.done(() => {
238 document.getElementById("weapon-to-acquire").value = "";
239 updateInventory();
240 });
216 241 });
217 242 }
218 243
@@ -228,12 +253,14 @@ function addGearExp(category, oid, xp) {
228 253 XP: xp
229 254 }
230 255 ];
231 $.post({
232 url: "/api/missionInventoryUpdate.php?" + window.authz,
233 contentType: "text/plain",
234 data: JSON.stringify(data)
235 }).done(function () {
236 updateInventory();
256 revalidateAuthz(() => {
257 $.post({
258 url: "/api/missionInventoryUpdate.php?" + window.authz,
259 contentType: "text/plain",
260 data: JSON.stringify(data)
261 }).done(function () {
262 updateInventory();
263 });
237 264 });
238 265 }
239 266
@@ -248,12 +275,14 @@ function disposeOfGear(category, oid) {
248 275 String: oid
249 276 }
250 277 ];
251 $.post({
252 url: "/api/sell.php?" + window.authz,
253 contentType: "text/plain",
254 data: JSON.stringify(data)
255 }).done(function () {
256 updateInventory();
278 revalidateAuthz(() => {
279 $.post({
280 url: "/api/sell.php?" + window.authz,
281 contentType: "text/plain",
282 data: JSON.stringify(data)
283 }).done(function () {
284 updateInventory();
285 });
257 286 });
258 287 }
259 288
@@ -263,19 +292,21 @@ function doAcquireMiscItems() {
263 292 $("#miscitem-type").addClass("is-invalid").focus();
264 293 return;
265 294 }
266 $.post({
267 url: "/api/missionInventoryUpdate.php?" + window.authz,
268 contentType: "text/plain",
269 data: JSON.stringify({
270 MiscItems: [
271 {
272 ItemType: uniqueName,
273 ItemCount: $("#miscitem-count").val()
274 }
275 ]
276 })
277 }).done(function () {
278 alert("Successfully added.");
295 revalidateAuthz(() => {
296 $.post({
297 url: "/api/missionInventoryUpdate.php?" + window.authz,
298 contentType: "text/plain",
299 data: JSON.stringify({
300 MiscItems: [
301 {
302 ItemType: uniqueName,
303 ItemCount: $("#miscitem-count").val()
304 }
305 ]
306 })
307 }).done(function () {
308 alert("Successfully added.");
309 });
279 310 });
280 311 }
281 312
@@ -301,43 +332,45 @@ function doAcquireRiven() {
301 332 return;
302 333 }
303 334 const uniqueName = "/Lotus/Upgrades/Mods/Randomized/" + $("#addriven-type").val();
304 // Add riven type to inventory
305 $.post({
306 url: "/api/missionInventoryUpdate.php?" + window.authz,
307 contentType: "text/plain",
308 data: JSON.stringify({
309 RawUpgrades: [
310 {
311 ItemType: uniqueName,
312 ItemCount: 1
313 }
314 ]
315 })
316 }).done(function () {
317 // Get riven's assigned id
318 $.get("/api/inventory.php?" + window.authz).done(data => {
319 for (const rawUpgrade of data.RawUpgrades) {
320 if (rawUpgrade.ItemType === uniqueName) {
321 // Add fingerprint to riven
322 $.post({
323 url: "/api/artifacts.php?" + window.authz,
324 contentType: "text/plain",
325 data: JSON.stringify({
326 Upgrade: {
327 ItemType: uniqueName,
328 UpgradeFingerprint: JSON.stringify(fingerprint),
329 ItemId: rawUpgrade.LastAdded
330 },
331 LevelDiff: 0,
332 Cost: 0,
333 FusionPointCost: 0
334 })
335 }).done(function () {
336 alert("Successfully added.");
337 });
338 break;
335 revalidateAuthz(() => {
336 // Add riven type to inventory
337 $.post({
338 url: "/api/missionInventoryUpdate.php?" + window.authz,
339 contentType: "text/plain",
340 data: JSON.stringify({
341 RawUpgrades: [
342 {
343 ItemType: uniqueName,
344 ItemCount: 1
345 }
346 ]
347 })
348 }).done(function () {
349 // Get riven's assigned id
350 $.get("/api/inventory.php?" + window.authz).done(data => {
351 for (const rawUpgrade of data.RawUpgrades) {
352 if (rawUpgrade.ItemType === uniqueName) {
353 // Add fingerprint to riven
354 $.post({
355 url: "/api/artifacts.php?" + window.authz,
356 contentType: "text/plain",
357 data: JSON.stringify({
358 Upgrade: {
359 ItemType: uniqueName,
360 UpgradeFingerprint: JSON.stringify(fingerprint),
361 ItemId: rawUpgrade.LastAdded
362 },
363 LevelDiff: 0,
364 Cost: 0,
365 FusionPointCost: 0
366 })
367 }).done(function () {
368 alert("Successfully added.");
369 });
370 break;
371 }
339 372 }
340 }
373 });
341 374 });
342 375 });
343 376 }