chat

package
v0.39.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxPreviousMessageCount = 5
View Source
const (
	MaxServerBoundMessageLength = 256
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgumentSignature

type ArgumentSignature struct {
	Name      string
	Signature []byte
}

func (*ArgumentSignature) Decode

func (a *ArgumentSignature) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*ArgumentSignature) Encode

func (a *ArgumentSignature) Encode(c *proto.PacketContext, wr io.Writer) error

type ArgumentSignatures

type ArgumentSignatures struct {
	Entries []ArgumentSignature
}

func (*ArgumentSignatures) Decode

func (*ArgumentSignatures) Encode

type Builder

type Builder struct {
	// Protocol is the protocol version of the message.
	// If not set, defaults to supporting older clients.
	Protocol proto.Protocol
	// Component is the component to send to the client.
	// If nil, Message is used instead.
	Component component.Component
	Message   string // Only used if Component is nil
	// Type is the position the message is going to be sent.
	// If not set, defaults to ChatMessageType.
	Type MessageType
	// Sender is the UUID of the player who sent the message.
	// If zero (uuid.Nil), the message is sent by the server.
	Sender uuid.UUID
	// Timestamp is the time the message was sent.
	Timestamp time.Time
	// LastSeenMessages is the last seen messages state of the player.
	LastSeenMessages LastSeenMessages
}

Builder is a builder for protocol aware chat messages.

func (*Builder) ToClient

func (b *Builder) ToClient() proto.Packet

ToClient creates a packet which can be sent to the client; using the provided information in the builder.

func (*Builder) ToServer

func (b *Builder) ToServer() proto.Packet

ToServer creates a packet which can be sent to the server; using the provided information in the builder.

type ChatAcknowledgement added in v0.35.0

type ChatAcknowledgement struct {
	Offset int
}

func (*ChatAcknowledgement) Decode added in v0.35.0

func (c *ChatAcknowledgement) Decode(_ *proto.PacketContext, rd io.Reader) (err error)

func (*ChatAcknowledgement) Encode added in v0.35.0

type ComponentHolder added in v0.35.0

type ComponentHolder struct {
	Protocol  proto.Protocol
	Component component.Component
	JSON      json.RawMessage
	BinaryTag nbt.RawMessage
}

ComponentHolder holds a chat component that can be represented in different formats.

func FromComponent added in v0.35.0

func FromComponent(comp component.Component) *ComponentHolder

func FromComponentProtocol added in v0.35.0

func FromComponentProtocol(comp component.Component, protocol proto.Protocol) *ComponentHolder

func ReadComponentHolder added in v0.35.0

func ReadComponentHolder(rd io.Reader, protocol proto.Protocol) (*ComponentHolder, error)

ReadComponentHolder reads a ComponentHolder from the provided reader.

func ReadComponentHolderNP added in v0.35.0

func ReadComponentHolderNP(rd io.Reader, protocol proto.Protocol) (ComponentHolder, error)

ReadComponentHolderNP reads a ComponentHolder from the provided reader.

func (*ComponentHolder) AsBinaryTag added in v0.35.0

func (c *ComponentHolder) AsBinaryTag() (util.BinaryTag, error)

func (*ComponentHolder) AsComponent added in v0.35.0

func (c *ComponentHolder) AsComponent() (component.Component, error)

AsComponent returns the component as a component.Component.

func (*ComponentHolder) AsComponentOrNil added in v0.35.0

func (c *ComponentHolder) AsComponentOrNil() component.Component

func (*ComponentHolder) AsJson added in v0.35.0

func (c *ComponentHolder) AsJson() (json.RawMessage, error)

AsJson returns the component as a JSON raw message.

func (*ComponentHolder) AsJsonOrNil added in v0.35.0

func (c *ComponentHolder) AsJsonOrNil() json.RawMessage

func (*ComponentHolder) Write added in v0.35.0

func (c *ComponentHolder) Write(wr io.Writer, protocol proto.Protocol) error

Write writes the component holder to the writer.

type KeyedPlayerChat

type KeyedPlayerChat struct {
	Message          string
	SignedPreview    bool
	Unsigned         bool
	Expiry           time.Time // may be zero if no salt or signature specified
	Signature        []byte
	Salt             []byte
	PreviousMessages []*crypto.SignaturePair
	LastMessage      *crypto.SignaturePair
}

func (*KeyedPlayerChat) Decode

func (p *KeyedPlayerChat) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*KeyedPlayerChat) Encode

func (p *KeyedPlayerChat) Encode(c *proto.PacketContext, wr io.Writer) error

