From 657e49e52a53efd903e1cc658d0d71edfc135565 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 16 Oct 2026 23:03:07 +0900 Subject: [PATCH] Switchbot: sbtest isolated test cluster scripts + live test results tools/server/sbtest/{setup,restart,rollback}.sh build and manage the isolated 203 test cluster (db :15040, auth :11040, channel5 on *_sb schemas with the unlocked AVA2 protos). Docs record the channel5/sbtest switchbot results: weapon, ring, talisman, relog (cache + MySQL), same-core warp. Co-Authored-By: Claude Opus 5.5 --- docs/AVA2-PARITY-PLAN.md | 4 +- docs/AVA2-SWITCHBOT.md | 8 +++- tools/server/sbtest/README.md | 38 ++++++++++++++++++ tools/server/sbtest/restart.sh | 23 +++++++++++ tools/server/sbtest/rollback.sh | 23 +++++++++++ tools/server/sbtest/setup.sh | 70 +++++++++++++++++++++++++++++++++ 6 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 tools/server/sbtest/README.md create mode 100644 tools/server/sbtest/restart.sh create mode 100644 tools/server/sbtest/rollback.sh create mode 100644 tools/server/sbtest/setup.sh diff --git a/docs/AVA2-PARITY-PLAN.md b/docs/AVA2-PARITY-PLAN.md index 4c3f3510..69b66afd 100644 --- a/docs/AVA2-PARITY-PLAN.md +++ b/docs/AVA2-PARITY-PLAN.md @@ -29,7 +29,7 @@ AVA2 功能包头号在当前服务端基本空闲,可以直接沿用: | 系统 | AVA2 | 当前实现 | 主要差异 | |---|---|---|---| -| 自动洗练 | `uiswitchbot.py` + `switcher.py`,`PythonSwitchbot`,CG/GC 171,`new_switchbot.cpp`;独立 SWITCHBOT 窗口,5 个物品槽 + 1 个道具槽,0.1 秒/次,换线后通过 P2P 转移继续洗 | `/mt_switchbot`,物品留在背包,一次只洗 1 件,0.25 秒/次,每次调用原 `UseItem`;换线或下线即停止 | 窗口、物品存放(新增窗口类型 = 物品位置枚举和 DB)、协议、速度、换线续洗。**2026-10-16 已在 feature/ava2-unlock 按 AVA2 实现,未部署**(`docs/AVA2-SWITCHBOT.md`、服务端 `FEATURE-SWITCHBOT.md`) | +| 自动洗练 | `uiswitchbot.py` + `switcher.py`,`PythonSwitchbot`,CG/GC 171,`new_switchbot.cpp`;独立 SWITCHBOT 窗口,5 个物品槽 + 1 个道具槽,0.1 秒/次,换线后通过 P2P 转移继续洗 | `/mt_switchbot`,物品留在背包,一次只洗 1 件,0.25 秒/次,每次调用原 `UseItem`;换线或下线即停止 | 窗口、物品存放(新增窗口类型 = 物品位置枚举和 DB)、协议、速度、换线续洗。**2026-10-16 已在 feature/ava2-unlock 按 AVA2 实现,联机测试通过(武器、戒指、护符、重新登录、同核心换地图;跨核心换线未测),未部署**(`docs/AVA2-SWITCHBOT.md`、服务端 `FEATURE-SWITCHBOT.md`) | | 属性锁定 | `ENABLE_LOCK_ATTR`:把 50348/50349 拖到装备上,选择属性;锁定信息存在属性数组第 7、8 位;物品提示里显示锁定 | 独立表 `mt_item_attr_lock`;入口是洗练窗口里的 5 个锁定按钮;main 的 `2222885` 已加入 50348/50349 的消耗 | 入口和提示改成 AVA2 的方式;存储继续用独立表(7 条属性的结构放不下)。洗练窗口里的锁定按钮和锁定命令已删,50348/50349 走服务端 UseItemEx;AVA2 选槽位界面和提示未做 | | 批量开箱 | `/chest_drop`,Ctrl + 右键弹出滑块,Ctrl + Z + 右键开整叠;`AutoGiveItemChest`,单次最多 1000 | `/mt_chest`,固定 1/10/50/全部,单次最多 200,逐个调用原 `UseItem` | 窗口、按键、命令、单次上限、发奖路径 | | 批量拾取 | CG 235 `ITEMS_PICKUP`;70002 自动拾取状态 | `/mt_pickup`,自建 8 类分类窗口,只在按 Z 时触发 | 包、自动拾取状态、分类方式 | @@ -84,7 +84,7 @@ AVA2 功能包头号在当前服务端基本空闲,可以直接沿用: 改动玩家正在用的系统,旧版和新版需要同时切换,并有回滚方案。 -1. 自动洗练(已完成代码,待联机测试和部署)+ 属性锁定(界面未做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 +1. 自动洗练(已完成,联机测试通过,待 Android 测试和部署)+ 属性锁定(界面未做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 2. 批量开箱:`/chest_drop`、滑块、Ctrl + Z、`AutoGiveItemChest`。 3. 批量拾取:CG 235、70002 自动拾取。 4. 世界 Boss / 副本追踪:uitrack。 diff --git a/docs/AVA2-SWITCHBOT.md b/docs/AVA2-SWITCHBOT.md index 6a086e7f..eee3326a 100644 --- a/docs/AVA2-SWITCHBOT.md +++ b/docs/AVA2-SWITCHBOT.md @@ -48,9 +48,15 @@ - `tests/wiki/test_item_actions.py` 已更新:50348/50349 走原来的使用流程。 - 脚本能在 Python 2.7 下编译。macOS 构建(`build/switchbot-check`,关闭 MeshPort)通过,ctest 52 项全过(7 项跳过,和之前一样)。 - 服务端 `tests/features/test_switchbot.py` 同时检查客户端 `Packet.h`、`PythonSwitchbot.h` 和版本字符串。 +- 联机测试(2026-10-16,Mac 客户端 + 203 的 channel5,脚本驱动): + - 武器(channel5 连线上 db):放入、拖回、开始和停止、洗到目标自动结束、洗练中拖出被拒绝、放入无效物品被拒绝;约 12 次/秒,ItemLog 记录数和消耗数一致。 + - 戒指和护符(`tools/server/sbtest` 隔离环境,解锁后的 proto):戒指用戒指属性池(20 条),消耗 71084;护符用护符属性池,只消耗 71302。两边都能洗到目标。 + - 重新登录:物品和属性保留(从 db 缓存读和重启后从 MySQL 读都测过,`window=SWITCHBOT`);洗练停止,目标清空,和 AVA2 一样(下线时 `UnregisterItem`)。 + - 同核心换地图(1 → 21 → 1):传送后接着洗,目标保留,只在传送时暂停一下,和 AVA2 一样。 ## 未完成 -- 联机测试:channel5 或部署后的 CH1。203 正式环境还是 v1,服务端和客户端要一起部署。 +- 跨核心换线(P2P 转移)的联机测试:测试环境只有一个核心。 +- 部署:203 正式环境还是 v1。戒指和护符要整个 feature/ava2-unlock(含解锁后的 proto)一起上线,服务端和客户端也要一起部署。 - Android 构建和真机测试。 - 属性锁定界面(AVA2 拖 50348/50349,并在物品提示里显示锁定)。 diff --git a/tools/server/sbtest/README.md b/tools/server/sbtest/README.md new file mode 100644 index 00000000..44f405dc --- /dev/null +++ b/tools/server/sbtest/README.md @@ -0,0 +1,38 @@ +# 203 隔离测试环境(sbtest) + +在 203 上搭一套和线上分开的测试环境,用来联机测试还没部署的服务端功能,比如 feature/ava2-unlock 里的戒指、护符和自动洗练。线上的 db、auth、CH1–4 和线上库只读取,不会被修改。 + +| 进程 | 端口 | 目录 | 二进制 | +|---|---|---|---| +| db | 15040 | `/usr/metin2/server/sbtest/db` | `db.switchbot` 的副本 | +| auth | 11040(P2P 12040) | `/usr/metin2/server/sbtest/auth` | `sbtest/game.switchbot` | +| channel5 | 13040(P2P 14040),地图 1 21 41 | `/usr/metin2/server/channel5/first` | `sbtest/game.switchbot` | + +- 数据库:`player_sb` / `common_sb` / `account_sb` / `log_sb`,从线上库复制(用 `--default-character-set=binary` 复制,gb2312 角色名不会乱码),并导入 `../pendant/refine.sql`。 +- proto:先复制线上的 `share/conf`,再用 `../ava2-items/install_items.py` 装入解锁后的 AVA2 物品,放在 `sbtest/share/conf`。 +- channel5 原来的配置保存为 `CONFIG.livedb`,原来的 game 链接保存为 `game.livedb`。 + +## 搭建 + +先在 `/root/metin2-features-dev` 编译出 `bin/db.switchbot` 和 `bin/game.switchbot`,再在本机生成中文客户端(会顺带生成 `build/zh-locale/ava2-items/*.tsv`),然后: + +```sh +scp build/zh-locale/ava2-items/{items,mobs}-server.tsv tools/server/ava2-items/install_items.py \ + tools/server/pendant/refine.sql root@192.168.21.203:/usr/metin2/server/sbtest/stage/ +scp tools/server/sbtest/*.sh root@192.168.21.203:/usr/metin2/server/sbtest/tools/ +ssh root@192.168.21.203 sh /usr/metin2/server/sbtest/tools/setup.sh /usr/metin2/server/sbtest/stage +``` + +重新运行会删除并重新复制 `*_sb` 库,测试数据会丢失。复制前脚本会先停掉 channel5 并等 15 秒,让线上 db 把 channel5 上的玩家写回 MySQL。还在线上 db 缓存里没写回的物品不会被复制过去。 + +## 日常 + +- `restart.sh`:按 db、auth、channel5 的顺序重启。重启会清空 db 缓存,下次登录全部从 MySQL 读取。 +- `rollback.sh`:停掉测试环境,把 channel5 改回线上 db 和原来的二进制。`*_sb` 库和 `sbtest/` 目录会保留。 +- Mac 客户端:`mt_native_render --live-client build/zh-locale/Client --live-server 192.168.21.203:11040:13040 --login-screen`。zh 客户端带 ava2items 包,能显示中文。 +- GM 发物品:`/item <数量>`,单堆最多 200 个。 + +## 注意 + +- db 下线后要过一段时间才写回(`g_iLogoutSeconds`),物品缓存每 5 分钟写一次。要确认数据已经进了 MySQL,就查 `player_sb.item`,或者跑一次 `restart.sh`。 +- 只有一个核心,跨核心换线测不了。 diff --git a/tools/server/sbtest/restart.sh b/tools/server/sbtest/restart.sh new file mode 100644 index 00000000..ba84fe96 --- /dev/null +++ b/tools/server/sbtest/restart.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# (Re)starts the sbtest cluster in order db, auth, channel5 (README.md). Restarting empties the db cache, +# so the next login reads everything from MySQL. +set -eu +R=/usr/metin2/server +T=$R/sbtest +C5=$R/channel5/first +grep -q '^DB_PORT: 15040' $C5/CONFIG || { echo "channel5 is not on the sbtest db; run setup.sh" >&2; exit 1; } + +for d in $C5 $T/auth $T/db; do + [ -f $d/pid ] || continue + p=$(cat $d/pid) + kill -0 "$p" 2>/dev/null || continue + kill -1 "$p" + i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done + echo "$d stopped after ${i}s" +done + +daemon -f sh -c "cd $T/db && exec ./db > stdout 2>&1"; sleep 6 +daemon -f sh -c "cd $T/auth && exec ./auth > stdout 2>&1"; sleep 4 +daemon -f sh -c "cd $C5 && exec ./game > stdout 2>&1"; sleep 12 +sockstat -l | grep -E ':(15040|11040|12040|13040|14040) ' +echo "live db/auth listening: $(sockstat -l | grep -c -E ':(15000|11000) ') (expect 2)" diff --git a/tools/server/sbtest/rollback.sh b/tools/server/sbtest/rollback.sh new file mode 100644 index 00000000..5f7f41a8 --- /dev/null +++ b/tools/server/sbtest/rollback.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Stops the sbtest cluster and puts channel5 back on the live db with the binary it had before setup.sh +# (README.md). The *_sb schemas and /usr/metin2/server/sbtest stay; setup.sh rebuilds them. +set -eu +R=/usr/metin2/server +T=$R/sbtest +C5=$R/channel5/first +[ -f $C5/CONFIG.livedb ] || { echo "no $C5/CONFIG.livedb; channel5 was never moved" >&2; exit 1; } + +for d in $C5 $T/auth $T/db; do + [ -f $d/pid ] || continue + p=$(cat $d/pid) + kill -0 "$p" 2>/dev/null || continue + kill -1 "$p" + i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done + echo "$d stopped after ${i}s" +done + +cp $C5/CONFIG.livedb $C5/CONFIG +[ -e $C5/game.livedb ] && { rm -f $C5/game; mv $C5/game.livedb $C5/game; } +daemon -f sh -c "cd $C5 && exec ./game > stdout 2>&1"; sleep 12 +grep -E '^DB_PORT' $C5/CONFIG; ls -l $C5/game +sockstat -l | grep -E ':(13040) ' diff --git a/tools/server/sbtest/setup.sh b/tools/server/sbtest/setup.sh new file mode 100644 index 00000000..8e23a5b2 --- /dev/null +++ b/tools/server/sbtest/setup.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Builds the isolated test cluster on 203 (README.md): sbtest db :15040 + auth :11040, and channel5 moved onto it, +# all on *_sb copies of the live schemas. Live db / auth / CH1-4 and the live schemas are only read. +# Usage (on the server): sh setup.sh ; the stage dir holds items-server.tsv, mobs-server.tsv, +# install_items.py (../ava2-items) and refine.sql (../pendant). A rerun drops and recopies the *_sb schemas. +set -eu +STAGE=$(cd "$1" && pwd) +R=/usr/metin2/server +T=$R/sbtest +DEV=${DEV:-/root/metin2-features-dev} +C5=$R/channel5/first +for f in items-server.tsv mobs-server.tsv install_items.py refine.sql; do [ -f "$STAGE/$f" ] || { echo "missing $STAGE/$f" >&2; exit 1; }; done +[ -x $DEV/bin/db.switchbot ] && [ -x $DEV/bin/game.switchbot ] || { echo "build db.switchbot / game.switchbot in $DEV first" >&2; exit 1; } + +stop() # : SIGHUP the process in /pid and wait for it +{ + [ -f "$1/pid" ] || return 0 + p=$(cat "$1/pid") + kill -0 "$p" 2>/dev/null || return 0 + kill -1 "$p" + i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done + echo "$1 stopped after ${i}s" +} + +# 1. stop channel5 and an earlier sbtest cluster; the live db flushes channel5's players on logout +stop $C5; stop $T/auth; stop $T/db +sleep 15 + +# 2. copy the schemas (the binary connection charset keeps the gb2312 name bytes untouched) +for s in player common account log; do + mysql -uroot -e "DROP DATABASE IF EXISTS ${s}_sb; CREATE DATABASE ${s}_sb" + mysqldump -uroot --default-character-set=binary --routines --triggers --single-transaction $s | mysql -uroot --default-character-set=binary ${s}_sb + echo "$s -> ${s}_sb: $(mysql -uroot -N -e "select count(*) from information_schema.tables where table_schema='${s}_sb'") tables" +done +mysql -uroot --default-character-set=binary player_sb < $STAGE/refine.sql +echo "talisman refine rows: $(mysql -uroot -N -e 'select count(*) from player_sb.refine_proto where id between 440 and 499 and cost=50000')" + +# 3. protos: live copies + the unlocked AVA2 rows +mkdir -p $T/share/conf +for f in item_proto item_names mob_proto mob_names; do cp $R/share/conf/$f.txt $T/share/conf/$f.txt; done +rm -rf $T/backup-conf +/usr/local/bin/python3.9 $STAGE/install_items.py $T $STAGE/items-server.tsv $T/backup-conf $STAGE/mobs-server.tsv + +# 4. db +mkdir -p $T/db/log $T/db/cores +cp $DEV/bin/db.switchbot $T/db/db +for f in item_proto item_names mob_proto mob_names; do ln -sf ../share/conf/$f.txt $T/db/$f.txt; done +sed -e 's/^BIND_PORT = .*/BIND_PORT = 15040/' \ + -e 's/ account metin2/ account_sb metin2/' -e 's/ common metin2/ common_sb metin2/' -e 's/ player metin2/ player_sb metin2/' \ + $R/db/conf.txt > $T/db/conf.txt + +# 5. auth +mkdir -p $T/auth/log $T/auth/cores $T/auth/mark +cp $DEV/bin/game.switchbot $T/game.switchbot +ln -sf ../game.switchbot $T/auth/auth +for d in data locale package; do ln -sfn ../../share/$d $T/auth/$d; done +sed -e 's/^HOSTNAME: .*/HOSTNAME: sbauth/' -e 's/^PORT: .*/PORT: 11040/' -e 's/^P2P_PORT: .*/P2P_PORT: 12040/' -e 's/^DB_PORT: .*/DB_PORT: 15040/' \ + -e 's/password account$/password account_sb/' -e 's/password common$/password common_sb/' -e 's/password log$/password log_sb/' \ + $R/auth/CONFIG > $T/auth/CONFIG + +# 6. channel5 -> sbtest db (CONFIG.livedb + game.livedb keep the old setup for rollback.sh) +[ -f $C5/CONFIG.livedb ] || cp $C5/CONFIG $C5/CONFIG.livedb +[ -e $C5/game.livedb ] || cp -P $C5/game $C5/game.livedb +sed -e 's/^DB_PORT: .*/DB_PORT: 15040/' \ + -e 's/password player$/password player_sb/' -e 's/password common$/password common_sb/' -e 's/password log$/password log_sb/' \ + $C5/CONFIG.livedb > $C5/CONFIG +ln -sfn $T/game.switchbot $C5/game + +# 7. start db, auth, channel5 +sh $(dirname "$0")/restart.sh