feat(client): 锁定终局结果并接入 Windows 签名构建
- fix(match): 首次归零结束对局并撤销双方扣血许可,裁判结果同步后不再改判 - fix(hud): 蓝方低血量始终保留队伍颜色 - build(windows): 校验代码签名身份和时间戳,明确标注未签名测试包 - docs(version): 说明发布标签基线与语义版本迭代
This commit is contained in:
26 files changed
+823
-229
No files matched your search
@@ -50,6 +50,8 @@ use std::net::{Ipv4Addr, SocketAddrV4};
|
||||
|
||||
mod match_state;
|
||||
pub use match_state::MatchState;
|
||||
mod match_result;
|
||||
pub use match_result::MatchResult;
|
||||
mod armor_damage;
|
||||
pub use armor_damage::ArmorDamageControl;
|
||||
mod armor_reset;
|
||||
@@ -128,6 +130,8 @@ pub enum MsgType {
|
||||
ArmorDamageControl = 8,
|
||||
/// 裁判定向复位装甲板及板端回执。
|
||||
ArmorReset = 9,
|
||||
/// 裁判广播的锁定胜负及结束计时,自包含快照(5601)。
|
||||
MatchResult = 10,
|
||||
}
|
||||
|
||||
impl MsgType {
|
||||
@@ -143,6 +147,7 @@ impl MsgType {
|
||||
7 => MsgType::MatchState,
|
||||
8 => MsgType::ArmorDamageControl,
|
||||
9 => MsgType::ArmorReset,
|
||||
10 => MsgType::MatchResult,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
use crate::{decode_header, encode_header_into, Header, MsgType, HEADER_LEN, PROTOCOL_VERSION};
|
||||
|
||||
/// 自包含的裁判终局快照。独立消息保持原计时和装甲板许可格式兼容。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MatchResult {
|
||||
pub session: u64,
|
||||
pub sequence: u64,
|
||||
/// 首次结算时的序号;重发时不变,下一局严格递增。
|
||||
pub result_id: u64,
|
||||
pub remaining_ms: u32,
|
||||
pub elapsed_ms: u32,
|
||||
/// 队伍 0/1:0 未判定、1 胜、2 负、3 平局。
|
||||
pub outcomes: [u8; 2],
|
||||
}
|
||||
|
||||
impl MatchResult {
|
||||
pub fn valid(&self) -> bool {
|
||||
self.session != 0
|
||||
&& self.result_id != 0
|
||||
&& self.result_id <= self.sequence
|
||||
&& self.remaining_ms <= 180_000
|
||||
&& self.elapsed_ms <= 180_000
|
||||
&& matches!(self.outcomes, [1, 2] | [2, 1] | [2, 0] | [0, 2] | [3, 3])
|
||||
}
|
||||
pub fn encode(&self) -> Option<Vec<u8>> {
|
||||
if !self.valid() {
|
||||
return None;
|
||||
}
|
||||
let mut out = Vec::with_capacity(HEADER_LEN + 34);
|
||||
encode_header_into(
|
||||
&Header {
|
||||
msg_type: MsgType::MatchResult,
|
||||
version: PROTOCOL_VERSION,
|
||||
..Default::default()
|
||||
},
|
||||
&mut out,
|
||||
);
|
||||
out.extend(self.session.to_le_bytes());
|
||||
out.extend(self.sequence.to_le_bytes());
|
||||
out.extend(self.result_id.to_le_bytes());
|
||||
out.extend(self.remaining_ms.to_le_bytes());
|
||||
out.extend(self.elapsed_ms.to_le_bytes());
|
||||
out.extend(self.outcomes);
|
||||
Some(out)
|
||||
}
|
||||
pub fn decode(bytes: &[u8]) -> Option<Self> {
|
||||
let header = decode_header(bytes)?;
|
||||
if header.msg_type != MsgType::MatchResult
|
||||
|| header.sender_id != 0
|
||||
|| bytes.len() != HEADER_LEN + 34
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let p = &bytes[HEADER_LEN..];
|
||||
let result = Self {
|
||||
session: u64::from_le_bytes(p[0..8].try_into().ok()?),
|
||||
sequence: u64::from_le_bytes(p[8..16].try_into().ok()?),
|
||||
result_id: u64::from_le_bytes(p[16..24].try_into().ok()?),
|
||||
remaining_ms: u32::from_le_bytes(p[24..28].try_into().ok()?),
|
||||
elapsed_ms: u32::from_le_bytes(p[28..32].try_into().ok()?),
|
||||
outcomes: p[32..34].try_into().ok()?,
|
||||
};
|
||||
result.valid().then_some(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn exact_result_roundtrip_rejects_bad_identity_length_and_conclusions() {
|
||||
let result = MatchResult {
|
||||
session: 9,
|
||||
sequence: 20,
|
||||
result_id: 18,
|
||||
remaining_ms: 100_000,
|
||||
elapsed_ms: 80_000,
|
||||
outcomes: [2, 1],
|
||||
};
|
||||
let bytes = result.encode().unwrap();
|
||||
assert_eq!(bytes.len(), 61);
|
||||
let hex = bytes
|
||||
.iter()
|
||||
.map(|byte| format!("{byte:02x}"))
|
||||
.collect::<String>();
|
||||
assert_eq!(
|
||||
hex,
|
||||
concat!(
|
||||
"3143564d0a0100",
|
||||
"0000000000000000000000000000000000000000",
|
||||
"0900000000000000",
|
||||
"1400000000000000",
|
||||
"1200000000000000",
|
||||
"a0860100",
|
||||
"80380100",
|
||||
"0201"
|
||||
)
|
||||
);
|
||||
assert_eq!(MatchResult::decode(&bytes), Some(result));
|
||||
assert!(crate::MatchState::decode(&bytes).is_none());
|
||||
assert!(crate::ArmorHealth::decode_from(&bytes).is_none());
|
||||
for n in 0..bytes.len() {
|
||||
assert!(MatchResult::decode(&bytes[..n]).is_none());
|
||||
}
|
||||
let mut extra = bytes.clone();
|
||||
extra.push(0);
|
||||
assert!(MatchResult::decode(&extra).is_none());
|
||||
for (offset, value) in [(4, 7), (5, 99), (7, 1), (HEADER_LEN + 33, 4)] {
|
||||
let mut bad = bytes.clone();
|
||||
bad[offset] = value;
|
||||
assert!(MatchResult::decode(&bad).is_none());
|
||||
}
|
||||
for outcomes in [[1, 1], [0, 1], [2, 2], [3, 0], [0, 0]] {
|
||||
assert!(MatchResult { outcomes, ..result }.encode().is_none());
|
||||
}
|
||||
assert!(MatchResult {
|
||||
result_id: 21,
|
||||
..result
|
||||
}
|
||||
.encode()
|
||||
.is_none());
|
||||
assert!(MatchResult {
|
||||
elapsed_ms: 180_001,
|
||||
..result
|
||||
}
|
||||
.encode()
|
||||
.is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user