aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-29 13:54:19 -0500
committermat <github@matdoes.dev>2022-10-29 13:54:19 -0500
commitf235c9d064fbb2cc7d51a0c921ee632103dd9567 (patch)
tree67ac567dd158d8e7687ff12b0e865d5007b59b67
parent9de6c03dfbaa08890b1ec8322a97b7097d4a9d37 (diff)
downloadazalea-drasl-f235c9d064fbb2cc7d51a0c921ee632103dd9567.tar.xz
don't panic if connection closes on join
-rw-r--r--azalea-client/src/client.rs85
1 files changed, 39 insertions, 46 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 2ca92354..05461f0f 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -182,55 +182,48 @@ impl Client {
.await?;
let (conn, game_profile) = loop {
- let packet_result = conn.read().await;
- match packet_result {
- Ok(packet) => match packet {
- ClientboundLoginPacket::Hello(p) => {
- debug!("Got encryption request");
- let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
-
- if let Some(access_token) = &account.access_token {
- conn.authenticate(
- access_token,
- &account
- .uuid
- .expect("Uuid must be present if access token is present."),
- e.secret_key,
- p,
- )
- .await?;
- }
-
- conn.write(
- ServerboundKeyPacket {
- nonce_or_salt_signature: NonceOrSaltSignature::Nonce(
- e.encrypted_nonce,
- ),
- key_bytes: e.encrypted_public_key,
- }
- .get(),
+ let packet = conn.read().await?;
+ match packet {
+ ClientboundLoginPacket::Hello(p) => {
+ debug!("Got encryption request");
+ let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
+
+ if let Some(access_token) = &account.access_token {
+ conn.authenticate(
+ access_token,
+ &account
+ .uuid
+ .expect("Uuid must be present if access token is present."),
+ e.secret_key,
+ p,
)
.await?;
-
- conn.set_encryption_key(e.secret_key);
- }
- ClientboundLoginPacket::LoginCompression(p) => {
- debug!("Got compression request {:?}", p.compression_threshold);
- conn.set_compression_threshold(p.compression_threshold);
- }
- ClientboundLoginPacket::GameProfile(p) => {
- debug!("Got profile {:?}", p.game_profile);
- break (conn.game(), p.game_profile);
}
- ClientboundLoginPacket::LoginDisconnect(p) => {
- debug!("Got disconnect {:?}", p);
- }
- ClientboundLoginPacket::CustomQuery(p) => {
- debug!("Got custom query {:?}", p);
- }
- },
- Err(e) => {
- panic!("Error: {e:?}");
+
+ conn.write(
+ ServerboundKeyPacket {
+ nonce_or_salt_signature: NonceOrSaltSignature::Nonce(e.encrypted_nonce),
+ key_bytes: e.encrypted_public_key,
+ }
+ .get(),
+ )
+ .await?;
+
+ conn.set_encryption_key(e.secret_key);
+ }
+ ClientboundLoginPacket::LoginCompression(p) => {
+ debug!("Got compression request {:?}", p.compression_threshold);
+ conn.set_compression_threshold(p.compression_threshold);
+ }
+ ClientboundLoginPacket::GameProfile(p) => {
+ debug!("Got profile {:?}", p.game_profile);
+ break (conn.game(), p.game_profile);
+ }
+ ClientboundLoginPacket::LoginDisconnect(p) => {
+ debug!("Got disconnect {:?}", p);
+ }
+ ClientboundLoginPacket::CustomQuery(p) => {
+ debug!("Got custom query {:?}", p);
}
}
};