Fix: kick in player state when client fails
This commit is contained in:
parent
033648bd94
commit
533357ceaa
@ -17,9 +17,10 @@ use crossbeam::atomic::AtomicCell;
|
|||||||
use mio::{event::Event, net::TcpStream, Token};
|
use mio::{event::Event, net::TcpStream, Token};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use pumpkin_config::compression::CompressionInfo;
|
use pumpkin_config::compression::CompressionInfo;
|
||||||
|
use pumpkin_core::text::TextComponent;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::{packet_id::Packet, DeserializerError},
|
bytebuf::{packet_id::Packet, DeserializerError},
|
||||||
client::{config::CConfigDisconnect, login::CLoginDisconnect},
|
client::{config::CConfigDisconnect, login::CLoginDisconnect, play::CPlayDisconnect},
|
||||||
packet_decoder::PacketDecoder,
|
packet_decoder::PacketDecoder,
|
||||||
packet_encoder::PacketEncoder,
|
packet_encoder::PacketEncoder,
|
||||||
server::{
|
server::{
|
||||||
@ -416,6 +417,11 @@ impl Client {
|
|||||||
self.try_send_packet(&CConfigDisconnect::new(reason))
|
self.try_send_packet(&CConfigDisconnect::new(reason))
|
||||||
.unwrap_or_else(|_| self.close());
|
.unwrap_or_else(|_| self.close());
|
||||||
}
|
}
|
||||||
|
// This way players get kicked when players using client functions (e.g. poll, send_packet)
|
||||||
|
ConnectionState::Play => {
|
||||||
|
self.try_send_packet(&CPlayDisconnect::new(&TextComponent::text(reason)))
|
||||||
|
.unwrap_or_else(|_| self.close());
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("Can't kick in {:?} State", self.connection_state)
|
log::warn!("Can't kick in {:?} State", self.connection_state)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ use pumpkin_protocol::{
|
|||||||
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround,
|
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround,
|
||||||
SSwingArm, SUseItem, SUseItemOn,
|
SSwingArm, SUseItem, SUseItemOn,
|
||||||
},
|
},
|
||||||
ConnectionState, RawPacket, ServerPacket, VarInt,
|
RawPacket, ServerPacket, VarInt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use pumpkin_protocol::server::play::{SCloseContainer, SKeepAlive};
|
use pumpkin_protocol::server::play::{SCloseContainer, SKeepAlive};
|
||||||
@ -215,7 +215,6 @@ impl Player {
|
|||||||
|
|
||||||
/// 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(&self, reason: TextComponent) {
|
pub fn kick(&self, reason: TextComponent) {
|
||||||
assert!(self.client.connection_state.load() == ConnectionState::Play);
|
|
||||||
assert!(!self
|
assert!(!self
|
||||||
.client
|
.client
|
||||||
.closed
|
.closed
|
||||||
|
|||||||
@ -234,7 +234,7 @@ fn main() -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
clients.insert(token, client);
|
clients.insert(token, client);
|
||||||
},
|
},
|
||||||
|
// Maybe received an event for a TCP connection.
|
||||||
token => {
|
token => {
|
||||||
// Poll Players
|
// Poll Players
|
||||||
if let Some(player) = players.get_mut(&token) {
|
if let Some(player) = players.get_mut(&token) {
|
||||||
@ -256,7 +256,6 @@ fn main() -> io::Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Poll current Clients (non players)
|
// Poll current Clients (non players)
|
||||||
// Maybe received an event for a TCP connection.
|
|
||||||
let (done, make_player) = if let Some(client) = clients.get_mut(&token) {
|
let (done, make_player) = if let Some(client) = clients.get_mut(&token) {
|
||||||
client.poll(event).await;
|
client.poll(event).await;
|
||||||
let closed = client.closed.load(std::sync::atomic::Ordering::Relaxed);
|
let closed = client.closed.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user