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",
|
"aes",
|
||||||
"bytes",
|
"bytes",
|
||||||
"cfb8",
|
"cfb8",
|
||||||
|
"fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@ -15,6 +15,9 @@ serde_json = "1.0"
|
|||||||
thiserror = "1.0.63"
|
thiserror = "1.0.63"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
|
# for text component
|
||||||
|
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
||||||
|
|
||||||
# encryption
|
# encryption
|
||||||
aes = "0.8.4"
|
aes = "0.8.4"
|
||||||
cfb8 = "0.8.1"
|
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 {
|
pub struct SetHeldItem {
|
||||||
slot: i8,
|
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 {
|
pub struct CChangeDifficulty {
|
||||||
difficulty: u8,
|
difficulty: u8,
|
||||||
locked: bool,
|
locked: bool,
|
||||||
|
|||||||
@ -12,7 +12,11 @@ use crate::{
|
|||||||
use mio::{event::Event, net::TcpStream, Token};
|
use mio::{event::Event, net::TcpStream, Token};
|
||||||
use player_packet::PlayerPacketProcessor;
|
use player_packet::PlayerPacketProcessor;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::{config::CConfigDisconnect, login::CLoginDisconnect},
|
client::{
|
||||||
|
config::CConfigDisconnect,
|
||||||
|
login::CLoginDisconnect,
|
||||||
|
play::{CPlayDisconnect, CSyncPlayerPostion},
|
||||||
|
},
|
||||||
packet_decoder::PacketDecoder,
|
packet_decoder::PacketDecoder,
|
||||||
packet_encoder::PacketEncoder,
|
packet_encoder::PacketEncoder,
|
||||||
server::{
|
server::{
|
||||||
@ -22,6 +26,7 @@ use pumpkin_protocol::{
|
|||||||
play::SConfirmTeleport,
|
play::SConfirmTeleport,
|
||||||
status::{SPingRequest, SStatusRequest},
|
status::{SPingRequest, SStatusRequest},
|
||||||
},
|
},
|
||||||
|
text::{Text},
|
||||||
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
|
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -118,6 +123,12 @@ impl Client {
|
|||||||
Ok(())
|
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) {
|
pub fn process_packets(&mut self, server: &mut Server) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < self.client_packets_queue.len() {
|
while i < self.client_packets_queue.len() {
|
||||||
@ -258,7 +269,7 @@ impl Client {
|
|||||||
|
|
||||||
/// Kicks the Client with a reason depending on the connection state
|
/// Kicks the Client with a reason depending on the connection state
|
||||||
pub fn kick(&mut self, reason: &str) {
|
pub fn kick(&mut self, reason: &str) {
|
||||||
// Todo
|
dbg!(reason);
|
||||||
match self.connection_state {
|
match self.connection_state {
|
||||||
ConnectionState::Login => {
|
ConnectionState::Login => {
|
||||||
self.send_packet(CLoginDisconnect::new(reason))
|
self.send_packet(CLoginDisconnect::new(reason))
|
||||||
@ -268,6 +279,12 @@ impl Client {
|
|||||||
self.send_packet(CConfigDisconnect::new(reason))
|
self.send_packet(CConfigDisconnect::new(reason))
|
||||||
.unwrap_or_else(|_| self.close());
|
.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)
|
log::warn!("Cant't kick in {:?} State", self.connection_state)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,7 +134,7 @@ impl Server {
|
|||||||
.send_packet(CGameEvent::new(13, 0.0))
|
.send_packet(CGameEvent::new(13, 0.0))
|
||||||
.unwrap_or_else(|e| client.kick(&e.to_string()));
|
.unwrap_or_else(|e| client.kick(&e.to_string()));
|
||||||
|
|
||||||
Server::spawn_test_chunk(client);
|
// Server::spawn_test_chunk(client);
|
||||||
|
|
||||||
client.player = Some(player);
|
client.player = Some(player);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user