feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位
This commit is contained in:
39 files changed
+1094
-54
No files matched your search
@@ -200,6 +200,7 @@ pub struct ArmorHealthStore {
|
||||
assignments: Mutex<Vec<(u32, u8)>>,
|
||||
match_sink: Mutex<Option<MatchSink>>,
|
||||
damage_participants: Mutex<HashSet<u32>>,
|
||||
reset: Mutex<Option<crate::armor_reset::ArmorResetTracker>>,
|
||||
}
|
||||
|
||||
impl Default for ArmorHealthStore {
|
||||
@@ -217,6 +218,7 @@ impl ArmorHealthStore {
|
||||
assignments: Mutex::new(Vec::new()),
|
||||
match_sink: Mutex::new(None),
|
||||
damage_participants: Mutex::new(HashSet::new()),
|
||||
reset: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,6 +284,12 @@ impl ArmorHealthStore {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(packet) = protocol::ArmorReset::decode(bytes) {
|
||||
if let Some(reset) = self.reset.lock().expect("armor reset poisoned").as_mut() {
|
||||
reset.acknowledge(packet, addr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 同一个端口上可能有别的东西(图传板的心跳、别的协议),解不出来就当不是给
|
||||
// 我的,安静跳过。
|
||||
@@ -383,6 +391,9 @@ impl ArmorHealthStore {
|
||||
entry.last_seen = Instant::now();
|
||||
}
|
||||
|
||||
if let Some(reset) = self.reset.lock().expect("armor reset poisoned").as_mut() {
|
||||
reset.observe(&report);
|
||||
}
|
||||
let sink = self.sink.lock().expect("armor sink mutex poisoned").clone();
|
||||
if let Some(sink) = sink {
|
||||
sink(report);
|
||||
@@ -474,6 +485,55 @@ impl ArmorHealthStore {
|
||||
first_error.map_or(Ok(()), Err)
|
||||
}
|
||||
|
||||
pub fn begin_reset(
|
||||
&self,
|
||||
state: &protocol::MatchState,
|
||||
participants: [Option<u32>; 2],
|
||||
) -> Result<(), String> {
|
||||
let tracker =
|
||||
crate::armor_reset::ArmorResetTracker::new(state, participants, &self.boards())?;
|
||||
let mut reset = self.reset.lock().expect("armor reset poisoned");
|
||||
if reset.is_some() {
|
||||
return Err("正在复位装甲板,请等待结果".into());
|
||||
}
|
||||
*reset = Some(tracker);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reset_waiting(&self) -> Vec<u32> {
|
||||
self.reset
|
||||
.lock()
|
||||
.expect("armor reset poisoned")
|
||||
.as_ref()
|
||||
.map(|reset| reset.waiting())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn finish_reset(&self) {
|
||||
*self.reset.lock().expect("armor reset poisoned") = None;
|
||||
}
|
||||
|
||||
/// 与禁止扣血许可使用同一份序号;每次心跳最多向每块待确认主板发送一次。
|
||||
pub fn send_reset_controls(
|
||||
&self,
|
||||
socket: &UdpSocket,
|
||||
state: &protocol::MatchState,
|
||||
) -> std::io::Result<()> {
|
||||
let packets = {
|
||||
let mut reset = self.reset.lock().expect("armor reset poisoned");
|
||||
reset
|
||||
.as_mut()
|
||||
.map(|reset| reset.packets(state))
|
||||
.unwrap_or_default()
|
||||
};
|
||||
for (packet, addr) in packets {
|
||||
if let Some(bytes) = packet.encode() {
|
||||
socket.send_to(&bytes, addr)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send_controls(&self, socket: &UdpSocket) {
|
||||
let selected = self
|
||||
.assignments
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
//! 一次有界复位事务:固定目标,等待逐板回执及回执后的四路满血上报。
|
||||
use crate::armor::{ArmorBoard, ArmorReport};
|
||||
use protocol::{ArmorReset, MatchState};
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Target {
|
||||
id: u32,
|
||||
addr: SocketAddrV4,
|
||||
acknowledged: bool,
|
||||
full_plates: u8,
|
||||
sent_sequence: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ArmorResetTracker {
|
||||
session: u64,
|
||||
reset_id: u64,
|
||||
targets: Vec<Target>,
|
||||
}
|
||||
|
||||
impl ArmorResetTracker {
|
||||
pub fn new(
|
||||
state: &MatchState,
|
||||
participants: [Option<u32>; 2],
|
||||
boards: &[ArmorBoard],
|
||||
) -> Result<Self, String> {
|
||||
if state.phase != 6 || state.session == 0 || state.sequence == 0 {
|
||||
return Err("请先结束本局,再复位装甲板".into());
|
||||
}
|
||||
if participants[0].is_some() && participants[0] == participants[1] {
|
||||
return Err("两队不能使用同一块装甲板,请检查槽位".into());
|
||||
}
|
||||
let mut targets = Vec::new();
|
||||
for id in participants.into_iter().flatten() {
|
||||
let board = boards
|
||||
.iter()
|
||||
.find(|board| board.id == id && board.is_online())
|
||||
.ok_or_else(|| format!("装甲板 0x{id:08X} 离线,无法复位;请恢复连接后重试"))?;
|
||||
targets.push(Target {
|
||||
id,
|
||||
addr: board.addr,
|
||||
acknowledged: false,
|
||||
full_plates: 0,
|
||||
sent_sequence: 0,
|
||||
});
|
||||
}
|
||||
Ok(Self {
|
||||
session: state.session,
|
||||
reset_id: state.sequence,
|
||||
targets,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn packets(&mut self, state: &MatchState) -> Vec<(ArmorReset, SocketAddrV4)> {
|
||||
if state.phase != 6 || state.session != self.session || state.sequence < self.reset_id {
|
||||
return Vec::new();
|
||||
}
|
||||
self.targets
|
||||
.iter_mut()
|
||||
.filter(|target| !target.acknowledged)
|
||||
.map(|target| {
|
||||
target.sent_sequence = state.sequence;
|
||||
(
|
||||
ArmorReset {
|
||||
board_id: target.id,
|
||||
session: self.session,
|
||||
sequence: state.sequence,
|
||||
reset_id: self.reset_id,
|
||||
acknowledged: false,
|
||||
},
|
||||
target.addr,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn acknowledge(&mut self, packet: ArmorReset, from: SocketAddrV4) {
|
||||
if !packet.acknowledged
|
||||
|| packet.session != self.session
|
||||
|| packet.reset_id != self.reset_id
|
||||
{
|
||||
return;
|
||||
}
|
||||
if let Some(target) = self.targets.iter_mut().find(|target| {
|
||||
target.id == packet.board_id
|
||||
&& target.addr == from
|
||||
&& packet.sequence >= self.reset_id
|
||||
&& packet.sequence <= target.sent_sequence
|
||||
}) {
|
||||
target.acknowledged = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn observe(&mut self, report: &ArmorReport) {
|
||||
if let Some(target) = self.targets.iter_mut().find(|target| {
|
||||
target.id == report.board && target.addr == report.addr && target.acknowledged
|
||||
}) {
|
||||
if report.hp == 100 && report.index < 4 {
|
||||
target.full_plates |= 1 << report.index;
|
||||
} else {
|
||||
target.full_plates = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn waiting(&self) -> Vec<u32> {
|
||||
self.targets
|
||||
.iter()
|
||||
.filter(|target| !target.acknowledged || target.full_plates != 0b1111)
|
||||
.map(|target| target.id)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -438,6 +438,8 @@ pub struct Config {
|
||||
pub armor_id: Option<u32>,
|
||||
/// 左右镜像。摄像头装反了,出图左右颠倒,所以默认翻回来。
|
||||
pub mirror: bool,
|
||||
/// 上下镜像,与左右镜像独立;旧配置默认关闭。
|
||||
pub mirror_vertical: bool,
|
||||
/// 密码的 Argon2id PHC 字符串。`None` = 还没设过。
|
||||
///
|
||||
/// 只对用户端有意义([`Role::needs_password`])。
|
||||
@@ -463,6 +465,7 @@ impl Default for Config {
|
||||
camera_id: None,
|
||||
armor_id: None,
|
||||
mirror: true,
|
||||
mirror_vertical: false,
|
||||
password: None,
|
||||
hud: HudConfig::default(),
|
||||
referee: RefereeConfig::default(),
|
||||
@@ -607,6 +610,7 @@ const HEADER: &str = "\
|
||||
# cameraId : 图传板 id,由 MAC 派生,重启不变,所以绑定是稳的
|
||||
# armorId : 装甲板主板 id,同上
|
||||
# mirror : true = 左右镜像(摄像头装反了,默认)
|
||||
# mirrorVertical: true = 上下镜像(默认关闭,可与左右镜像组合)
|
||||
# password : Argon2id 哈希(仅 team 端)。这里没有明文,也恢复不出明文;
|
||||
# 忘了密码就删掉这一行,然后第一次启动会要求重新设置。
|
||||
#
|
||||
@@ -867,6 +871,14 @@ mod tests {
|
||||
assert!(!config.needs_password_setup(), "裁判端不设密码");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_configs_keep_their_orientation_without_vertical_mirroring() {
|
||||
let config = Config::parse("mirror = false\nteamNames = [\"红队\", \"蓝队\"]\n").unwrap();
|
||||
assert!(!config.mirror);
|
||||
assert!(!config.mirror_vertical);
|
||||
assert_eq!(config.team_names, ["红队", "蓝队"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_roundtrip_survives_every_field() {
|
||||
let mut config = Config::default();
|
||||
@@ -877,6 +889,7 @@ mod tests {
|
||||
config.camera_id = Some(0x3D4D_8A9A);
|
||||
config.armor_id = Some(0x00AB_CDEF);
|
||||
config.mirror = false;
|
||||
config.mirror_vertical = true;
|
||||
config.password = Some("$argon2id$v=19$m=19456,t=2,p=1$c2FsdA$aGFzaA".to_string());
|
||||
config.hud.crosshair.offset_x = -0.125;
|
||||
config.hud.crosshair.style = CrosshairStyle::CircleDot;
|
||||
@@ -894,6 +907,7 @@ mod tests {
|
||||
assert_eq!(back.camera_id, Some(0x3D4D_8A9A));
|
||||
assert_eq!(back.armor_id, Some(0x00AB_CDEF));
|
||||
assert!(!back.mirror);
|
||||
assert!(back.mirror_vertical);
|
||||
assert_eq!(back.password, config.password);
|
||||
assert_eq!(back.hud.crosshair.offset_x, -0.125);
|
||||
assert_eq!(back.hud.crosshair.style, CrosshairStyle::CircleDot);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
//! 那两处要的是当前状态,不是每一帧。
|
||||
|
||||
pub mod armor;
|
||||
pub mod armor_reset;
|
||||
pub mod config;
|
||||
pub mod match_clock;
|
||||
pub mod password;
|
||||
|
||||
@@ -10,6 +10,7 @@ pub const SYNC_LEASE_MS: u64 = 1500;
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
pub enum MatchAction {
|
||||
Prepare,
|
||||
SkipPreparation,
|
||||
Countdown {
|
||||
seconds: u32,
|
||||
},
|
||||
@@ -162,6 +163,10 @@ impl MatchClock {
|
||||
self.state.phase = 1;
|
||||
self.state.remaining_ms = 180_000;
|
||||
}
|
||||
MatchAction::SkipPreparation if matches!(self.state.phase, 1 | 2) => {
|
||||
self.state.phase = 2;
|
||||
self.state.remaining_ms = 0;
|
||||
}
|
||||
MatchAction::Countdown { seconds }
|
||||
if self.state.phase == 2 && (1..=60).contains(&seconds) =>
|
||||
{
|
||||
@@ -204,6 +209,20 @@ impl MatchClock {
|
||||
self.state.sequence = self.state.sequence.saturating_add(1);
|
||||
Ok(())
|
||||
}
|
||||
/// 装甲板复位期间保持结束状态,先停止扣血;确认满血后再 Reset 到未开始。
|
||||
pub fn begin_reset(&mut self, has_outcome: bool, now: u64) -> Result<MatchState, String> {
|
||||
if !self.authority {
|
||||
return Err("只有裁判端可以重置比赛".into());
|
||||
}
|
||||
self.advance(now);
|
||||
if !matches!(self.state.phase, 0 | 6) && !has_outcome {
|
||||
return Err("比赛尚未结束,请先结束本局再重置".into());
|
||||
}
|
||||
self.state.phase = 6;
|
||||
clear_pause(&mut self.state);
|
||||
self.state.sequence = self.state.sequence.saturating_add(1);
|
||||
Ok(self.state.clone())
|
||||
}
|
||||
fn pause(&mut self, kind: u8, team: u8, reason: String) -> Result<(), String> {
|
||||
if !(1..=4).contains(&self.state.phase) {
|
||||
return Err("当前阶段不能申请技术暂停".into());
|
||||
@@ -315,6 +334,71 @@ mod tests {
|
||||
assert_eq!((v.phase, v.elapsed_ms), ("finished", 180_000));
|
||||
}
|
||||
#[test]
|
||||
fn skip_preparation_waits_for_confirmation_and_syncs_without_changing_session() {
|
||||
let mut c = MatchClock::new(true, 44, 0);
|
||||
assert!(c.action(MatchAction::SkipPreparation, 0).is_err());
|
||||
c.action(MatchAction::Prepare, 0).unwrap();
|
||||
c.action(MatchAction::SkipPreparation, 1000).unwrap();
|
||||
let packet = c.broadcast(1000).unwrap();
|
||||
assert_eq!(
|
||||
(packet.phase, packet.remaining_ms, packet.elapsed_ms),
|
||||
(2, 0, 0)
|
||||
);
|
||||
let mut follower = MatchClock::new(false, 2, 0);
|
||||
assert!(follower.receive(packet.clone(), Ipv4Addr::LOCALHOST, 1000));
|
||||
assert_eq!(follower.view(1000).phase, "ready");
|
||||
assert!(follower.action(MatchAction::SkipPreparation, 1000).is_err());
|
||||
assert_eq!(c.view(200_000).phase, "ready");
|
||||
// 重复操作、准备刚好自然结束时均保持待开赛。
|
||||
c.action(MatchAction::SkipPreparation, 200_000).unwrap();
|
||||
c.action(MatchAction::Countdown { seconds: 5 }, 200_000)
|
||||
.unwrap();
|
||||
assert!(c.action(MatchAction::SkipPreparation, 201_000).is_err());
|
||||
assert_eq!(c.view(205_000).phase, "running");
|
||||
assert!(c.action(MatchAction::SkipPreparation, 205_000).is_err());
|
||||
let later = c.broadcast(205_000).unwrap();
|
||||
assert_eq!(later.session, packet.session);
|
||||
assert!(later.sequence > packet.sequence);
|
||||
assert!(follower.receive(later, Ipv4Addr::LOCALHOST, 205_000));
|
||||
assert!(!follower.receive(packet, Ipv4Addr::LOCALHOST, 205_000));
|
||||
assert_eq!(follower.view(205_000).phase, "running");
|
||||
}
|
||||
#[test]
|
||||
fn reset_after_a_verdict_stops_the_match_then_clears_all_round_state() {
|
||||
let mut c = MatchClock::new(true, 44, 0);
|
||||
ready(&mut c);
|
||||
c.action(MatchAction::Countdown { seconds: 1 }, 180_000)
|
||||
.unwrap();
|
||||
assert!(c.begin_reset(false, 185_000).is_err());
|
||||
c.action(
|
||||
MatchAction::PauseOfficial {
|
||||
reason: "检查".into(),
|
||||
},
|
||||
185_000,
|
||||
)
|
||||
.unwrap();
|
||||
let stopped = c.begin_reset(true, 186_000).unwrap();
|
||||
assert_eq!((stopped.phase, stopped.pause_kind), (6, 0));
|
||||
assert_eq!(c.view(190_000).elapsed_ms, 4000);
|
||||
c.action(MatchAction::Reset, 190_000).unwrap();
|
||||
let state = c.broadcast(190_000).unwrap();
|
||||
assert_eq!(
|
||||
(
|
||||
state.phase,
|
||||
state.remaining_ms,
|
||||
state.elapsed_ms,
|
||||
state.pause_elapsed_ms
|
||||
),
|
||||
(0, 0, 0, 0)
|
||||
);
|
||||
assert_eq!(state.resume_phase, 0);
|
||||
assert!(state.reason.is_empty());
|
||||
assert_eq!(state.session, stopped.session);
|
||||
assert!(state.sequence > stopped.sequence);
|
||||
assert!(state.valid());
|
||||
assert!(MatchClock::new(false, 1, 0).begin_reset(true, 0).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn pause_approval_freezes_time_and_expiry_never_resumes() {
|
||||
let mut c = MatchClock::new(true, 1, 0);
|
||||
c.action(MatchAction::Prepare, 0).unwrap();
|
||||
|
||||
@@ -389,6 +389,7 @@ pub struct Snapshot {
|
||||
pub role: Role,
|
||||
pub team: u8,
|
||||
pub mirrored: bool,
|
||||
pub mirrored_vertical: bool,
|
||||
/// 演示模式:画面与血量是本地合成的,不是场上的板子。界面必须把它显示出来,
|
||||
/// 否则截图与验收会被误读成真实链路。
|
||||
pub demo: bool,
|
||||
@@ -436,6 +437,7 @@ pub struct ConfigView {
|
||||
pub armor_id: Option<u32>,
|
||||
pub armor_id_text: Option<String>,
|
||||
pub mirror: bool,
|
||||
pub mirror_vertical: bool,
|
||||
pub password_set: bool,
|
||||
pub hud: HudView,
|
||||
pub recording_dir: String,
|
||||
@@ -465,6 +467,7 @@ impl From<&Config> for ConfigView {
|
||||
armor_id: config.armor_id,
|
||||
armor_id_text: config.armor_id.map(id_text),
|
||||
mirror: config.mirror,
|
||||
mirror_vertical: config.mirror_vertical,
|
||||
password_set: config.password.is_some(),
|
||||
hud: HudView {
|
||||
health: config.hud.health.clone(),
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
use cam_core::armor::{ArmorBoard, ArmorHealthStore, ArmorReport};
|
||||
use cam_core::armor_reset::ArmorResetTracker;
|
||||
use cam_core::match_clock::{MatchAction, MatchClock};
|
||||
use std::net::{Ipv4Addr, SocketAddrV4, UdpSocket};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn board(id: u32) -> ArmorBoard {
|
||||
ArmorBoard {
|
||||
id,
|
||||
addr: SocketAddrV4::new(Ipv4Addr::LOCALHOST, 41000 + id as u16),
|
||||
team: (id - 1) as u8,
|
||||
hp: 0,
|
||||
plates_seen: 15,
|
||||
last_seen: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_reset_needs_matching_ack_and_four_fresh_full_health_reports() {
|
||||
let mut clock = MatchClock::new(true, 1, 0);
|
||||
let state = clock.begin_reset(true, 0).unwrap();
|
||||
let boards = [board(1), board(2)];
|
||||
let mut reset = ArmorResetTracker::new(&state, [Some(1), Some(2)], &boards).unwrap();
|
||||
let packets = reset.packets(&state);
|
||||
let (request, addr) = packets[0];
|
||||
let ack = protocol::ArmorReset {
|
||||
acknowledged: true,
|
||||
..request
|
||||
};
|
||||
let report = |index, hp| ArmorReport {
|
||||
board: 1,
|
||||
addr,
|
||||
team: 0,
|
||||
index,
|
||||
hp,
|
||||
};
|
||||
for index in 0..4 {
|
||||
reset.observe(&report(index, 100));
|
||||
}
|
||||
assert_eq!(reset.waiting(), [1, 2], "满血本身不能冒充复位回执");
|
||||
reset.acknowledge(ack, boards[1].addr);
|
||||
reset.acknowledge(protocol::ArmorReset { session: 2, ..ack }, addr);
|
||||
reset.acknowledge(protocol::ArmorReset { reset_id: 2, ..ack }, addr);
|
||||
reset.acknowledge(
|
||||
protocol::ArmorReset {
|
||||
sequence: state.sequence + 1,
|
||||
..ack
|
||||
},
|
||||
addr,
|
||||
);
|
||||
assert_eq!(reset.packets(&state).len(), 2);
|
||||
reset.acknowledge(ack, addr);
|
||||
for index in 0..3 {
|
||||
reset.observe(&report(index, 100));
|
||||
}
|
||||
assert_eq!(reset.waiting(), [1, 2]);
|
||||
reset.observe(&report(3, 0));
|
||||
reset.observe(&report(3, 100));
|
||||
assert_eq!(reset.waiting(), [1, 2], "非满血读数会清除这一轮确认");
|
||||
for index in 0..3 {
|
||||
reset.observe(&report(index, 100));
|
||||
}
|
||||
assert_eq!(reset.waiting(), [2], "一块完成不能掩盖另一块失败");
|
||||
assert_eq!(reset.packets(&state).len(), 1, "已回执的主板不再补血");
|
||||
assert!(ArmorResetTracker::new(&state, [Some(1), Some(1)], &boards).is_err());
|
||||
let mut offline = board(1);
|
||||
offline.last_seen -= Duration::from_secs(2);
|
||||
assert!(ArmorResetTracker::new(&state, [Some(1), None], &[offline]).is_err());
|
||||
clock.action(MatchAction::Reset, 0).unwrap();
|
||||
assert!(reset.packets(&clock.broadcast(0).unwrap()).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn udp_reset_retries_lost_request_and_waits_for_real_ack_and_health() {
|
||||
let client = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).unwrap();
|
||||
let board = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).unwrap();
|
||||
client
|
||||
.set_read_timeout(Some(Duration::from_secs(2)))
|
||||
.unwrap();
|
||||
board
|
||||
.set_read_timeout(Some(Duration::from_secs(2)))
|
||||
.unwrap();
|
||||
let store = ArmorHealthStore::new();
|
||||
store.datagram(
|
||||
&protocol::ArmorHealth {
|
||||
team: 0,
|
||||
index: 0,
|
||||
hp: 0,
|
||||
}
|
||||
.encode_from(17),
|
||||
board.local_addr().unwrap(),
|
||||
);
|
||||
let mut clock = MatchClock::new(true, 88, 0);
|
||||
let state = clock.begin_reset(true, 0).unwrap();
|
||||
store.begin_reset(&state, [Some(17), None]).unwrap();
|
||||
let mut bytes = [0; 128];
|
||||
// 首次请求丢失;下一次心跳使用新序号及相同 reset_id 重试。
|
||||
store.send_reset_controls(&client, &state).unwrap();
|
||||
let (n, _) = board.recv_from(&mut bytes).unwrap();
|
||||
let dropped = protocol::ArmorReset::decode(&bytes[..n]).unwrap();
|
||||
let later = clock.broadcast(200).unwrap();
|
||||
store
|
||||
.send_damage_controls(&client, &later, [Some(17), None])
|
||||
.unwrap();
|
||||
let (n, _) = board.recv_from(&mut bytes).unwrap();
|
||||
assert!(
|
||||
!protocol::ArmorDamageControl::decode(&bytes[..n])
|
||||
.unwrap()
|
||||
.enabled
|
||||
);
|
||||
store.send_reset_controls(&client, &later).unwrap();
|
||||
let (n, from) = board.recv_from(&mut bytes).unwrap();
|
||||
let request = protocol::ArmorReset::decode(&bytes[..n]).unwrap();
|
||||
assert_eq!(request.reset_id, dropped.reset_id);
|
||||
assert!(request.sequence > dropped.sequence);
|
||||
assert_eq!(store.reset_waiting(), [17]);
|
||||
let ack = protocol::ArmorReset {
|
||||
acknowledged: true,
|
||||
..request
|
||||
}
|
||||
.encode()
|
||||
.unwrap();
|
||||
board.send_to(&ack, from).unwrap();
|
||||
let (n, from) = client.recv_from(&mut bytes).unwrap();
|
||||
store.datagram(&bytes[..n], from);
|
||||
assert_eq!(store.reset_waiting(), [17]);
|
||||
assert_eq!(store.health_of_board(17), Some(0), "回执不能伪造血量");
|
||||
for index in 0..4 {
|
||||
board
|
||||
.send_to(
|
||||
&protocol::ArmorHealth {
|
||||
team: 0,
|
||||
index,
|
||||
hp: 100,
|
||||
}
|
||||
.encode_from(17),
|
||||
client.local_addr().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let (n, from) = client.recv_from(&mut bytes).unwrap();
|
||||
store.datagram(&bytes[..n], from);
|
||||
}
|
||||
assert!(store.reset_waiting().is_empty());
|
||||
assert_eq!(store.health_of_board(17), Some(100));
|
||||
store.finish_reset();
|
||||
}
|
||||
Reference in new issue
Block a user