pub struct JavaConnection {
outgoing_packets: UnboundedSender<OutboundPacket>,
cancel_token: CancellationToken,
compression: Option<CompressionInfo>,
network_writer: JavaNetworkWriter,
id: u64,
player: Weak<Player>,
keep_alive_tracker: SyncMutex<KeepAliveTracker>,
latency: SyncMutex<u32>,
}Expand description
A connection to a Java client.
Fields§
§outgoing_packets: UnboundedSender<OutboundPacket>§cancel_token: CancellationToken§compression: Option<CompressionInfo>§network_writer: JavaNetworkWriter§id: u64§player: Weak<Player>§keep_alive_tracker: SyncMutex<KeepAliveTracker>§latency: SyncMutex<u32>Implementations§
Source§impl JavaConnection
impl JavaConnection
Sourcepub const fn new(
outgoing_packets: UnboundedSender<OutboundPacket>,
cancel_token: CancellationToken,
compression: Option<CompressionInfo>,
network_writer: JavaNetworkWriter,
id: u64,
player: Weak<Player>,
) -> Self
pub const fn new( outgoing_packets: UnboundedSender<OutboundPacket>, cancel_token: CancellationToken, compression: Option<CompressionInfo>, network_writer: JavaNetworkWriter, id: u64, player: Weak<Player>, ) -> Self
Creates a new JavaConnection.
async fn write_packet_now( &self, packet: &EncodedPacket, ) -> Result<(), PacketError>
async fn release_network_writer(&self)
fn keep_connection_alive(&self)
Sourcefn handle_keep_alive(&self, packet: SKeepAlive)
fn handle_keep_alive(&self, packet: SKeepAlive)
Handles a keep alive packet.
Sourcepub fn latency(&self) -> i32
pub fn latency(&self) -> i32
Returns the current latency in milliseconds. This is a smoothed average calculated from keep-alive round-trip times.
Sourcepub fn disconnect(&self, reason: impl Into<TextComponent>)
pub fn disconnect(&self, reason: impl Into<TextComponent>)
Disconnects the client.
Sourcepub fn send_packet<P: ClientPacket>(&self, packet: P)
pub fn send_packet<P: ClientPacket>(&self, packet: P)
Sends a packet to the client.
§Panics
- If the packet fails to be encoded.
- If the packet fails to be sent through the channel.
Sourcepub fn send_encoded_packet(&self, packet: EncodedPacket)
pub fn send_encoded_packet(&self, packet: EncodedPacket)
Sourcepub async fn wait_for_close(&self)
pub async fn wait_for_close(&self)
Waits for the connection to be closed.
const fn can_process_before_join(packet_id: i32) -> bool
const fn can_process_during_domain_handshake(packet_id: i32) -> bool
Sourcefn process_packet(
&self,
packet: RawPacket,
player: Arc<Player>,
server: &Server,
) -> Result<(), PacketError>
fn process_packet( &self, packet: RawPacket, player: Arc<Player>, server: &Server, ) -> Result<(), PacketError>
Decodes and dispatches one packet received from the client.
fn decode_domain_gated_packet( packet: RawPacket, player: &Player, ) -> Result<Option<DecodedPlayPacket>, PacketError>
fn decode_play_packet( packet: RawPacket, ) -> Result<DecodedPlayPacket, PacketError>
fn handle_immediate_packet(&self, packet: ImmediatePlayPacket, player: &Player)
Sourcepub async fn listener(
&self,
reader: TCPNetworkDecoder<BufReader<OwnedReadHalf>>,
server: Arc<Server>,
)
pub async fn listener( &self, reader: TCPNetworkDecoder<BufReader<OwnedReadHalf>>, server: Arc<Server>, )
Listens for packets from the client.
Sourcepub async fn sender(&self, sender_recv: UnboundedReceiver<OutboundPacket>)
pub async fn sender(&self, sender_recv: UnboundedReceiver<OutboundPacket>)
Sends packets to the client.
async fn write_queued_disconnect( &self, sender_recv: &mut UnboundedReceiver<OutboundPacket>, )
Trait Implementations§
Source§impl From<JavaConnection> for PlayerConnection
impl From<JavaConnection> for PlayerConnection
Source§fn from(v: JavaConnection) -> PlayerConnection
fn from(v: JavaConnection) -> PlayerConnection
Converts to this type from the input type.
Source§impl NetworkConnection for JavaConnection
impl NetworkConnection for JavaConnection
Source§fn compression(&self) -> Option<CompressionInfo>
fn compression(&self) -> Option<CompressionInfo>
Returns compression info for packet encoding. Read more
Source§fn send_encoded(&self, packet: EncodedPacket)
fn send_encoded(&self, packet: EncodedPacket)
Sends a pre-encoded packet. Read more
Source§fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
Sends multiple pre-encoded packets as an atomic bundle. Read more
Source§fn disconnect_with_reason(&self, reason: TextComponent)
fn disconnect_with_reason(&self, reason: TextComponent)
Disconnects the player with a reason.
Source§impl TextResolutor for JavaConnection
impl TextResolutor for JavaConnection
fn resolve_content(&self, _resolvable: &Resolvable) -> TextComponent
fn resolve_custom(&self, _data: &CustomData) -> Option<TextComponent>
fn translate(&self, _key: &str) -> Option<String>
fn resolve_other(&self, content: &Content) -> TextComponent
fn split_translation(&self, text: String) -> Vec<(String, usize)>
Source§impl TryInto<JavaConnection> for PlayerConnection
impl TryInto<JavaConnection> for PlayerConnection
Auto Trait Implementations§
impl !Freeze for JavaConnection
impl !RefUnwindSafe for JavaConnection
impl !UnwindSafe for JavaConnection
impl Send for JavaConnection
impl Sync for JavaConnection
impl Unpin for JavaConnection
impl UnsafeUnpin for JavaConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreWraps this value in an
Arc<SyncMutex<>>