二七王:前端删掉 9 处阶段/控制权推导,一律读服务端包字段

I-3 前端不再持有对局状态机(配合服务端上一提交的下发面补齐):
- 删掉 5 处按 rpc 名硬编码的 aset.step(Deal=1 / Call=2 / Main=3 / Bury=5 / Result=6),
  一律改 _apply 读包里的 step
- 删掉 4 处 turn.seat = aset.banker(CallHandler / MainHandler / ResyncHandler×2),
  增量路径读 nextseat、重连路径读分组里的 seat;同一条规则不再有 4 个写入处

I-2 ResyncHandler._applyBalance 由只接 aset 扩为接 aset/bottom/account,
结算面板开着时重连/硬刷新不再丢抠底明细与末局大结算。
一致性测试 EXCLUDE 随之从 4 条收缩为 2 条(去掉 result.bottom / result.account,
只留一次性事件 table.ancard3s 与归下一轮的 result.chupai),未新增任何豁免条目。

夹具按新包结构重跑(种子不变,牌局不变):diff 纯为 67 行新增字段、0 行删除;
test_fixture 补上 step/nextseat/Balance 同源断言(68→82 checks)。
export_packets.js 里关于 playproc/seatlist 活引用的注释已过时,更正为仍存在的
Balance.readystate 与三份结算快照。

