diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-15 21:51:37 +0200 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-15 21:51:37 +0200 |
| commit | 39ca508e7e2710166947bed5954eb8fc92de86d9 (patch) | |
| tree | 7b8a58318f74d01b82e1f5b32c3a39f79c008434 /server/replaytool | |
| parent | 5da3f0278b3cc3a2024216117f9be67c674bcbd0 (diff) | |
| download | hurrycurry-39ca508e7e2710166947bed5954eb8fc92de86d9.tar hurrycurry-39ca508e7e2710166947bed5954eb8fc92de86d9.tar.bz2 hurrycurry-39ca508e7e2710166947bed5954eb8fc92de86d9.tar.zst | |
replaytool: Send ready + show packet counter
Diffstat (limited to 'server/replaytool')
| -rw-r--r-- | server/replaytool/src/record.rs | 25 |
1 files changed, 21 insertions, 4 deletions
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; |