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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c6813cd653
commit
a28393b16b
+48
-78
@@ -1,93 +1,63 @@
|
||||
# PORT switchbot (automatic attribute change), v1
|
||||
# PORT switchbot (自动洗练), AVA2 port
|
||||
|
||||
AVA2-style automatic rerolling (reference: AVA2 `new_switchbot.cpp` / `uiswitchbot.py`), rebuilt so that the server stays authoritative and the existing reroll path is unchanged. Source: `src/server/game/src/port_switchbot.h`, command `mt_switchbot` (cmd.cpp), quiet-INFO hook in `CHARACTER::ChatPacket` (char.cpp), fields in char.h. No attribute lock, no DB schema, no packet header, no P2P transfer.
|
||||
AVA2 `ENABLE_SWITCHBOT` ported 1:1 (reference: AVA2 `game/src/new_switchbot.{h,cpp}`, client `PythonSwitchbot.cpp` and `root/uiswitchbot.py`). Classes, API, packets, the window and the 0.1 s roll speed are AVA2's. It replaces the v1 `/mt_switchbot` chat protocol (`MTSB1`, query capability bit 64). That command and its lock verb are gone.
|
||||
|
||||
## Rules
|
||||
Source:
|
||||
- `src/server/game/src/port_switchbot.{h,cpp}`: `SwitchbotHelper`, `CSwitchbot`, `CSwitchbotManager`, `PortSwitchbotBoot`.
|
||||
- `common/length.h`: `SWITCHBOT = 7` in `EWindows` (GROUND is now 8), `SWITCHBOT_SLOT_COUNT 6 / _REAL 5 / ALTERNATIVE_COUNT 2 / NORM_ATTR_NUM 5`, `TItemPos::IsSwitchbotPosition`.
|
||||
- `common/tables.h`: the switchbot tables.
|
||||
|
||||
- Each roll calls the original `CHARACTER::UseItem(scroll cell, target cell)`. All checks, probabilities, the addon handling, `ItemLog CHANGE_ATTRIBUTE` and scroll consumption are the manual path's. That includes the 71151/76023 restriction (weapon/body, level limit <= 40) and the GM quest flag. A roll counts only when exactly one scroll of the chosen vnum was consumed. Otherwise the bot stops with `rejected` and resends the original INFO line once.
|
||||
- The per-roll INFO lines (`属性已变更`) are held back while the bot calls UseItem (`m_portQuietInfo`); all other chat types pass through.
|
||||
- Only `ITEM_USE / USE_CHANGE_ATTRIBUTE` scrolls are accepted. `USE_CHANGE_ATTRIBUTE2` has no handler in this server's UseItemEx.
|
||||
- Target item: inventory cell, not costume, attribute set != -1, at least one attribute, not equipped or in an exchange. It is bound by item ID.
|
||||
- One bot per character. One roll every 250 ms (`PASSES_PER_SEC(1)/4`). Limit 1..1000 rolls.
|
||||
- Targets: up to 2 alternatives, each 1..5 distinct (apply, minimum). An alternative matches when every target is found among the 5 normal attribute slots with value >= minimum. Any matching alternative stops the bot (AVA2 CheckItem semantics). The bot also checks before it starts, so an item that already matches consumes nothing.
|
||||
- Allowed targets are the applies the attribute table can roll for this item's set, excluding the item's base proto applies. The maximum is `lValues[min(maxLevelBySet,5)-1]`. Items with an addon type also allow skill damage 30 / normal hit 65, the item_addon bounds.
|
||||
- Every tick re-checks the state and stops with a reason. This replaces AVA2's hooks into every move/trade path.
|
||||
- Character gone, VID changed (logout or warp) or descriptor lost: the bot is erased silently.
|
||||
- `busy`: dead, warping, `!CanHandleItem()`, exchange, own shop, shop, safebox or cube open.
|
||||
- `item_gone`: the item is missing, has another owner, has left the inventory window or is equipped.
|
||||
- `no_scroll`, `limit`, `matched`, `rejected`, `stopped`.
|
||||
- No offline rolling. Rolls stop when the player leaves, and every completed roll has already been saved and logged by the original path.
|
||||
## Window and items
|
||||
|
||||
## Protocol (CHAT_TYPE_COMMAND, version 1)
|
||||
- Items placed in the `SWITCHBOT` window (cells 0..4) are kept in `m_pointsInstant.pSwitchbotItems` and saved with `window = 'SWITCHBOT'`. The db loads, saves and deletes that window with SAFEBOX and DRAGON_SOUL_INVENTORY (three queries in `ClientManagerPlayer.cpp`).
|
||||
- At boot (game cores only), `PortSwitchbotBoot` adds `'SWITCHBOT'` to the `player.item.window` enum if it is missing. The deploy SQL carries the same ALTER.
|
||||
- `MoveItem` only accepts `SwitchbotHelper::IsValidItem` items into the window. That is AVA2's list: weapons, rings, and armour (body, head, shield, wrist, shoes, necklace, earrings, talisman). Cell 5 is rejected. The move hooks send:
|
||||
- `switchbot_error active` when the item is moved out of a running slot;
|
||||
- `switchbot_error invalid` when the item is not valid for the switchbot.
|
||||
- Drop, give, exchange and safebox refuse switchbot cells: the item has to go back to the inventory first. Shops sell only from the inventory.
|
||||
|
||||
Requests (250 ms per-character throttle; tokens <= 10 chars, <= 30 tokens):
|
||||
## Rolling
|
||||
|
||||
```
|
||||
/mt_switchbot 1 attrs CELL
|
||||
/mt_switchbot 1 start CELL SCROLL_VNUM LIMIT N1 (APPLY MIN)*N1 [N2 (APPLY MIN)*N2]
|
||||
/mt_switchbot 1 stop
|
||||
/mt_switchbot 1 status
|
||||
/mt_switchbot 1 lock CELL SLOT (attribute lock, see FEATURE-ATTR-LOCK.md)
|
||||
```
|
||||
- `CSwitchbot::SwitchItems` runs every 0.1 s (`c_fSpeed`). Each active slot takes one switcher per pass.
|
||||
- A slot finishes when one configured alternative fully matches within the first 5 attributes (AVA2 `CheckItem`). An alternative that isn't configured counts as a match.
|
||||
- Deviations from AVA2 (also listed at the top of `port_switchbot.cpp`):
|
||||
- Cell 5 (AVA2's hidden switcher cell) is never used. Switchers come from the inventory, skipping stacks that are being exchanged, locked or sold in the player's shop.
|
||||
- Which switcher is used follows the manual path:
|
||||
- a talisman takes only 71302;
|
||||
- a weapon or body armour with no level limit above 40 takes 71151 / 76023 first;
|
||||
- everything else takes 71084, then 39028.
|
||||
- A slot whose item has no attributes stops instead of rolling.
|
||||
- Every roll is written to ItemLog as `SWITCHBOT`, with the item id as the hint.
|
||||
- End and stop messages are server commands, which the client turns into localized text:
|
||||
- `switchbot_end <slot>`
|
||||
- `switchbot_stop noattr <slot>`
|
||||
- `switchbot_stop nochanger <slot>`
|
||||
|
||||
Replies:
|
||||
The slot is 0-based. AVA2 sent the locale ids `864` / `865` with slot+1.
|
||||
- Leaving the core deletes the table once it has been sent on. A logout that unregisters the last active slot also stops the event.
|
||||
- The attribute list has two pseudo sets after `ATTRIBUTE_SET_MAX_NUM`: 8 = rings (`port_rings.cpp`) and 9 = talismans (`port_pendant.cpp`).
|
||||
- Warp: `CHARACTER::WarpSet` sends the table over P2P (`HEADER_GG_SWITCHBOT 31`, `TPacketGGSwitchbot`) before `GC_WARP`. The target core keeps it, and `EnterGame` re-registers the slots whose item is still there and restarts the event.
|
||||
|
||||
```
|
||||
MTSB1 attrs CELL VNUM COUNT
|
||||
MTSB1 attr INDEX APPLY MAX (COUNT rows, INDEX 0..COUNT-1)
|
||||
MTSB1 attrs_end CELL COUNT
|
||||
MTSB1 state ACTIVE CELL VNUM ROLLS LIMIT SCROLL SCROLLS REASON
|
||||
MTSB1 lock CELL VNUM MASK (after every attrs_end, and as the reply to lock)
|
||||
MTSB1 error VERB CODE
|
||||
```
|
||||
## Protocol
|
||||
|
||||
`REASON` is one of `running matched limit no_scroll item_gone rejected busy stopped idle`. Error codes:
|
||||
Header numbers, subheaders and field order are AVA2's. The structs are `pack(1)`, and their sizes are pinned with `static_assert` in `port_switchbot.cpp` and in the client (`Packet.h`, `PythonSwitchbot.h`).
|
||||
|
||||
| Code | Meaning |
|
||||
| --- | --- |
|
||||
| `rate` | throttled |
|
||||
| `invalid` | malformed |
|
||||
| `item` | no item in that cell |
|
||||
| `equipped` | equipped or in an exchange |
|
||||
| `no_attr` | the item cannot be rerolled |
|
||||
| `scroll` | the scroll is missing or the wrong type |
|
||||
| `target` | the apply is not allowed, above the maximum or a duplicate |
|
||||
| `running` | this character already has a bot |
|
||||
| `busy` | see the busy states above |
|
||||
| Packet | Header | Layout |
|
||||
| --- | --- | --- |
|
||||
| CG | 171, dynamic | `BYTE header, int size, BYTE subheader, BYTE slot` (7) + `START`: `TSwitchbotAttributeAlternativeTable[2]` (15 each) / `STOP` |
|
||||
| GC | 171, dynamic | same 7-byte head + `UPDATE`: `TSwitchbotTable` (220) / `UPDATE_ITEM`: `TSwitchbotUpdateItem` (40: slot, vnum, count, 3 sockets, 7 attributes) / `SEND_ATTRIBUTE_INFORMATION`: `TSwitchbottAttributeTable[n]` (9) |
|
||||
| GG | 31 | `TPacketGGSwitchbot` (223) |
|
||||
|
||||
A state line is pushed after every roll and when the bot stops. When the reason is `item_gone`, CELL and VNUM are 0.
|
||||
CG is registered in `packet_info.cpp` with `Set(..., true)` and GG with `Set(..., false)`. The 40250 base packets are unchanged.
|
||||
|
||||
Capability: the MTF1 cap mask advertises bit 64 (63 -> 127). Clients that don't know it ignore it, and the client also times out to "unsupported" against old servers.
|
||||
**Version gate.** The new client sends `mt20261016` as the `CG_CLIENT_VERSION` timestamp, in place of `__TIMESTAMP__`. Before `EnterGame` sends anything, it checks `SwitchbotHelper::IsClientSupported`, which requires `mt<date>` with date >= `PORT_SWITCHBOT_CLIENT_VERSION`. An older client gets no GC_SWITCHBOT packet. It can't fill the window either. The EU-branch client timestamp (`1215955205`) doesn't pass the gate.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/features/test_switchbot.py` compiles the production header against stubs of the UseItem/ChatPacket contract. It covers the allowed list (proto exclusion, set filter, level cap, addon), validation, two alternatives, the already-matched start, quiet INFO, limit, `no_scroll`, `rejected` (INFO resent once), `item_gone`, `busy`, stop/status/idle and silent erase on a VID change.
|
||||
- `tests/features/test_queries.py` was updated for cap mask 127.
|
||||
- FreeBSD build of the whole game target on 203 in `/root/metin2-features-dev` (BINDIR=GAMEDIR=`/root/metin2-features-dev/bin`), log `/root/metin2-features-dev/switchbot-build.log`, with no warnings from the new code. The live `/usr/metin2` binary was not replaced and no service was restarted.
|
||||
- Live test on 2026-10-15. 203 ran an extra core (`/usr/metin2/server/channel5/first`: CHANNEL 5, PORT 13040, P2P 14040, MAP_ALLOW 1 21 41) with its `game` symlinked to the isolated binary. The macOS native client (`--live-server 192.168.21.203:11000:13040`) drove [SA]Admin, sword 279, scroll 71084:
|
||||
- `attrs` returned 14 rows for the sword (18 for armor 12019), received complete.
|
||||
- limit 10 → `limit` after 10 rolls. State lines arrived about every 0.24 s (about 4 rolls/s); the scroll count fell 200 → 190.
|
||||
- Two alternatives with minimum 1 → `matched` after 18 rolls.
|
||||
- Start on an item that already matches → `matched` with 0 rolls and no scroll used.
|
||||
- Moving the item 33 → 90 mid-run → the run continued, the state line reported cell 90, and `stop` → `stopped`.
|
||||
- Client exit mid-run (8 rolls) → `log.log` stopped at the exit second. The CHANGE_ATTRIBUTE row count (72 = 10+18+12+12+12+8) stayed the same 20 s later.
|
||||
- Opening a private shop mid-run → `busy` about 1 s after the shop opened (6 rolls). The character needs a shop bundle (50200 or 71049); without one `OpenMyShop` returns before setting `m_pkMyShop`, so no shop opens and the bot correctly keeps rolling.
|
||||
- 76014 with 6 scrolls and limit 10 → `no_scroll` after 6 rolls.
|
||||
- 71151 on the level-90 sword (the original path allows limit level <= 40) → `rejected` with 0 rolls and the scroll kept.
|
||||
- Every roll wrote one `CHANGE_ATTRIBUTE` row. The core's syserr shows no new errors; the `new_quest_lv52` LUA_ERROR also appears on the live cores.
|
||||
- Live acceptance on CH1 (13000) after the deploy, sword 279 and scroll 71084:
|
||||
- two alternatives with minimum 1 → `matched` after 2 rolls;
|
||||
- three attributes at the maximum with limit 10 → `limit` after 10 rolls, scrolls 157 → 147;
|
||||
- `stop` after 1 s → `stopped` after 4 rolls.
|
||||
- Not done yet: Android device validation.
|
||||
|
||||
## Production deployment
|
||||
|
||||
- 2026-10-15 14:51, approved by the user. The 203 live cores now run main `3b7e158` (`game` sha256 `0d798ec0…`, the binary the channel-5 core was tested with). The db binary is unchanged. Live `/usr/metin2/src` was at `4577d86`, so the deploy also shipped `1a36719` (query protocol and calendar drop gates; the gates stay inert without `port_events.tsv`).
|
||||
- Package `/root/deploy-features/20261015-features` (`deploy.sh check|go|rollback`, `SHA256SUMS`). The previous `game`/`db` are in `/root/backup-bin/20261015-145122` (recorded in `LAST_BACKUP`), and the replaced `/usr/metin2/src` files are in `src-before/`. `sh deploy.sh rollback` restores both.
|
||||
- The first `go` stopped at `rebuild.sh stop_server` ("server still running" after about 38 s, cores still exiting) before any backup or copy; the second `go` succeeded. `start.sh` was answered with `1`, which starts only CH1 and game99, so CH2–CH4 were started afterwards with each `run.sh` in the `start.sh` order. The channel-5 test core was restarted too, giving the pre-deploy layout of 14 cores plus db and auth. The new syserr entries contain only the existing `new_quest_lv52` LUA_ERROR (present since 2026-09-21).
|
||||
|
||||
## Open items
|
||||
|
||||
- Attribute lock: done separately in `FEATURE-ATTR-LOCK.md` (table `mt_item_attr_lock`, applied inside `CItem::ChangeAttribute`, so every bot roll keeps the locked slots). The bot's own item cannot be locked or unlocked while it rolls.
|
||||
- In 203 `player.item_proto`, 71084, 71151, 76014, 76023 and 39028 are USE/USE_CHANGE_ATTRIBUTE (subtype 18); 71302 (the AVA2 talisman scroll) does not exist. The bot accepts any `USE_CHANGE_ATTRIBUTE` scroll and leaves item rules to the original path.
|
||||
- `tests/features/test_switchbot.py` checks:
|
||||
- the window enum, headers, subheaders, struct fields and sizes, on both the server and the client;
|
||||
- the window hooks, the P2P hand-over, the boot ALTER and the switcher choice;
|
||||
- the version gate;
|
||||
- that `/mt_switchbot` is gone.
|
||||
- Client: `metin2-client/tests/wiki/test_switchbot.py` checks that the window script is AVA2 `uiswitchbot.py` verbatim, plus its glue.
|
||||
- Not yet compiled on 203 and not deployed. The live 203 still runs v1, so the server and client must be deployed together.
|
||||
|
||||
Reference in New Issue
Block a user