各 handler 单测补齐新字段并新增守卫用例:刻意构造 nextseat != banker、
step 为非预期值的包,使「退回硬编码/banker 反推」的写法必然转红(11/11 已验证)。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-27 21:31:20 +08:00
co-authored by Claude Opus 5
parent 5d981a722e
commit 8b2cfdaf27
14 changed files with 284 additions and 55 deletions
+5 -3
View File
@@ -108,10 +108,12 @@ function drain() {
// packetIndex 是关键对齐锚点:取快照时先 drain,记下该座位此刻已收到的包数,
// 与 Task 12 一致性测试"喂完 seats[seat] 的前 packetIndex 个包"对齐。
//
// 【必须 clone】class.export.js 的 get_deskinfo 在 step5 分支对 PushCards.playproc /
// PushCards.seatlist 是【无拷贝的活引用赋值】(deskinfo.PushCards.playproc = paiju.playproc)。
// 【必须 clone】get_deskinfo 的返回值里仍有若干【无拷贝的活引用赋值】——
// 例如 Balance.readystate = o_desk.prepare、Balance.aset/bottom/account 三份结算快照。
// (PushCards.playproc / PushCards.seatlist / pushlist / burycards 已各自走深拷贝快照函数,
// 这段注释早先把它们也算在内,已过时,现更正。)
// 真实链路里这份返回值被平台立刻序列化下发,活引用不会被观测到;但本脚本要跑完整局之后才
// 统一 JSON.stringify 写盘,若不在这里当场拷贝一份,写盘时这些字段会被后续出牌篡改成终局
// 统一 JSON.stringify 写盘,若不在这里当场拷贝一份,写盘时这些字段会被后续操作篡改成终局
// 状态,导致同一座位不同 packetIndex 下的快照"逐字节相同"——这是本脚本自身的缺陷,与服务端
// 无关(服务端没有"延后序列化"这个用法)。
function snap(step, seat) {
+67
View File
@@ -169,6 +169,7 @@
"success": true,
"asetidx": 1,
"asetcount": 6,
"step": 1,
"seat": 0,
"countdown": 15,
"cards": [
@@ -211,6 +212,7 @@
"call": 65,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 1,
"countdown": 15
}
@@ -223,6 +225,7 @@
"call": 0,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 2,
"countdown": 15
}
@@ -236,6 +239,8 @@
"banker": 0,
"grade": 65,
"multiple": 2,
"step": 2,
"nextseat": 0,
"countdown": 20,
"touxiang": 0,
"curmultiple": 3,
@@ -295,6 +300,8 @@
"success": true,
"banker": 0,
"flower": 1,
"step": 3,
"nextseat": 0,
"countdown": 25,
"cards": [
52,
@@ -340,6 +347,7 @@
"rpc": "maipai",
"data": {
"success": true,
"step": 5,
"seat": 0,
"countdown": 30,
"seatlist": [
@@ -5908,6 +5916,7 @@
71
]
},
"step": 6,
"aset": {
"banker": 0,
"call": 65,
@@ -5973,6 +5982,7 @@
"success": true,
"asetidx": 1,
"asetcount": 6,
"step": 1,
"seat": 0,
"countdown": 15,
"cards": [
@@ -6015,6 +6025,7 @@
"call": 65,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 1,
"countdown": 15
}
@@ -6027,6 +6038,7 @@
"call": 0,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 2,
"countdown": 15
}
@@ -6040,6 +6052,8 @@
"banker": 0,
"grade": 65,
"multiple": 2,
"step": 2,
"nextseat": 0,
"countdown": 20,
"touxiang": 0,
"curmultiple": 3
@@ -6051,6 +6065,8 @@
"success": true,
"banker": 0,
"flower": 1,
"step": 3,
"nextseat": 0,
"countdown": 25,
"cards": [
106,
@@ -6088,6 +6104,7 @@
"rpc": "maipai",
"data": {
"success": true,
"step": 5,
"seat": 0,
"countdown": 30,
"seatlist": [
@@ -11622,6 +11639,7 @@
71
]
},
"step": 6,
"aset": {
"banker": 0,
"call": 65,
@@ -11687,6 +11705,7 @@
"success": true,
"asetidx": 1,
"asetcount": 6,
"step": 1,
"seat": 0,
"countdown": 15,
"cards": [
@@ -11729,6 +11748,7 @@
"call": 65,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 1,
"countdown": 15
}
@@ -11741,6 +11761,7 @@
"call": 0,
"currcall": 65,
"multiple": 2,
"step": 1,
"nextseat": 2,
"countdown": 15
}
@@ -11754,6 +11775,8 @@
"banker": 0,
"grade": 65,
"multiple": 2,
"step": 2,
"nextseat": 0,
"countdown": 20,
"touxiang": 0,
"curmultiple": 3
@@ -11765,6 +11788,8 @@
"success": true,
"banker": 0,
"flower": 1,
"step": 3,
"nextseat": 0,
"countdown": 25,
"cards": [
53,
@@ -11802,6 +11827,7 @@
"rpc": "maipai",
"data": {
"success": true,
"step": 5,
"seat": 0,
"countdown": 30,
"seatlist": [
@@ -17335,6 +17361,7 @@
71
]
},
"step": 6,
"aset": {
"banker": 0,
"call": 65,
@@ -17615,6 +17642,7 @@
59
],
"ChooseMain": {
"seat": 0,
"banker": 0,
"call": 65,
"multiple": 2,
@@ -17678,6 +17706,7 @@
4
],
"ChooseMain": {
"seat": 0,
"banker": 0,
"call": 65,
"multiple": 2,
@@ -17731,6 +17760,7 @@
61
],
"ChooseMain": {
"seat": 0,
"banker": 0,
"call": 65,
"multiple": 2,
@@ -17792,6 +17822,7 @@
71
],
"BuryCards": {
"seat": 0,
"banker": 0,
"call": 65,
"multiple": 2,
@@ -19438,6 +19469,18 @@
"score": -2
}
]
},
"bottom": {
"cards": [
67,
79,
23,
75,
20,
18,
72,
71
]
}
}
}
@@ -19516,6 +19559,18 @@
"score": -2
}
]
},
"bottom": {
"cards": [
67,
79,
23,
75,
20,
18,
72,
71
]
}
}
}
@@ -19594,6 +19649,18 @@
"score": -2
}
]
},
"bottom": {
"cards": [
67,
79,
23,
75,
20,
18,
72,
71
]
}
}
}
+4 -2
View File
@@ -26,8 +26,10 @@ const fx = JSON.parse(fs.readFileSync(path.join(ROOT, 'client/tests/fixtures/pac
const EXCLUDE = [
// 70 分坐庄的 3 秒开底是上庄时的一次性事件,协议明确 deskinfo 不重放
'table.ancard3s',
// 结算明细来自 jiesuan 包,deskinfo 的 Balance 只在结算阶段带 aset
'result.chupai', 'result.bottom', 'result.account'
// 收尾墩:牌局最后一手不发 chupai3,整包换成 jiesuan,其 data.chupai 由 ResultHandler
// 归档进 result.chupai;deskinfo 的 Balance 不带这一墩(它属于「出牌过程」而非结算数据)。
// 【本条是本清单仅剩的松口处】result.bottom / result.account 已随服务端 Balance 补发而移除。
'result.chupai'
];
function pick(snap, exclude) {
+38
View File
@@ -63,6 +63,44 @@ Object.keys(step5BySeat).forEach(seat => {
}
});
// I-3:推进阶段的下发包必须自带 step,且与该时刻的 deskinfo.step 属于同一套取值。
// 前端不得按 rpc 名硬编码阶段(前端红线「数据驱动、前端无对局状态机」)。
const STEP_OF = { fapai: 1, jiaofen: 1, shangzhuang: 2, xuanzhu: 3, maipai: 5, jiesuan: 6 };
const noStep = [], badStep = [];
[0, 1, 2].forEach(s => fx.seats[s].forEach(p => {
if (!STEP_OF.hasOwnProperty(p.rpc)) { return; }
if (!p.data.hasOwnProperty('step')) { noStep.push(s + ':' + p.rpc); return; }
if (p.data.step !== STEP_OF[p.rpc]) { badStep.push(s + ':' + p.rpc + '=' + p.data.step); }
}));
t.eq('推进阶段的下发包都带 step', noStep, []);
t.eq('各包的 step 就是该时点的真实阶段', badStep, []);
// I-3:选主/埋牌阶段的「轮到谁」必须由服务端显式给出(增量 nextseat / 重连分组的 seat)
const noNext = [];
[0, 1, 2].forEach(s => fx.seats[s].forEach(p => {
if ((p.rpc === 'shangzhuang' || p.rpc === 'xuanzhu') && !p.data.hasOwnProperty('nextseat')) {
noNext.push(s + ':' + p.rpc);
}
}));
t.eq('shangzhuang/xuanzhu 都带 nextseat(控制权)', noNext, []);
fx.deskinfo.filter(d => d.step === 2).forEach(d => {
t.eq('重连 ChooseMain 带控制权 seat (seat' + d.seat + ')', typeof d.info.ChooseMain.seat, 'number');
});
fx.deskinfo.filter(d => d.step === 3).forEach(d => {
t.eq('重连 BuryCards 带控制权 seat (seat' + d.seat + ')', typeof d.info.BuryCards.seat, 'number');
});
// I-2:结算阶段的重连包必须与 jiesuan 推送给同一份结算数据(抠底明细 bottom 恒有;
// account 只在末局,本夹具是第 1/6 局,故两条路径都没有)
const jiesuanPk = fx.seats[0].filter(p => p.rpc === 'jiesuan')[0];
t.eq('夹具的 jiesuan 带抠底明细 bottom', !!(jiesuanPk && jiesuanPk.data.bottom), true);
fx.deskinfo.filter(d => d.step === 6).forEach(d => {
t.eq('重连 Balance.bottom == jiesuan.bottom (seat' + d.seat + ')',
JSON.stringify(d.info.Balance.bottom), JSON.stringify(jiesuanPk.data.bottom));
t.eq('非末局:两条路径都不带 account (seat' + d.seat + ')',
[d.info.Balance.hasOwnProperty('account'), jiesuanPk.data.hasOwnProperty('account')], [false, false]);
});
// 每个包都有 success(协议 §0.1:每个下发包的 data 必带 success)
const noSuccess = [];
[0,1,2].forEach(s => fx.seats[s].forEach(p => {
+23 -10
View File
@@ -14,37 +14,45 @@ Object.keys(EQW_Events).forEach(k => EventBus.on(EQW_Events[k], () => evts.push(
// ================= xuanzhu =================
S.reset(); evts.length = 0;
EQW_MainHandler.handleXuanzhu({ success: true, banker: 1, flower: 3,
EQW_MainHandler.handleXuanzhu({ success: true, banker: 1, flower: 3, step: 3, nextseat: 1,
countdown: 30, cards: [5, 6, 7] });
t.eq('主牌花色', S.aset.flower, 3);
t.eq('庄家', S.aset.banker, 1);
t.eq('选主后手牌', S.my.cards, [5, 6, 7]);
t.eq('step 置为埋牌', S.aset.step, 3);
t.eq('控制权归庄家', S.turn.seat, 1);
t.eq('step 读包字段(埋牌=3)', S.aset.step, 3);
t.eq('控制权读包里的 nextseat', S.turn.seat, 1);
t.eq('倒计时', S.turn.countdown, 30);
t.eq('选主发事件',
['EQW_MAIN_SET','EQW_HAND_CHANGED'].every(e => evts.indexOf(e) >= 0), true);
// 闲家视角:没有 cards,不抹已有手牌
S.reset(); S.my.cards = [1, 2];
EQW_MainHandler.handleXuanzhu({ success: true, banker: 0, flower: 2, countdown: 30 });
EQW_MainHandler.handleXuanzhu({ success: true, banker: 0, flower: 2, step: 3, nextseat: 0, countdown: 30 });
t.eq('闲家手牌不被抹', S.my.cards, [1, 2]);
t.eq('闲家也拿到花色', S.aset.flower, 2);
// 【守卫】阶段与控制权都必须来自包,不得按 rpc 名硬编码、也不得用本地 banker 反推。
// 真实链路里 nextseat 恒 == banker,相等时"读哪个"分辨不出来;这里刻意让它们不同,
// 退回 `aset.step = 3` / `turn.seat = aset.banker` 的写法必转红。
S.reset();
EQW_MainHandler.handleXuanzhu({ success: true, banker: 0, flower: 2, step: 4, nextseat: 2, countdown: 30 });
t.eq('xuanzhu step 照读包字段', S.aset.step, 4);
t.eq('xuanzhu 控制权取 nextseat,不取 banker', S.turn.seat, 2);
// ================= maipai =================
S.reset(); evts.length = 0;
EQW_BuryHandler.handle({ success: true, cards: [1,2,3], burycards: [9,10,11,12,13,14,15,16],
seat: 1, countdown: 20 });
step: 5, seat: 1, countdown: 20 });
t.eq('埋牌后手牌', S.my.cards, [1,2,3]);
t.eq('埋牌底牌', S.my.buryCards, [9,10,11,12,13,14,15,16]);
t.eq('step 置为出牌', S.aset.step, 5);
t.eq('首出者', S.turn.seat, 1);
t.eq('step 读包字段(出牌=5)', S.aset.step, 5);
t.eq('首出者(控制权读包里的 seat)', S.turn.seat, 1);
t.eq('埋牌发事件',
['EQW_BURY_DONE','EQW_HAND_CHANGED','EQW_TURN_CHANGED'].every(e => evts.indexOf(e) >= 0), true);
// 闲家视角:无 cards/burycards,但可能有 liangpai
S.reset(); S.my.cards = [4, 5]; evts.length = 0;
EQW_BuryHandler.handle({ success: true, seat: 0, countdown: 20,
EQW_BuryHandler.handle({ success: true, step: 5, seat: 0, countdown: 20,
liangpai: { cards: [52, 53, 2, 15] } });
t.eq('闲家手牌不被抹', S.my.cards, [4, 5]);
t.eq('闲家无埋牌底牌', S.my.buryCards, []);
@@ -52,14 +60,19 @@ t.eq('亮牌数据', S.table.liangpai, { cards: [52, 53, 2, 15] });
// 不达标/不查牌:无 liangpai 字段,保持 null
S.reset();
EQW_BuryHandler.handle({ success: true, seat: 0, countdown: 20 });
EQW_BuryHandler.handle({ success: true, step: 5, seat: 0, countdown: 20 });
t.eq('无亮牌时保持 null', S.table.liangpai, null);
// 【守卫】maipai 的 step 同样只读包字段
S.reset();
EQW_BuryHandler.handle({ success: true, step: 4, seat: 0, countdown: 20 });
t.eq('maipai step 照读包字段(不按 rpc 名硬编码)', S.aset.step, 4);
// playproc:埋牌完成时服务端已就地开好 round-1 的进行态,恒有、原样拷贝进 table.playproc,
// 与 chupai1/2/3.playproc 同源同结构(协议 §9),漏接会让「埋牌完成→庄家首出」这段窗口
// 增量路径 table.playproc 停在上一阶段的 null、与重连路径不一致
S.reset();
EQW_BuryHandler.handle({ success: true, seat: 0, countdown: 20, cards: [1, 2, 3],
EQW_BuryHandler.handle({ success: true, step: 5, seat: 0, countdown: 20, cards: [1, 2, 3],
burycards: [9, 10, 11, 12, 13, 14, 15, 16],
playproc: { round: 1, start: 0, currseat: 0, startcount: -1,
startflower: -1, starttype: -1, maxseat: -1, maxcard: -1,
+28 -9
View File
@@ -15,43 +15,50 @@ Object.keys(EQW_Events).forEach(k => EventBus.on(EQW_Events[k], () => evts.push(
// ================= fapai =================
S.reset(); S.room.mySeat = 1; evts.length = 0;
EQW_DealHandler.handle({ success: true, asetidx: 2, asetcount: 6,
cards: [1, 2, 3], seat: 0, countdown: 15 });
cards: [1, 2, 3], step: 1, seat: 0, countdown: 15 });
t.eq('局数', S.room.asetIdx, 2);
t.eq('总局数', S.room.asetCount, 6);
t.eq('手牌', S.my.cards, [1, 2, 3]);
t.eq('当前叫分者', S.turn.seat, 0);
t.eq('倒计时', S.turn.countdown, 15);
t.eq('step 置为叫分', S.aset.step, 1);
t.eq('step 读包字段(叫分=1)', S.aset.step, 1);
t.eq('mySeat 未被 reset 冲掉', S.room.mySeat, 1);
t.eq('fapai 发了 RESET/HAND/TURN 事件',
['EQW_RESET','EQW_HAND_CHANGED','EQW_TURN_CHANGED'].every(e => evts.indexOf(e) >= 0), true);
// fapai 必须先 reset:上一局的残留要清掉
S.aset.banker = 2; S.table.pushlist = [[9]];
EQW_DealHandler.handle({ success: true, asetidx: 3, asetcount: 6, cards: [4], seat: 1, countdown: 15 });
EQW_DealHandler.handle({ success: true, asetidx: 3, asetcount: 6, cards: [4], step: 1, seat: 1, countdown: 15 });
t.eq('fapai 清掉上局 banker', S.aset.banker, -1);
t.eq('fapai 清掉上局 pushlist', S.table.pushlist, []);
// 【守卫】step 必须来自包,不得按 rpc 名硬编码。这里刻意给一个"服务端将来新插的阶段"值:
// 前端应照单收下(服务端权威),而不是把它改回 1。退回 `aset.step = 1` 的写法必转红。
EQW_DealHandler.handle({ success: true, asetidx: 3, asetcount: 6, cards: [4], step: 4, seat: 1, countdown: 15 });
t.eq('fapai step 照读包字段(不按 rpc 名硬编码)', S.aset.step, 4);
// ================= jiaofen =================
S.reset(); evts.length = 0;
EQW_CallHandler.handleJiaofen({ success: true, seat: 0, call: 60, currcall: 60,
multiple: 3, nextseat: 1, countdown: 15 });
multiple: 3, step: 1, nextseat: 1, countdown: 15 });
t.eq('记录该家叫分', S.call.calls, [60, null, null]);
t.eq('当前叫到的分', S.call.currcall, 60);
t.eq('基础子数', S.aset.multiple, 3);
t.eq('jiaofen step 读包字段(仍在叫分=1)', S.aset.step, 1);
t.eq('下一个叫分者', S.turn.seat, 1);
t.eq('jiaofen 发事件', evts.indexOf('EQW_CALL_CHANGED') >= 0, true);
// 不叫(call = 0)也要记下来,与「还没叫」(null) 区分
EQW_CallHandler.handleJiaofen({ success: true, seat: 1, call: 0, currcall: 60,
multiple: 3, nextseat: 2, countdown: 15 });
multiple: 3, step: 1, nextseat: 2, countdown: 15 });
t.eq('不叫记为 0,与未叫 null 区分', S.call.calls, [60, 0, null]);
// ================= shangzhuang =================
S.reset(); evts.length = 0;
EQW_CallHandler.handleShangzhuang({ success: true, seat: 0, call: 70, banker: 0, grade: 70,
multiple: 2, bottomcards: [1,2,3,4,5,6,7,8], ancard3s: 1,
multiple: 2, step: 2, nextseat: 0,
bottomcards: [1,2,3,4,5,6,7,8], ancard3s: 1,
cards: [1,2,3], countdown: 20, touxiang: 1, curmultiple: 3 });
t.eq('庄家', S.aset.banker, 0);
t.eq('庄家叫分', S.aset.call, 70);
@@ -61,15 +68,27 @@ t.eq('抓分倍数', S.aset.curmultiple, 3);
t.eq('开底标志', S.table.ancard3s, 1);
t.eq('底牌', S.my.bottomCards, [1,2,3,4,5,6,7,8]);
t.eq('摸底后手牌', S.my.cards, [1,2,3]);
t.eq('step 置为选主', S.aset.step, 2);
t.eq('控制权给庄家', S.turn.seat, 0);
t.eq('step 读包字段(选主=2)', S.aset.step, 2);
t.eq('控制权读包里的 nextseat', S.turn.seat, 0);
t.eq('shangzhuang 发事件',
['EQW_BANKER_SET','EQW_HAND_CHANGED'].every(e => evts.indexOf(e) >= 0), true);
// 【守卫】控制权必须来自包里的 nextseat,不得用本地 banker 反推。
// 真实链路里 nextseat 恒 == banker,两者相等时"读哪个"分辨不出来;这里刻意让它们不同,
// 退回 `turn.seat = EQW_GameState.aset.banker` 的写法必转红。
// 同理 data.seat(=最后一个叫分者)也不是控制权,这里也给成第三个值。
S.reset();
EQW_CallHandler.handleShangzhuang({ success: true, seat: 1, call: 55, banker: 0, grade: 55,
multiple: 4, step: 2, nextseat: 2,
countdown: 20, touxiang: 0, curmultiple: 3 });
t.eq('控制权取 nextseat,不取 banker', S.turn.seat, 2);
t.eq('控制权不取 data.seat(最后一个叫分者)', S.turn.seat !== 1, true);
// 闲家视角:没有 cards / bottomcards(非 70 分),缺字段不能把已有值抹掉
S.reset(); S.my.cards = [7, 8, 9];
EQW_CallHandler.handleShangzhuang({ success: true, seat: 0, call: 55, banker: 0, grade: 55,
multiple: 4, countdown: 20, touxiang: 0, curmultiple: 3 });
multiple: 4, step: 2, nextseat: 0,
countdown: 20, touxiang: 0, curmultiple: 3 });
t.eq('闲家手牌不被抹', S.my.cards, [7, 8, 9]);
t.eq('闲家无底牌', S.my.bottomCards, []);
t.eq('非 70 分无开底标志', S.table.ancard3s, 0);
+12 -5
View File
@@ -17,7 +17,7 @@ const ASET = { banker: 0, call: 60, multiple: 3, flower: 3, grade: 45, upgrade:
// ================= 正常出牌结算 =================
S.reset(); evts.length = 0;
EQW_ResultHandler.handleJiesuan({ success: true,
EQW_ResultHandler.handleJiesuan({ success: true, step: 6,
chupai: { seat: 2, cards: [9], maxseat: 0, grade: 10 },
bottom: { cards: [1,2,3,4,5,6,7,8], multiple: 2, grade1: 20, grade2: 40 },
aset: ASET });
@@ -25,13 +25,13 @@ EQW_ResultHandler.handleJiesuan({ success: true,
t.eq('小局结算入状态', S.result.aset, ASET);
t.eq('抠底入状态', S.result.bottom.grade2, 40);
t.eq('最后一手入状态', S.result.chupai.maxseat, 0);
t.eq('step 置为结算', S.aset.step, 6);
t.eq('step 读包字段(结算=6)', S.aset.step, 6);
t.eq('结算发事件', evts.indexOf('EQW_ASET_RESULT') >= 0, true);
t.eq('非末局不发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') < 0, true);
// ================= 投降结算(无 chupai / 无 bottom)=================
S.reset(); evts.length = 0;
EQW_ResultHandler.handleJiesuan({ success: true, aset: { banker: 0, call: 70, multiple: 1,
EQW_ResultHandler.handleJiesuan({ success: true, step: 6, aset: { banker: 0, call: 70, multiple: 1,
upgrade: -99, seatlist: [] } });
t.eq('投降结算入状态', S.result.aset.upgrade, -99);
t.eq('投降无 chupai', S.result.chupai, null);
@@ -43,18 +43,25 @@ const ACCOUNT = [{ score: 12, grades: [6,6], grade_jf_total: 8, grade_cg_total:
{ score: -6, grades: [-3,-3], grade_jf_total: -4, grade_cg_total: -2, grade_bw_total: 0 },
{ score: -6, grades: [-3,-3], grade_jf_total: -4, grade_cg_total: -2, grade_bw_total: 0 }];
S.reset(); evts.length = 0;
EQW_ResultHandler.handleJiesuan({ success: true, aset: ASET, account: ACCOUNT });
EQW_ResultHandler.handleJiesuan({ success: true, step: 6, aset: ASET, account: ACCOUNT });
t.eq('大局结算入状态', S.result.account, ACCOUNT);
t.eq('末局发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') >= 0, true);
// ================= 解散:走 Free 入口,取值少一层 =================
S.reset(); evts.length = 0;
EQW_ResultHandler.handleFree({ rpc: 'jiesuan',
data: { success: true, aset: { banker: -1, call: -1, multiple: 0, upgrade: 0, seatlist: [] },
data: { success: true, step: 6, aset: { banker: -1, call: -1, multiple: 0, upgrade: 0, seatlist: [] },
account: ACCOUNT } });
t.eq('解散取到 aset', S.result.aset.multiple, 0);
t.eq('解散取到 account', S.result.account, ACCOUNT);
t.eq('解散发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') >= 0, true);
t.eq('解散包的 step 也读包字段', S.aset.step, 6);
// 【守卫】结算 step 只读包字段,不按 rpc 名硬编码为 6。
// 退回 `aset.step = 6` 的写法必转红。
S.reset();
EQW_ResultHandler.handleJiesuan({ success: true, step: 4, aset: ASET });
t.eq('jiesuan step 照读包字段', S.aset.step, 4);
// ================= 解散:deskfree 为 null(首局发牌前解散)=================
S.reset(); evts.length = 0;
+45 -3
View File
@@ -73,25 +73,67 @@ t.eq('三家叫分', S.call.calls, [null, 0, 65]);
S.reset(); evts.length = 0;
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 1, PlayerInfo: [0,0,0], step: 2, MyCards: [1,2],
ChooseMain: { banker: 0, call: 70, multiple: 2, countdown: 20,
ChooseMain: { seat: 0, banker: 0, call: 70, multiple: 2, countdown: 20,
bottomcards: [1,2,3,4,5,6,7,8], touxiang: 1 }
});
t.eq('选主阶段', S.aset.step, 2);
t.eq('底牌', S.my.bottomCards, [1,2,3,4,5,6,7,8]);
t.eq('允许投降', S.aset.touxiang, 1);
t.eq('控制权归庄家', S.turn.seat, 0);
t.eq('控制权读 ChooseMain.seat', S.turn.seat, 0);
// 重连【不重放】70 分开底:deskinfo 里没有 ancard3s
t.eq('重连不重放开底', S.table.ancard3s, 0);
// 【守卫】控制权取分组里的 seat(服务端权威),不用本地 banker 反推。
// 真实链路里 ChooseMain.seat 恒 == banker,相等时"读哪个"分辨不出来;这里刻意让它们不同,
// 退回 `turn.seat = aset.banker` 的写法必转红。
S.reset();
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 1, PlayerInfo: [0,0,0], step: 2, MyCards: [1,2],
ChooseMain: { seat: 2, banker: 0, call: 70, multiple: 2, countdown: 20, touxiang: 1 }
});
t.eq('ChooseMain 控制权取 seat,不取 banker', S.turn.seat, 2);
// ================= deskinfo:step 3 埋牌阶段 =================
S.reset();
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 1, PlayerInfo: [0,0,0], step: 3, MyCards: [1,2],
BuryCards: { seat: 0, banker: 0, call: 65, multiple: 2, flower: 1, countdown: 25,
bottomcards: [1,2,3,4,5,6,7,8], curmultiple: 3 }
});
t.eq('埋牌阶段', S.aset.step, 3);
t.eq('控制权读 BuryCards.seat', S.turn.seat, 0);
// 同样的守卫:seat 与 banker 刻意不同
S.reset();
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 1, PlayerInfo: [0,0,0], step: 3, MyCards: [1,2],
BuryCards: { seat: 1, banker: 0, call: 65, multiple: 2, flower: 1, countdown: 25 }
});
t.eq('BuryCards 控制权取 seat,不取 banker', S.turn.seat, 1);
// ================= deskinfo:step 6 结算阶段 =================
S.reset(); evts.length = 0;
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 6, PlayerInfo: [12,-6,-6], step: 6, MyCards: [],
Balance: { readystate: [1,0,0], aset: { banker: 0, upgrade: 1, seatlist: [] } }
Balance: { readystate: [1,0,0], aset: { banker: 0, upgrade: 1, seatlist: [] },
bottom: { cards: [1,2,3,4,5,6,7,8], multiple: 2, grade1: 20, grade2: 40 },
account: [{ score: 12 }, { score: -6 }, { score: -6 }] }
});
t.eq('结算阶段', S.aset.step, 6);
t.eq('小局结算数据', S.result.aset.upgrade, 1);
// I-2:结算面板还开着时重连,抠底明细与大局结算必须一并恢复(与 jiesuan 推送同一份数据)。
// 漏接会让重连后抠底明细、末局大结算全部空白
t.eq('重连恢复抠底明细', S.result.bottom.grade2, 40);
t.eq('重连恢复大局结算', S.result.account.length, 3);
// 反面:非末局 / 投降局的 Balance 没有 bottom / account,缺字段保持 null,不兜底造分组
S.reset();
EQW_ResyncHandler.handleDeskinfo({
count: 6, idx: 2, PlayerInfo: [0,0,0], step: 6, MyCards: [],
Balance: { readystate: [0,0,0], aset: { banker: 0, upgrade: -99, seatlist: [] } }
});
t.eq('无抠底分组时保持 null', S.result.bottom, null);
t.eq('无大局结算时保持 null', S.result.account, null);
// ================= StartWar:差异化下发 =================
S.reset(); S.room.mySeat = 2; evts.length = 0;