class Rosegold::ChatManager

Overview

Manages chat message signing, salt generation, and acknowledgment tracking according to the Minecraft 1.21.8 protocol requirements.

Defined in:

rosegold/chat_manager.cr

Constant Summary

MAX_LAST_SEEN_MESSAGES = 20
SIGNATURE_SIZE = 256

Constructors

Instance Method Summary

Constructor Detail

def self.new(client : Client) #

[View source]

Instance Method Detail

def acknowledgment : Acknowledgment #

[View source]
def add_last_seen_signature(signature : Bytes) #

Track a received signed chat message like vanilla's LastSeenMessagesTracker: a repeat of the previous signature is ignored, otherwise it takes the newest slot of the 20-entry window and counts toward the next acknowledgment offset. Every tracked message is treated as shown.


[View source]
def increment_message_count #

Increment message count (used when receiving messages from server)


[View source]
def public_key_bytes : Bytes | Nil #

Get public key bytes for server authentication (if needed)


[View source]
def reset_session #

Reset chat session (useful for reconnections)


[View source]
def send_chat(message : String, session : Client::PlaySession | Nil = nil, authorized : -> Bool | Nil = nil) : Bool #

Send chat message or command, automatically determining the correct method based on the message content and protocol version. With session, it is written only while that PLAY session is still current, and with authorized only while it approves under the write lock.


[View source]
def send_command(command : String, session : Client::PlaySession | Nil = nil, authorized : -> Bool | Nil = nil) : Bool #

Send a command with proper signing. With session, it is written only while that PLAY session is still current, and with authorized only while it approves under the write lock.


[View source]
def send_message(message : String, session : Client::PlaySession | Nil = nil, authorized : -> Bool | Nil = nil) : Bool #

Send a regular chat message with proper signing and acknowledgment. With session, it is written only while that PLAY session is still current, and with authorized only while it approves under the write lock.


[View source]
def try_send_command(command : String, & : -> Bool) : SendResult #

Single-attempt slash command through the native ChatCommand packet, with the same Busy/Refused/Sent contract as #try_send_message. command is the full typed text including its leading '/'. Runs with the bot's own server permissions; the server decides whether the command is allowed. Delivery after a raised failure is unknown and must not be retried.


[View source]
def try_send_message(message : String, & : -> Bool) : SendResult #

Single-attempt chat send for callers that must not queue stale text. Returns Busy when another writer is active and Refused when the text is invalid or guard (run under the write lock) declines; signing state advances only on Sent. Raises NotConnected or an IO error without retrying, so delivery after a failure is unknown.


[View source]