pub struct PlayerSession {
id: PlayerSessionId,
current_player: SyncRwLock<CurrentPlayerSlot>,
pub(crate) chunk_sender: SyncMutex<ChunkSender>,
pub(crate) chat: SyncMutex<ChatState>,
pub(super) drop_spam_throttler: SyncMutex<TickThrottler>,
}Expand description
Connection-owned state that survives replacement of the active player entity.
Fields§
§id: PlayerSessionId§current_player: SyncRwLock<CurrentPlayerSlot>§chunk_sender: SyncMutex<ChunkSender>§chat: SyncMutex<ChatState>§drop_spam_throttler: SyncMutex<TickThrottler>Vanilla keeps creative drop throttling on the connection across respawns.
Implementations§
Source§impl PlayerSession
impl PlayerSession
Sourcepub fn new(
chat_spam_threshold_seconds: i32,
command_spam_threshold_seconds: i32,
) -> Self
pub fn new( chat_spam_threshold_seconds: i32, command_spam_threshold_seconds: i32, ) -> Self
Creates an unbound session for a newly accepted client connection.
§Panics
Panics if the process exhausts the player-session ID space.
pub(crate) const fn id(&self) -> PlayerSessionId
pub(crate) const fn chunk_sender(&self) -> &SyncMutex<ChunkSender>
Sourcepub(crate) fn current_player(&self) -> Option<Arc<Player>>
pub(crate) fn current_player(&self) -> Option<Arc<Player>>
Returns the player entity currently controlled by this connection.
Sourcepub(crate) fn is_current_player(&self, player: &Arc<Player>) -> bool
pub(crate) fn is_current_player(&self, player: &Arc<Player>) -> bool
Returns whether player is the entity currently controlled by this session.
Sourcepub fn bind_initial_player(&self, player: &Arc<Player>) -> bool
pub fn bind_initial_player(&self, player: &Arc<Player>) -> bool
Binds the first player entity created for this connection.
Sourcepub(crate) fn replace_player(
&self,
expected: &Arc<Player>,
replacement: &Arc<Player>,
) -> bool
pub(crate) fn replace_player( &self, expected: &Arc<Player>, replacement: &Arc<Player>, ) -> bool
Rebinds the connection only if expected is still its active player entity.
Sourcepub(crate) fn clear_player(&self, expected: &Arc<Player>) -> bool
pub(crate) fn clear_player(&self, expected: &Arc<Player>) -> bool
Clears the active player only if expected still owns this connection.
fn owns(&self, player: &Player) -> bool
Auto Trait Implementations§
impl !Freeze for PlayerSession
impl !RefUnwindSafe for PlayerSession
impl !UnwindSafe for PlayerSession
impl Send for PlayerSession
impl Sync for PlayerSession
impl Unpin for PlayerSession
impl UnsafeUnpin for PlayerSession
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<>>