Skip to content

Commit

Permalink
session: rework keepalive logic to match other clients
Browse files Browse the repository at this point in the history
  • Loading branch information
wisp3rwind committed Sep 30, 2024
1 parent 3781a08 commit a61f707
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ impl Session {

match packet_type {
Some(Ping) => {
info!("Received Ping");
let server_timestamp = BigEndian::read_u32(data.as_ref()) as i64;
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand All @@ -388,7 +389,23 @@ impl Session {
}

self.debug_info();
self.send_packet(Pong, vec![0, 0, 0, 0])
let session = self.weak();
tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
if let Some(session) = session.try_upgrade() {
info!("Sending Pong");
let _ = session.send_packet(Pong, vec![0, 0, 0, 0]);
}

// TODO: Wait for PongAck. Then, wait for next ping and use
// both events in the session timeout detection.
});

Ok(())
}
Some(PongAck) => {
info!("Received PongAck");
Ok(())
}
Some(CountryCode) => {
let country = String::from_utf8(data.as_ref().to_owned())?;
Expand Down Expand Up @@ -439,8 +456,7 @@ impl Session {
self.0.data.write().user_data.attributes = user_attributes;
Ok(())
}
Some(PongAck)
| Some(SecretBlock)
Some(SecretBlock)
| Some(LegacyWelcome)
| Some(UnknownDataAllZeros)
| Some(LicenseVersion) => Ok(()),
Expand Down

0 comments on commit a61f707

Please sign in to comment.