90 lines
8.4 KiB
Markdown
90 lines
8.4 KiB
Markdown
# PORT switchbot (自动洗练), AVA2 port
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
## Window and items
|
||
|
||
- 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.
|
||
|
||
## Rolling
|
||
|
||
- `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>`
|
||
|
||
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.
|
||
|
||
## Protocol
|
||
|
||
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`).
|
||
|
||
| 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) |
|
||
|
||
CG is registered in `packet_info.cpp` with `Set(..., true)` and GG with `Set(..., false)`. The 40250 base packets are unchanged.
|
||
|
||
**Version gate.** The client is built with `LOCALE_SERVICE_EUROPE`, so every locale sends `CG_CLIENT_VERSION2`. The new client's timestamp is `1215955205 mt20261016`. 203 is a europe locale and checks the version with `atoi`, which still reads 1215955205. Before `EnterGame` sends anything, it checks `SwitchbotHelper::IsClientSupported`, which looks for `mt<date>` in the timestamp with date >= `PORT_SWITCHBOT_CLIENT_VERSION`. An older client sends `1215955205` only and gets no GC_SWITCHBOT packet. It can't fill the window either. (The non-EU branch sends `mt20261016`.)
|
||
|
||
## Verification
|
||
|
||
- `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.
|
||
- Live-tested on 203 on 2026-10-16 with the Mac client and a script driver. Weapons ran on channel5 against the live db. Rings and talismans ran on the isolated sbtest cluster (`metin2-client/tools/server/sbtest`), which has the unlocked protos. Results:
|
||
- Move in, drag back, start/stop, auto-finish on target, refusal to move out while active, refusal of an invalid item; about 12 rolls/s, ItemLog matches the switchers consumed.
|
||
- Rings roll from the ring pool with 71084; talismans roll from the talisman pool with 71302 only.
|
||
- Relog keeps the items (from the db cache, and from MySQL after a restart). The bot stops and the targets are cleared, as in AVA2 (`UnregisterItem` on logout).
|
||
- Same-core map change (1 → 21 → 1) keeps rolling with the targets kept; it only pauses during the warp.
|
||
- Cross-core map hand-over was not tested in that initial run; see the later dual-core acceptance below.
|
||
- The initial 2026-10-16 deployment note is superseded: on 2026-10-17 the live binary was confirmed to contain CSwitchbotManager/switchbot_end and the SWITCHBOT DB window. This does not deploy the later sbtest changes or prove live cross-channel operation.
|
||
|
||
## 2026-10-18 补充验收
|
||
|
||
独立 sbtest 的 QA1017,武器起初无类型9;所有备选均只设释放速度9≥1。未手动停止,实际消耗13个71084后,最终含 (9,10),active=0、finished=1,约1.315秒。客户端证据 switchbot-cast-natural.json。跨频道换线仍未验收,不能将本项扩大解释为全部洗练场景通过。
|
||
|
||
## 双核心地图传送验收
|
||
|
||
2026-10-18:临时测试核心13040/P2P14040载入地图1/62,独立13041/P2P14041载入地图61,均为频道5、仅连接db15040。原生追踪传送1→61→62,两次跨核心日志确认;两边均 active=1、两个备选目标相同,第4条锁定属性 (4,6) 不变,71084总数2069→1811→1595。已停止洗练、退回物品并解锁。
|
||
|
||
验收后恢复 channel5/first 原CONFIG(逐字节核对),关闭辅助核心并重启sbtest,QA1017离线位置恢复主城。生产game仍为40335e41…,正式服配置未改。日志和配置备份在 /root/deploy-features/20261018-ava2-parity/crosscore;不向版本库提交CONFIG或凭据。
|
||
|
||
此项仅验证同频道跨核心地图传送。该次测试时客户端换线仍使用退出重登;后续原生跨频道验收见下节。
|
||
|
||
## 原生跨频道续洗验收
|
||
|
||
2026-10-18,sbtest临时频道5:13040和频道6:13050均仅加载地图1。按 AVA2 启用的 do_cmd→MoveChannel、MoveChannelDialog 完成5→6→5,无额外人工查询辅助,active全程为1、两套目标表相同,第4条锁定属性 (4,6) 保持,71084总数1034→976→919。往返后主动停止,武器返回背包159格并解锁,数据库锁表记录为0。
|
||
|
||
同频道、未开放频道、倒计时取消和任务选择中拒绝均通过;另测换到6后退出重登仍在6/auth11040,回5后关闭辅助核心,列表只剩5且拒绝旧目标6。详见 FEATURE-AVA2-NATIVE-CHANNEL.md。恢复两个原CONFIG并关闭辅助核心,sbtest已重启;正式服game仍40335e41…,本轮换线没有正式部署,Android真机按用户要求暂停。
|
||
|
||
2026-10-18 后续:聊天链接和活动洗练槽已补锁定快照并通过sbtest联机验证;见 `FEATURE-ATTR-LOCK-SNAPSHOTS.md`。经典七属性封包保持不变,正式服部署与Android真机验收仍待做。
|