Commit Graph

2 Commits

Author SHA1 Message Date
DawnFire42
80946b2fd4 Unify counter clamp arithmetic into shared addClamped() helper
Rename MAX_COUNTERS_ON_CARD to MAX_COUNTER_VALUE

  Add addClamped() in trice_limits.h, which uses a 64-bit intermediate so
  the addition cannot overflow int. Both Server_Card and Server_Counter use it.

  Add optional [minValue, maxValue] bounds to Server_Counter; setCount()
  and incrementCount() both clamp. Defaults are unbounded, so existing
  callers are unaffected.
2026-06-19 12:27:05 -04:00
DawnFire42
8dca14933c
Centralize counter API with server-side bounds and no-op filtering (#6879)
* Refactor server counter API to own overflow protection and filter no-op events

  Counter modifications now clamp to int bounds server-side and return change
  status, allowing command handlers to skip network broadcasts when values
  don't actually change.

* Centralize MAX_COUNTERS_ON_CARD and enforce [0, 999] bounds on server

  - Move MAX_COUNTERS_ON_CARD to trice_limits.h
  - Server clamps values in setCounter() and incrementCounter()
  - Client uses clamped comparison to allow recovery from invalid states
  - Add tests for clamping behavior

* move incrementCount() implementation from header to cpp
2026-05-21 20:39:35 -07:00