From 39ca508e7e2710166947bed5954eb8fc92de86d9 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 15 Oct 2025 21:51:37 +0200 Subject: replaytool: Send ready + show packet counter --- server/replaytool/src/record.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'server/replaytool') diff --git a/server/replaytool/src/record.rs b/server/replaytool/src/record.rs index 8c12fc94..c8bdc642 100644 --- a/server/replaytool/src/record.rs +++ b/server/replaytool/src/record.rs @@ -18,15 +18,19 @@ use anyhow::Context; use async_compression::tokio::write::ZstdEncoder; -use futures_util::StreamExt; -use hurrycurry_protocol::PacketC; +use futures_util::{SinkExt, StreamExt}; +use hurrycurry_protocol::{PacketC, PacketS}; use log::{debug, info}; -use std::{path::Path, time::Instant}; +use std::{ + io::{Write, stderr}, + path::Path, + time::Instant, +}; use tokio::{ fs::File, io::{AsyncWriteExt, BufWriter}, }; -use tokio_tungstenite::tungstenite; +use tokio_tungstenite::tungstenite::{self, Message}; use crate::Event; @@ -38,6 +42,7 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> { let (mut sock, _) = tokio_tungstenite::connect_async(url).await?; info!("starting recording."); let start = Instant::now(); + let mut counter = 0; while let Some(Ok(message)) = sock.next().await { match message { @@ -46,6 +51,14 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> { debug!("<- {packet:?}"); let is_end = matches!(packet, PacketC::SetIngame { state: false, .. }); + let is_start = matches!(packet, PacketC::SetIngame { state: true, .. }); + + if is_start { + sock.send(Message::Text( + serde_json::to_string(&PacketS::Ready).unwrap().into(), + )) + .await?; + } file.write_all( format!( @@ -60,6 +73,10 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> { ) .await?; + counter += 1; + eprint!("{counter} packets received\r"); + stderr().flush().unwrap(); + if is_end { info!("stopping replay..."); break; -- cgit v1.3