type KeyedPlayerCommand

type KeyedPlayerCommand struct {
	Unsigned         bool
	Command          string
	Timestamp        time.Time
	Salt             int64
	SignedPreview    bool // purely for pass through for 1.19 -> 1.19.2 - this will never be implemented
	Arguments        map[string][]byte
	PreviousMessages []*crypto.SignaturePair
	LastMessage      *crypto.SignaturePair
}

func NewKeyedPlayerCommand

func NewKeyedPlayerCommand(command string, arguments []string, timestamp time.Time) *KeyedPlayerCommand

NewKeyedPlayerCommand returns a new KeyedPlayerCommand packet based on a command and list of arguments.

func (*KeyedPlayerCommand) Decode

func (p *KeyedPlayerCommand) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*KeyedPlayerCommand) Encode

type LastSeenMessages

type LastSeenMessages struct {
	Offset       int
	Acknowledged mathutil.BitSet
}

func (*LastSeenMessages) Decode

func (l *LastSeenMessages) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*LastSeenMessages) Empty

func (l *LastSeenMessages) Empty() bool

func (*LastSeenMessages) Encode

func (l *LastSeenMessages) Encode(c *proto.PacketContext, wr io.Writer) error

type LegacyChat

type LegacyChat struct {
	Message string
	Type    MessageType
	Sender  uuid.UUID // 1.16+, and can be empty UUID, all zeros
}

func (*LegacyChat) Decode

func (ch *LegacyChat) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*LegacyChat) Encode

func (ch *LegacyChat) Encode(c *proto.PacketContext, wr io.Writer) error

type MessageType

type MessageType byte

MessageType is the position a chat message is going to be sent.

const (
	// ChatMessageType lets the chat message appear in the client's HUD.
	// These messages can be filtered out by the client's settings.
	ChatMessageType MessageType = iota
	// SystemMessageType lets the chat message appear in the client's HUD and can't be dismissed.
	SystemMessageType
	// GameInfoMessageType lets the chat message appear above the player's main HUD.
	// This text format doesn't support many component features, such as hover events.
	GameInfoMessageType
)

type RemoteChatSession

type RemoteChatSession struct {
	ID  uuid.UUID // may be zero
	Key crypto.IdentifiedKey
}

RemoteChatSession represents a remote chat session that is used to send messages.

func (*RemoteChatSession) Decode

func (r *RemoteChatSession) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*RemoteChatSession) Encode

func (r *RemoteChatSession) Encode(c *proto.PacketContext, wr io.Writer) error

func (*RemoteChatSession) IdentifiedKey

func (r *RemoteChatSession) IdentifiedKey() crypto.IdentifiedKey

func (*RemoteChatSession) SessionID

func (r *RemoteChatSession) SessionID() uuid.UUID

type SessionPlayerChat

type SessionPlayerChat struct {
	Message          string
	Timestamp        time.Time
	Salt             int64
	Signed           bool
	Signature        []byte
	LastSeenMessages LastSeenMessages
}

func (*SessionPlayerChat) Decode

func (p *SessionPlayerChat) Decode(c *proto.PacketContext, rd io.Reader) error

func (*SessionPlayerChat) Encode

func (p *SessionPlayerChat) Encode(c *proto.PacketContext, wr io.Writer) error

type SessionPlayerCommand

type SessionPlayerCommand struct {
	Command            string
	Timestamp          time.Time
	Salt               int64
	ArgumentSignatures ArgumentSignatures
	LastSeenMessages   LastSeenMessages
}

func (*SessionPlayerCommand) Decode

func (*SessionPlayerCommand) Encode

func (*SessionPlayerCommand) Signed

func (s *SessionPlayerCommand) Signed() bool

type SystemChat

type SystemChat struct {
	Component *ComponentHolder
	Type      MessageType
}

func (*SystemChat) Decode

func (p *SystemChat) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*SystemChat) Encode

func (p *SystemChat) Encode(c *proto.PacketContext, wr io.Writer) error

type UnsignedPlayerCommand added in v0.37.0

type UnsignedPlayerCommand struct {
	SessionPlayerCommand
}

func (*UnsignedPlayerCommand) Decode added in v0.37.0

func (u *UnsignedPlayerCommand) Decode(c *proto.PacketContext, rd io.Reader) (err error)

func (*UnsignedPlayerCommand) Encode added in v0.37.0

func (*UnsignedPlayerCommand) Signed added in v0.37.0

func (u *UnsignedPlayerCommand) Signed() bool

Signed always returns false as it is unsigned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL