Add Clientbound Play Disconnect
This commit is contained in:
parent
a0d92fe45c
commit
30cdab5d09
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -665,6 +665,7 @@ dependencies = [
|
||||
"aes",
|
||||
"bytes",
|
||||
"cfb8",
|
||||
"fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@ -15,6 +15,9 @@ serde_json = "1.0"
|
||||
thiserror = "1.0.63"
|
||||
log = "0.4"
|
||||
|
||||
# for text component
|
||||
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
||||
|
||||
# encryption
|
||||
aes = "0.8.4"
|
||||
cfb8 = "0.8.1"
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::{bytebuf::ByteBuffer, BitSet, ClientPacket, VarInt};
|
||||
use crate::{bytebuf::ByteBuffer, text::Text, BitSet, ClientPacket, VarInt};
|
||||
|
||||
pub struct SetHeldItem {
|
||||
slot: i8,
|
||||
@ -44,6 +44,24 @@ impl ClientPacket for CPlayerAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CPlayDisconnect {
|
||||
reason: Text,
|
||||
}
|
||||
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: Text) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CPlayDisconnect {
|
||||
const PACKET_ID: VarInt = 0x1D;
|
||||
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.reason.encode());
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CChangeDifficulty {
|
||||
difficulty: u8,
|
||||
locked: bool,
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user