TraderX_Tools/docs/checking.md
2026-09-06 22:47:27 +03:00

58 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# `traderx_check.py` – validate and fix an existing config
Works directly on a TraderX profile folder; independent of the build tool. Useful for
configs made with the web editor, by hand, or for a quick health check before start.
```bash
python3 traderx_check.py ~/serverprofile/TraderX # report only
python3 traderx_check.py ~/serverprofile/TraderX --decode # + decoded bitfields per product
python3 traderx_check.py ~/serverprofile/TraderX --fix # apply safe fixes (backup first)
python3 traderx_check.py ~/serverprofile/TraderX --fix --fix-settings
```
The path may be the profiles dir, the `TraderX` dir or `TraderXConfig`.
## What it reports
**Errors** (the mod will skip or misread the file):
- file names not matching `prod_<name>_NNN.json` / `cat_<name>_NNN.json`
- invalid JSON (line/column), or top-level value not an object
- wrong field types that can't be coerced; missing `className`
- `buyPrice`/`sellPrice`/`maxStock` below `-1`; `coefficient ≤ 0`
- attachments / variants / `productIds` pointing at products that don't exist
- `licensesRequired` entries that aren't a `licenseId` in `TraderXGeneralSettings.json`
- trader `categoriesId` pointing at missing categories; duplicate `npcId`
**Warnings:**
- `coefficient ≠ 1` with unlimited stock (no effect); very low coefficients
- sell > buy; both prices `-1`
- unknown mode bits in `tradeQuantity`; out-of-range `stockSettings`
- products not listed in any category (fine for attachments)
- empty categories; traders with no categories
- a `Compiled/` folder shadowing `Products/` and `Categories/`
Repeated messages are grouped (`(414x) coefficient 0.9 has no effect …`); use
`--no-group` to list them all and `--ignore TEXT` (repeatable) to mute known-acceptable ones.
## What `--fix` changes
After copying `Products/` and `Categories/` to `Backup_traderx_check_<timestamp>/`:
- renames invalid file names (sanitise, append `_001`, bump on collision) and rewrites every
reference to the old id in categories, attachments, variants and the matching
`TraderXDatabase/Stock/<id>.json`
- adds missing fields with the mod's defaults; coerces `"5"` → `5`, `25.0` → `25`; drops
unknown keys (e.g. a stray `productId` inside a legacy product file)
- removes dangling and duplicate references; converts license *names* to license *ids*
- `--fix-settings`: also rewrites renamed category ids in `traders[].categoriesId`
(writes `TraderXGeneralSettings.json.bak` first)
Never changed automatically: invalid JSON, empty class names, prices, stock, coefficients,
missing licenses. Run with the server stopped – it renames stock files.
## Exit code
`0` when no errors remain, `1` otherwise – usable in start scripts (see
`scripts/prestart-check.sh`).