feat: leveling up intrinsics #725

Merged
Sainan merged 2 commits from playerskills into main 2025-01-05 20:36:18 -08:00
4 changed files with 46 additions and 15 deletions

View File

@ -0,0 +1,31 @@
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
import { getJSONfromString } from "@/src/helpers/stringHelpers";
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
import { getInventory } from "@/src/services/inventoryService";
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
import { getAccountIdForRequest } from "@/src/services/loginService";
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
import { IPlayerSkills } from "@/src/types/inventoryTypes/inventoryTypes";
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
import { RequestHandler } from "express";
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
export const playerSkillsController: RequestHandler = async (req, res) => {
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
const accountId = await getAccountIdForRequest(req);
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
const inventory = await getInventory(accountId);
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
const request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Gracefully handle malformed JSON requests.

Calling getJSONfromString directly on req.body might throw runtime errors if the request body is malformed or non-JSON. Consider guarding against null or invalid input, returning an error response if parsing fails or if required fields are missing.

- const request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest;
+ let request: IPlayerSkillsRequest;
+ try {
+   request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest;
+ } catch (err) {
+   return res.status(400).json({ error: "Invalid JSON format." });
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    let request: IPlayerSkillsRequest;
    try {
      request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest;
    } catch (err) {
      return res.status(400).json({ error: "Invalid JSON format." });
    }
_:warning: Potential issue_ **Gracefully handle malformed JSON requests.** Calling `getJSONfromString` directly on `req.body` might throw runtime errors if the request body is malformed or non-JSON. Consider guarding against `null` or invalid input, returning an error response if parsing fails or if required fields are missing. ```diff - const request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest; + let request: IPlayerSkillsRequest; + try { + request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest; + } catch (err) { + return res.status(400).json({ error: "Invalid JSON format." }); + } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion let request: IPlayerSkillsRequest; try { request = getJSONfromString(String(req.body)) as IPlayerSkillsRequest; } catch (err) { return res.status(400).json({ error: "Invalid JSON format." }); } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
const cost = (request.Pool == "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 14:37:50 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Add bounds checking for drifterCosts array access.

When accessing drifterCosts[oldRank], there's no validation to ensure oldRank is within array bounds (0-9). This could lead to undefined behavior if the rank exceeds the maximum level.

-    const cost = (request.Pool == "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000;
+    if (request.Pool === "LPP_DRIFTER" && (oldRank < 0 || oldRank >= drifterCosts.length)) {
+        return res.status(400).json({ error: `Invalid rank ${oldRank}. Maximum rank is ${drifterCosts.length - 1}` });
+    }
+    const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    if (request.Pool === "LPP_DRIFTER" && (oldRank < 0 || oldRank >= drifterCosts.length)) {
        return res.status(400).json({ error: `Invalid rank ${oldRank}. Maximum rank is ${drifterCosts.length - 1}` });
    }
    const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
    const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000;
_:warning: Potential issue_ **Add bounds checking for drifterCosts array access.** When accessing `drifterCosts[oldRank]`, there's no validation to ensure `oldRank` is within array bounds (0-9). This could lead to undefined behavior if the rank exceeds the maximum level. ```diff - const cost = (request.Pool == "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000; + if (request.Pool === "LPP_DRIFTER" && (oldRank < 0 || oldRank >= drifterCosts.length)) { + return res.status(400).json({ error: `Invalid rank ${oldRank}. Maximum rank is ${drifterCosts.length - 1}` }); + } + const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion if (request.Pool === "LPP_DRIFTER" && (oldRank < 0 || oldRank >= drifterCosts.length)) { return res.status(400).json({ error: `Invalid rank ${oldRank}. Maximum rank is ${drifterCosts.length - 1}` }); } const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 14:37:50 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Prevent negative costs and add maximum rank validation.

The current implementation lacks validation for:

  1. Maximum rank for non-Drifter skills (Railjack goes up to rank 9)
  2. Negative costs that could occur from integer overflow
-    const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000;
-    inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
-    inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+    // Maximum rank for non-Drifter skills
+    if (request.Pool !== "LPP_DRIFTER" && oldRank >= 9) {
+        return res.status(400).json({ error: "Maximum rank reached" });
+    }
+    
+    const baseCost = request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank;
+    const cost = baseCost * 1000;
+    
+    // Prevent integer overflow leading to negative costs
+    if (cost <= 0) {
+        return res.status(400).json({ error: "Invalid cost calculation" });
+    }
+    
+    const poolKey = request.Pool as keyof IPlayerSkills;
+    const skillKey = request.Skill as keyof IPlayerSkills;
+    
+    inventory.PlayerSkills[poolKey] -= cost;
+    inventory.PlayerSkills[skillKey]++;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    // Maximum rank for non-Drifter skills
    if (request.Pool !== "LPP_DRIFTER" && oldRank >= 9) {
        return res.status(400).json({ error: "Maximum rank reached" });
    }
    
    const baseCost = request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank;
    const cost = baseCost * 1000;
    
    // Prevent integer overflow leading to negative costs
    if (cost <= 0) {
        return res.status(400).json({ error: "Invalid cost calculation" });
    }
    
    const poolKey = request.Pool as keyof IPlayerSkills;
    const skillKey = request.Skill as keyof IPlayerSkills;
    
    inventory.PlayerSkills[poolKey] -= cost;
    inventory.PlayerSkills[skillKey]++;
_:warning: Potential issue_ **Prevent negative costs and add maximum rank validation.** The current implementation lacks validation for: 1. Maximum rank for non-Drifter skills (Railjack goes up to rank 9) 2. Negative costs that could occur from integer overflow ```diff - const cost = (request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // Maximum rank for non-Drifter skills + if (request.Pool !== "LPP_DRIFTER" && oldRank >= 9) { + return res.status(400).json({ error: "Maximum rank reached" }); + } + + const baseCost = request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank; + const cost = baseCost * 1000; + + // Prevent integer overflow leading to negative costs + if (cost <= 0) { + return res.status(400).json({ error: "Invalid cost calculation" }); + } + + const poolKey = request.Pool as keyof IPlayerSkills; + const skillKey = request.Skill as keyof IPlayerSkills; + + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion // Maximum rank for non-Drifter skills if (request.Pool !== "LPP_DRIFTER" && oldRank >= 9) { return res.status(400).json({ error: "Maximum rank reached" }); } const baseCost = request.Pool === "LPP_DRIFTER" ? drifterCosts[oldRank] : 1 << oldRank; const cost = baseCost * 1000; // Prevent integer overflow leading to negative costs if (cost <= 0) { return res.status(400).json({ error: "Invalid cost calculation" }); } const poolKey = request.Pool as keyof IPlayerSkills; const skillKey = request.Skill as keyof IPlayerSkills; inventory.PlayerSkills[poolKey] -= cost; inventory.PlayerSkills[skillKey]++; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
await inventory.save();
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
res.json({
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Pool: request.Pool,
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
PoolInc: -cost,
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Skill: request.Skill,
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Rank: oldRank + 1
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
});
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
};
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
interface IPlayerSkillsRequest {
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Pool: string;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Skill: string;
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
}
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
const drifterCosts = [20, 25, 30, 45, 65, 90, 125, 160, 205, 255];
coderabbitai[bot] commented 2025-01-05 04:21:25 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Check sufficient pool balance and skill validity.

  1. There's no validation to confirm the chosen pool (e.g., RegularCredits vs. FusionPoints) has enough funds to cover the cost. If cost exceeds the balance, this logic would set the pool to a negative value.
  2. Also ensure that request.Skill is valid and actually exists in inventory.PlayerSkills, to avoid writing to an undefined key or misusing the cast as keyof IPlayerSkills.
 const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills];
 const cost = (1 << oldRank) * 1000;
- inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost;
- inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++;
+ // 1) Validate pool balance
+ const poolKey = request.Pool as keyof IPlayerSkills;
+ if (inventory.PlayerSkills[poolKey] < cost) {
+   return res.status(400).json({ error: "Insufficient balance in pool" });
+ }
+ // 2) Validate skill
+ const skillKey = request.Skill as keyof IPlayerSkills;
+ if (typeof inventory.PlayerSkills[skillKey] !== "number") {
+   return res.status(400).json({ error: "Invalid skill name" });
+ }
+ 
+ // Safe to update
+ inventory.PlayerSkills[poolKey] -= cost;
+ inventory.PlayerSkills[skillKey]++;

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Check sufficient pool balance and skill validity.** 1) There's no validation to confirm the chosen pool (e.g., `RegularCredits` vs. `FusionPoints`) has enough funds to cover the `cost`. If `cost` exceeds the balance, this logic would set the pool to a negative value. 2) Also ensure that `request.Skill` is valid and actually exists in `inventory.PlayerSkills`, to avoid writing to an undefined key or misusing the cast `as keyof IPlayerSkills`. ```diff const oldRank: number = inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]; const cost = (1 << oldRank) * 1000; - inventory.PlayerSkills[request.Pool as keyof IPlayerSkills] -= cost; - inventory.PlayerSkills[request.Skill as keyof IPlayerSkills]++; + // 1) Validate pool balance + const poolKey = request.Pool as keyof IPlayerSkills; + if (inventory.PlayerSkills[poolKey] < cost) { + return res.status(400).json({ error: "Insufficient balance in pool" }); + } + // 2) Validate skill + const skillKey = request.Skill as keyof IPlayerSkills; + if (typeof inventory.PlayerSkills[skillKey] !== "number") { + return res.status(400).json({ error: "Invalid skill name" }); + } + + // Safe to update + inventory.PlayerSkills[poolKey] -= cost; + inventory.PlayerSkills[skillKey]++; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->

View File

@ -438,18 +438,17 @@ const seasonChallengeHistorySchema = new Schema<ISeasonChallenge>(
//TODO: check whether this is complete
const playerSkillsSchema = new Schema<IPlayerSkills>(
{
LPP_SPACE: Number,
LPP_DRIFTER: Number,
LPS_NONE: Number,
LPS_PILOTING: Number,
LPS_GUNNERY: Number,
LPS_TACTICAL: Number,
LPS_ENGINEERING: Number,
LPS_COMMAND: Number,
LPS_DRIFT_COMBAT: Number,
LPS_DRIFT_RIDING: Number,
LPS_DRIFT_OPPORTUNITY: Number,
LPS_DRIFT_ENDURANCE: Number
LPP_SPACE: { type: Number, default: 0 },
LPS_PILOTING: { type: Number, default: 0 },
LPS_GUNNERY: { type: Number, default: 0 },
LPS_TACTICAL: { type: Number, default: 0 },
LPS_ENGINEERING: { type: Number, default: 0 },
LPS_COMMAND: { type: Number, default: 0 },
LPP_DRIFTER: { type: Number, default: 0 },
LPS_DRIFT_COMBAT: { type: Number, default: 0 },
LPS_DRIFT_RIDING: { type: Number, default: 0 },
LPS_DRIFT_OPPORTUNITY: { type: Number, default: 0 },
LPS_DRIFT_ENDURANCE: { type: Number, default: 0 }
},
{ _id: false }
);
@ -1003,7 +1002,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
//Modulars lvl and exp(Railjack|Duviri)
//https://warframe.fandom.com/wiki/Intrinsics
PlayerSkills: playerSkillsSchema,
PlayerSkills: { type: playerSkillsSchema, default: {} },
//TradeBannedUntil data
TradeBannedUntil: Schema.Types.Mixed,

View File

@ -44,6 +44,7 @@ import { missionInventoryUpdateController } from "@/src/controllers/api/missionI
import { modularWeaponCraftingController } from "@/src/controllers/api/modularWeaponCraftingController";
import { modularWeaponSaleController } from "@/src/controllers/api/modularWeaponSaleController";
import { nameWeaponController } from "@/src/controllers/api/nameWeaponController";
import { playerSkillsController } from "@/src/controllers/api/playerSkillsController";
import { projectionManagerController } from "../controllers/api/projectionManagerController";
import { purchaseController } from "@/src/controllers/api/purchaseController";
import { queueDojoComponentDestructionController } from "@/src/controllers/api/queueDojoComponentDestructionController";
@ -130,6 +131,7 @@ apiRouter.post("/login.php", loginController);
apiRouter.post("/missionInventoryUpdate.php", missionInventoryUpdateController);
apiRouter.post("/modularWeaponCrafting.php", modularWeaponCraftingController);
apiRouter.post("/nameWeapon.php", nameWeaponController);
apiRouter.post("/playerSkills.php", playerSkillsController);
apiRouter.post("/projectionManager.php", projectionManagerController);
apiRouter.post("/purchase.php", purchaseController);
apiRouter.post("/rerollRandomMod.php", rerollRandomModController);

View File

@ -814,13 +814,12 @@ export interface IPersonalTechProject {
export interface IPlayerSkills {
LPP_SPACE: number;
LPP_DRIFTER: number;
LPS_NONE: number;
LPS_PILOTING: number;
LPS_GUNNERY: number;
LPS_TACTICAL: number;
LPS_ENGINEERING: number;
LPS_COMMAND: number;
LPP_DRIFTER: number;
LPS_DRIFT_COMBAT: number;
LPS_DRIFT_RIDING: number;
LPS_DRIFT_OPPORTUNITY: number;