Use correct time for heartbeats

This commit is contained in:
Artemis Tosini 2024-08-28 02:17:58 +00:00
parent 07d4a5d9b4
commit a42b72d963
Signed by: artemist
GPG key ID: EE5227935FE3FF18
2 changed files with 21 additions and 6 deletions

View file

@ -182,7 +182,6 @@ impl Context {
let message = maybe_message.ok_or_eyre("Socket was closed while trying to recieve")?;
if let Err(err) = self.as_mut().handle_receive(message) {
log::warn!("Got error while processing message: {:?}", err);
}
}
@ -245,14 +244,17 @@ impl CMSession {
inner: inner_wrapped,
};
let session_cloned = session.clone();
tokio::spawn(async move { session_cloned.send_heartbeat_task().await });
Ok(session)
}
async fn send_heartbeat_task(mut self) -> eyre::Result<()> {
let mut interval = tokio::time::interval(time::Duration::from_secs(5));
pub fn begin_heartbeat(&self, interval: u32) {
log::debug!("Starting heartbeats every {} seconds", interval);
let cloned = self.clone();
tokio::spawn(async move { cloned.send_heartbeat_task(interval).await });
}
async fn send_heartbeat_task(mut self, interval_secs: u32) -> eyre::Result<()> {
let mut interval = tokio::time::interval(time::Duration::from_secs(interval_secs as u64));
loop {
interval.tick().await;
self.send_notification(EMsg::k_EMsgClientHeartBeat, CMsgClientHeartBeat::default())?

View file

@ -163,6 +163,19 @@ pub async fn main() -> eyre::Result<()> {
log::debug!("Got logon response: {:#x?}", response);
if response.body.eresult != Some(0x01) {
eyre::bail!("Login failed");
};
session.set_steam_id(response.header.steamid());
session.set_client_session_id(response.header.client_sessionid());
if let Some(heartbeat_seconds) = response.body.heartbeat_seconds {
if heartbeat_seconds >= 5 {
session.begin_heartbeat(heartbeat_seconds as u32);
}
}
Ok(())
}