class
Rosegold::Connection(InboundPacket, OutboundPacket)
- Rosegold::Connection(InboundPacket, OutboundPacket)
- Reference
- Object
Overview
Something that packets can be read from and sent to. Can be used for client and server. Caller of #read_packet must update #state= appropriately. Useless after disconnect; create a new instance to reconnect.
Defined in:
rosegold/packets/connection.crConstructors
Class Method Summary
-
.decode_clientbound_packet(packet_bytes : Bytes, protocol_state : ProtocolState, protocol_version : UInt32) : Clientbound::Packet
Protocol-aware packet decoding for clientbound packets
-
.decode_serverbound_packet(packet_bytes : Bytes, protocol_state : ProtocolState, protocol_version : UInt32) : Serverbound::Packet
Protocol-aware packet decoding for serverbound packets
Instance Method Summary
- #close_reason : TextComponent | Nil
- #close_reason=(close_reason : TextComponent | Nil)
- #closed?
- #compression_threshold : UInt32
- #compression_threshold=(compression_threshold : UInt32)
- #disconnect(reason : String)
- #handler : Rosegold::EventEmitter | Nil
- #handler=(handler : Rosegold::EventEmitter | Nil)
- #io : Minecraft::IO
- #io=(io : Minecraft::IO)
- #io=(io)
- #open?
-
#play_ended? : Bool
True once AcknowledgeConfiguration was written in the current PLAY session: no PLAY frame may follow it.
-
#play_session : UInt64
Identifies one PLAY session of this connection; entering PLAY again after a reconfiguration starts a new one, so writes queued earlier stay refused.
- #protocol_state : ProtocolState
- #protocol_state=(state : Rosegold::ProtocolState)
- #protocol_version : UInt32
- #read_packet : InboundPacket
- #read_raw_packet : Bytes
-
#send_packet(build : -> Bytes | -> Bytes | Nil, written : -> Nil, ready : -> Bool, settled : -> Nil | Nil = nil) : Bool
Builds the packet under the write lock so state captured by
buildcannot go stale behind another writer;writtenruns under the lock after the frame is written and is skipped if the write raises. - #send_packet(packet_bytes : Bytes, ends_play : Bool = false)
- #send_packet(packet : OutboundPacket)
-
#try_send_packet(packet : OutboundPacket, written : -> Nil | Nil = nil, & : -> Bool) : SendResult
Writes only if no other writer is active and the guard still approves while the write lock is held.
-
#writable? : Bool
Whether the connection is open and no write to it has failed.
Constructor Detail
Class Method Detail
Protocol-aware packet decoding for clientbound packets
Protocol-aware packet decoding for serverbound packets
Instance Method Detail
True once AcknowledgeConfiguration was written in the current PLAY session: no PLAY frame may follow it.
Identifies one PLAY session of this connection; entering PLAY again after a reconfiguration starts a new one, so writes queued earlier stay refused.
Builds the packet under the write lock so state captured by build cannot
go stale behind another writer; written runs under the lock after the
frame is written and is skipped if the write raises. An error from build
or written propagates without closing the connection; a write failure
closes it and raises, so delivery is unknown. ready is rechecked under the
lock. Returns false if ready declines, build returns nil, or either
callback leaves the connection closed or unusable. settled runs last
under the lock, even if a callback or the write raised.
Writes only if no other writer is active and the guard still approves while
the write lock is held. Never waits behind a queued writer and never retries.
A guard that raises refuses without closing the connection. A write failure
closes the connection and raises; delivery is then unknown. written runs
under the lock after a successful write.