Added disconnect message

This commit is contained in:
Kyler 2023-12-19 19:48:42 -07:00
parent 50a4489499
commit 03d504f65f
2 changed files with 25 additions and 2 deletions

View File

@ -2,4 +2,21 @@
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
use crate::mc_types;
use crate::mc_types::{self, Result};
pub fn convert_clientbound_disconnect(reason: String) -> Vec<u8> {
let mut data: Vec<u8> = vec![0];
data.append(&mut &mut mc_types::convert_string(&reason));
data
}
pub async fn write_clientbound_disconnect(
stream: &mut OwnedWriteHalf,
reason: String,
) -> Result<()> {
mc_types::write_packet(
stream,
&mut convert_clientbound_disconnect(reason),
).await?;
Ok(())
}

View File

@ -97,7 +97,13 @@ async fn handle_client(client_socket: TcpStream) {
}
};
},
None => {}
None => {
login::write_clientbound_disconnect(
&mut client_writer,
"\"Server Error (Server may be starting)\"".to_string(),
).await.expect("Error sending disconnect on: \
Failed to connect to the backend server");
}
};
} else {
return;