Files
TravianZ/Templates
Ferywir dc971770e1 fix(market): harden NPC resource distribution against NaN [#211]
On some servers the NPC ("merchant") distribution screen could lock on
"Rest: NaN", hiding the trade button and making the NPC unusable. The "Rest"
value never returned to 0, so the player could not complete the trade.

Two layers of hardening:

* Client (Templates/Build/17_3.tpl):
  - add a safe npcDiv() helper (returns 0 on a 0 divisor or non-finite value)
    and route every division in portionOut() through it, so Infinity/NaN can no
    longer leak into the inputs;
  - in calculateRest(), coerce "Rest"/overall to a finite value (fall back to
    the total when org4 cannot be parsed) so the submit button can always
    reappear once the distribution is balanced;
  - coerce each resource, $totalRes, $maxstore and $maxcrop to a valid,
    non-negative integer before they reach the page/JS, so a resource computed
    as NaN/INF cannot poison org4/summe in the first place.

* Server (Market::tradeResource): clamp each requested amount to [0, maxstore]
  (crop to maxcrop) before persisting, so a forged or corrupted POST can no
  longer write out-of-range resources.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 21:38:46 +02:00
..
2026-05-07 11:20:05 +03:00
2026-05-07 11:20:05 +03:00
2026-05-07 11:20:05 +03:00
2026-05-07 11:20:05 +03:00
2026-05-07 11:20:05 +03:00
2026-05-07 11:20:05 +03:00
2026-05-08 13:06:53 +03:00