Files
metin2-server/docs/FEATURE-CHEST.md
T
shenleiandClaude Opus 5.5 a28393b16b Port the AVA2 switchbot (自动洗练) 1:1
AVA2 new_switchbot ported as port_switchbot.{h,cpp}: SWITCHBOT item window (7),
CG/GC 171 and GG 31 with AVA2 subheaders and field order, pack(1) structs pinned
by static_assert, 0.1 s roll, P2P hand-over on warp, boot ALTER of
player.item.window. Switchers come from the inventory; current checks and
ItemLog are kept. Clients sending "mt20261016" or newer as the version
timestamp get the switchbot; older clients are left alone.

The v1 /mt_switchbot chat command, its lock verb and query capability bit 64
are removed (cap mask 1023 -> 959).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 20:26:06 +09:00

6.0 KiB
Raw Blame History

PORT batch chest opening, v1

Date: 2026-10-15. AVA2-style batch opening of gift boxes (reference: AVA2 ENABLE_MULTI_CHEST, /chest_drop, CHARACTER::OpenChest). Source: src/server/game/src/port_chest.h (header-only, included from cmd_general.cpp), command mt_chest (cmd.cpp). It reuses the quiet-INFO hook (m_portQuietInfo / m_portLastInfo) (char.cpp; first added for the v1 switchbot, which no longer uses it). No packet header, no DB schema, no char.h/item.h change.

AVA2 rewrote the drop loop (GiveItemFromSpecialItemGroupNew, AutoGiveItemChest, cap 1000). That rewrite is not ported. Here every box goes through the original CHARACTER::UseItem → UseItemEx ITEM_GIFTBOX path, one box at a time, so the original checks, the special_item_group roll, gold/exp, ItemLog and consumption stay exactly as they are.

Rules

  • Only ITEM_GIFTBOX items whose special item group exists, is not empty and contains none of the give types MOB, SLOW, DRAIN_HP, POISON, MOB_GROUP. Boxes that spawn monsters or apply debuffs stay single-use (error kind). Other item types (e.g. ITEM_USE chests with quest scripts) are not batchable.
  • The chosen cell is opened first while it still holds the box vnum; after that, any other bag cell with the same vnum. Most gift boxes on 203 have no stack flag, so a batch normally spans many cells. Items being exchanged are skipped.
  • At most 200 boxes per command.
  • Before each box the character must still have 3 free bag cells (GetEmptyInventory(3)). This keeps room for any reward, so AutoGiveItem never has to drop one on the ground. The loop stops with reason full.
  • Busy: dead, stunned, warping, observer, !CanHandleItem, exchange, own shop, shop open, safebox, cube. Checked before the command and before each box.
  • A box counts as opened only when the bag count of its vnum went down by exactly one. Anything else (the original path refused it, e.g. the dragon soul qualification) stops the loop with reason rejected. The last INFO line of that refusal is forwarded once.
  • Per-box INFO lines are held back while the batch runs.
  • Throttle: one command per 500 ms per player id.

Protocol (CHAT_TYPE_COMMAND, version 1)

/mt_chest 1 open CELL COUNT          CELL = bag cell, COUNT = 1..200, digits only (at most 5)
MTCH1 got VNUM COUNT                 one line per gained vnum (box vnum excluded), at most 40 lines
MTCH1 done VNUM ASKED OPENED REASON GOLD
MTCH1 error rate|invalid|busy|item|kind|full
  • REASON: done (all asked boxes opened), empty (no box of this vnum left), full (fewer than 3 free cells), busy, rejected.
  • GOLD: gold balance change over the batch.
  • Gains are the difference between bag + dragon soul bag counts before and after the batch.
  • A request with a version other than 1, a token longer than 10 characters or more than 5 tokens is ignored silently.

There is no MTF1 capability bit (the mask stays 511). The client marks the server unsupported when no MTCH1 reply arrives within 3 s and falls back to normal single use.

Verification

  • tests/features/test_chest.py compiles the production header against stubs of the UseItem gift-box contract (consume one box, gold, stacking reward, dragon soul reward, INFO lines). It covers:
    • cross-cell order and the gains/gold summary with INFO held back;
    • a stack, fewer asked than held, more asked than held (empty);
    • the 3-free-cell stop (full, error full);
    • refusal by the original path (rejected, INFO forwarded once);
    • non-gift box, monster box, missing and empty group (kind);
    • missing/exchanging item, busy, invalid input, silently ignored version, throttle.
    • It also checks the cmd.cpp / cmd_general.cpp wiring.
  • All tests/features/test_*.py pass.
  • FreeBSD build of the game target in /root/metin2-features-dev (log chest-build.log, binary sha256 412977c7d7fda073493533d5bee43812a8f48dcb63399f747db6180d24803853). The live /usr/metin2 binary was not replaced and no live service was restarted.
  • Live test on 2026-10-15 against the channel-5 test core (port 13040, isolated binary) with the macOS native client as [SA]Admin, boxes created with /item:
    • 50037 (stacking, 30 held), 10 asked → done 50037 10 10 done 0, 6 gained vnums matching the bag difference exactly;
    • 50070 (not stacking, 4 boxes in 4 cells), all → done 50070 4 4 done 100000, gold balance +100000;
    • 71036 (group spawns a monster) → error kind, nothing consumed; an immediate second command → error rate;
    • remaining 20 of 50037 → done 50037 20 20 done 0, 11 gained vnums;
    • plain right click without Ctrl still uses one box the original way.
    • log.log only has the original path's rows (SYSTEM, TREASURE_EXP, TREASURE_GOLD). syserr shows only the pre-existing new_quest_lv52 LUA_ERROR.

Production deployment

  • Deployed 2026-10-15 16:43 with the user's approval, 0 players online. Server main bc32475, game sha256 412977c7… (the channel-5 tested binary), db unchanged. Package /root/deploy-features/20261015-chest, backup /root/backup-bin/20261015-164314, rollback sh /root/deploy-features/20261015-chest/deploy.sh rollback. /usr/metin2/src was synced (cmd.cpp, cmd_general.cpp, port_chest.h).
  • On the first start the db core exited at boot (QueryLocaleSet: ... errno 2013 Lost connection to MySQL server during query, db.core kept as db.core.164339 in the package). MySQL itself had not restarted and the db binary is unchanged. A clean stop of every core and a db-first start (db, auth, CH1–CH4, game99, then channel5) came up normally: 14 game, 1 db, 1 auth, port 15000 listening. If this repeats, check ps for ./db after every deploy, not only the game count.
  • CH1 (13000) acceptance with the channel-5 scenario: 50037 ×10 → done 50037 10 10 done 0 (8 vnums, equal to the bag difference); 50070 ×4 in 4 cells → done 50070 4 4 done 100000; 71036 → error kind, then error rate; remaining 20 → done 50037 20 20 done 0; plain use unchanged. syserr only has the pre-existing new_quest_lv52 LUA_ERROR.