class Rosegold::Connection(InboundPacket, OutboundPacket)

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(io : Minecraft::IO, protocol_state : Rosegold::ProtocolState, protocol_version : UInt32, handler : Rosegold::EventEmitter | Nil = nil) #

[View source]

Class Method Detail

def self.decode_clientbound_packet(packet_bytes : Bytes, protocol_state : ProtocolState, protocol_version : UInt32) : Clientbound::Packet #

Protocol-aware packet decoding for clientbound packets


[View source]
def self.decode_serverbound_packet(packet_bytes : Bytes, protocol_state : ProtocolState, protocol_version : UInt32) : Serverbound::Packet #

Protocol-aware packet decoding for serverbound packets


[View source]

Instance Method Detail

def close_reason : TextComponent | Nil #

[View source]
def close_reason=(close_reason : TextComponent | Nil) #

[View source]
def closed? #

[View source]
def compression_threshold : UInt32 #

[View source]
def compression_threshold=(compression_threshold : UInt32) #

[View source]
def disconnect(reason : String) #

[View source]
def handler : Rosegold::EventEmitter | Nil #

[View source]
def handler=(handler : Rosegold::EventEmitter | Nil) #

[View source]
def io : Minecraft::IO #

[View source]
def io=(io : Minecraft::IO) #

[View source]
def io=(io) #

[View source]
def open? #

[View source]
def play_ended? : Bool #

True once AcknowledgeConfiguration was written in the current PLAY session: no PLAY frame may follow it.


[View source]
def 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.


[View source]
def protocol_state : ProtocolState #

[View source]
def protocol_state=(state : Rosegold::ProtocolState) #

[View source]
def protocol_version : UInt32 #

[View source]
def read_packet : InboundPacket #

[View source]
def read_raw_packet : Bytes #

[View source]
def 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 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.


[View source]
def send_packet(packet_bytes : Bytes, ends_play : Bool = false) #

[View source]
def send_packet(packet : OutboundPacket) #

[View source]
def 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. 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.


[View source]
def writable? : Bool #

Whether the connection is open and no write to it has failed.


[View source]