aboutsummaryrefslogtreecommitdiff
path: root/server/replaytool
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-11-03 19:43:36 +0100
committermetamuffin <metamuffin@disroot.org>2025-11-03 19:43:36 +0100
commitca5a65a65f84d62ee01a1aed6b195a8c29d663cf (patch)
treed555d2d137cd5e940a734c88d6cc374aa4ccc1a3 /server/replaytool
parented525fec565b23a1ab5d1c03a7467f7838bab521 (diff)
downloadhurrycurry-ca5a65a65f84d62ee01a1aed6b195a8c29d663cf.tar
hurrycurry-ca5a65a65f84d62ee01a1aed6b195a8c29d663cf.tar.bz2
hurrycurry-ca5a65a65f84d62ee01a1aed6b195a8c29d663cf.tar.zst
implement keepalive in replaytool
Diffstat (limited to 'server/replaytool')
-rw-r--r--server/replaytool/src/record.rs18
-rw-r--r--server/replaytool/src/replay.rs1
2 files changed, 15 insertions, 4 deletions
diff --git a/server/replaytool/src/record.rs b/server/replaytool/src/record.rs
index c8bdc642..383d214d 100644
--- a/server/replaytool/src/record.rs
+++ b/server/replaytool/src/record.rs
@@ -16,11 +16,12 @@
*/
+use crate::Event;
use anyhow::Context;
use async_compression::tokio::write::ZstdEncoder;
use futures_util::{SinkExt, StreamExt};
use hurrycurry_protocol::{PacketC, PacketS};
-use log::{debug, info};
+use log::{debug, error, info};
use std::{
io::{Write, stderr},
path::Path,
@@ -32,8 +33,6 @@ use tokio::{
};
use tokio_tungstenite::tungstenite::{self, Message};
-use crate::Event;
-
pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> {
let mut file = BufWriter::new(ZstdEncoder::new(BufWriter::new(
File::create(&output).await?,
@@ -43,6 +42,7 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> {
info!("starting recording.");
let start = Instant::now();
let mut counter = 0;
+ let mut last_keepalive = Instant::now();
while let Some(Ok(message)) = sock.next().await {
match message {
@@ -59,6 +59,13 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> {
))
.await?;
}
+ if last_keepalive.elapsed().as_secs_f32() > 1. {
+ last_keepalive = Instant::now();
+ sock.send(Message::Text(
+ serde_json::to_string(&PacketS::Keepalive).unwrap().into(),
+ ))
+ .await?;
+ }
file.write_all(
format!(
@@ -82,7 +89,10 @@ pub async fn record(output: &Path, url: &str) -> anyhow::Result<()> {
break;
}
}
- tungstenite::Message::Close(_) => break,
+ tungstenite::Message::Close(_) => {
+ error!("connection closed by server");
+ break;
+ }
_ => (),
}
}
diff --git a/server/replaytool/src/replay.rs b/server/replaytool/src/replay.rs
index 958760ba..09c7e639 100644
--- a/server/replaytool/src/replay.rs
+++ b/server/replaytool/src/replay.rs
@@ -115,6 +115,7 @@ pub async fn replay(ws_listener: &TcpListener, input: &Path) -> Result<()> {
};
}
}
+ PacketS::Keepalive => (),
x => warn!("unhandled client packet: {x:?}"),
}
}