1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

don't panic if connection closes on join

This commit is contained in:
mat 2022-10-29 13:54:19 -05:00
parent 9de6c03dfb
commit f235c9d064

View file

@ -182,55 +182,48 @@ impl Client {
.await?; .await?;
let (conn, game_profile) = loop { let (conn, game_profile) = loop {
let packet_result = conn.read().await; let packet = conn.read().await?;
match packet_result { match packet {
Ok(packet) => match packet { ClientboundLoginPacket::Hello(p) => {
ClientboundLoginPacket::Hello(p) => { debug!("Got encryption request");
debug!("Got encryption request"); let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
if let Some(access_token) = &account.access_token { if let Some(access_token) = &account.access_token {
conn.authenticate( conn.authenticate(
access_token, access_token,
&account &account
.uuid .uuid
.expect("Uuid must be present if access token is present."), .expect("Uuid must be present if access token is present."),
e.secret_key, e.secret_key,
p, p,
)
.await?;
}
conn.write(
ServerboundKeyPacket {
nonce_or_salt_signature: NonceOrSaltSignature::Nonce(
e.encrypted_nonce,
),
key_bytes: e.encrypted_public_key,
}
.get(),
) )
.await?; .await?;
}
conn.set_encryption_key(e.secret_key); conn.write(
} ServerboundKeyPacket {
ClientboundLoginPacket::LoginCompression(p) => { nonce_or_salt_signature: NonceOrSaltSignature::Nonce(e.encrypted_nonce),
debug!("Got compression request {:?}", p.compression_threshold); key_bytes: e.encrypted_public_key,
conn.set_compression_threshold(p.compression_threshold); }
} .get(),
ClientboundLoginPacket::GameProfile(p) => { )
debug!("Got profile {:?}", p.game_profile); .await?;
break (conn.game(), p.game_profile);
} conn.set_encryption_key(e.secret_key);
ClientboundLoginPacket::LoginDisconnect(p) => { }
debug!("Got disconnect {:?}", p); ClientboundLoginPacket::LoginCompression(p) => {
} debug!("Got compression request {:?}", p.compression_threshold);
ClientboundLoginPacket::CustomQuery(p) => { conn.set_compression_threshold(p.compression_threshold);
debug!("Got custom query {:?}", p); }
} ClientboundLoginPacket::GameProfile(p) => {
}, debug!("Got profile {:?}", p.game_profile);
Err(e) => { break (conn.game(), p.game_profile);
panic!("Error: {e:?}"); }
ClientboundLoginPacket::LoginDisconnect(p) => {
debug!("Got disconnect {:?}", p);
}
ClientboundLoginPacket::CustomQuery(p) => {
debug!("Got custom query {:?}", p);
} }
} }
}; };