Use correct time for heartbeats
This commit is contained in:
parent
07d4a5d9b4
commit
a42b72d963
|
@ -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())?
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue