Add Clientbound Play Disconnect

This commit is contained in:
Snowiiii committed 2024-08-04 12:23:28 +02:00
1 parent a0d92fe45c
commit 30cdab5d09
5 files changed
+43 -4

No files matched your search

+19 -2
View File
@@ -12,7 +12,11 @@ use crate::{
use mio::{event::Event, net::TcpStream, Token};
use player_packet::PlayerPacketProcessor;
use pumpkin_protocol::{
client::{config::CConfigDisconnect, login::CLoginDisconnect},
client::{
config::CConfigDisconnect,
login::CLoginDisconnect,
play::{CPlayDisconnect, CSyncPlayerPostion},
},
packet_decoder::PacketDecoder,
packet_encoder::PacketEncoder,
server::{
@@ -22,6 +26,7 @@ use pumpkin_protocol::{
play::SConfirmTeleport,
status::{SPingRequest, SStatusRequest},
},
text::{Text},
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
};
@@ -118,6 +123,12 @@ impl Client {
Ok(())
}
pub fn teleport(&mut self) {
assert!(self.player.is_some());
self.send_packet(CSyncPlayerPostion::new(10.0, 10.0, 10.0, 10.0, 0.0, 0, 10))
.unwrap_or_else(|e| self.kick(&e.to_string()));
}
pub fn process_packets(&mut self, server: &mut Server) {
let mut i = 0;
while i < self.client_packets_queue.len() {
@@ -258,7 +269,7 @@ impl Client {
/// Kicks the Client with a reason depending on the connection state
pub fn kick(&mut self, reason: &str) {
// Todo
dbg!(reason);
match self.connection_state {
ConnectionState::Login => {
self.send_packet(CLoginDisconnect::new(reason))
@@ -268,6 +279,12 @@ impl Client {
self.send_packet(CConfigDisconnect::new(reason))
.unwrap_or_else(|_| self.close());
}
ConnectionState::Play => {
self.send_packet(CPlayDisconnect::new(Text {
text: reason.to_string(),
}))
.unwrap_or_else(|_| self.close());
}
_ => {
log::warn!("Cant't kick in {:?} State", self.connection_state)
}
+1 -1
View File
@@ -134,7 +134,7 @@ impl Server {
.send_packet(CGameEvent::new(13, 0.0))
.unwrap_or_else(|e| client.kick(&e.to_string()));
Server::spawn_test_chunk(client);
// Server::spawn_test_chunk(client);
client.player = Some(player);
}