chat

package
v0.0.0-...-9f1c46f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxChatHistory         = 1000
	MaxPendingAckPerPlayer = 100
)
View Source
const (
	SignatureVersion = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatChainStore

type ChatChainStore struct {
	PrivateKey     crypto.PrivateKey
	PublicKey      crypto.PublicKey
	SessionKey     []byte // Mojang signature
	KeyExpiry      time.Time
	PlayerUUID     ns.UUID
	SessionUUID    ns.UUID
	X509PublicKey  []byte
	PKCS1PublicKey []byte
	// contains filtered or unexported fields
}

func NewChatChainStore

func NewChatChainStore() *ChatChainStore

func (*ChatChainStore) AcknowledgeMessages

func (c *ChatChainStore) AcknowledgeMessages(playerUUID ns.UUID, signatures [][]byte)

func (*ChatChainStore) AddInboundMessage

func (c *ChatChainStore) AddInboundMessage(msg SignedMessage)

func (*ChatChainStore) AddOutboundMessage

func (c *ChatChainStore) AddOutboundMessage(msg SignedMessage) []byte

func (*ChatChainStore) AddPendingAck

func (c *ChatChainStore) AddPendingAck(playerUUID ns.UUID, msg SignedMessage) error

func (*ChatChainStore) AddPlayerPublicKey

func (c *ChatChainStore) AddPlayerPublicKey(playerUUID ns.UUID, publicKey *rsa.PublicKey)

func (*ChatChainStore) ClearPlayerState

func (c *ChatChainStore) ClearPlayerState(playerUUID ns.UUID)

func (*ChatChainStore) GetLastSeenMessages

func (c *ChatChainStore) GetLastSeenMessages(count int) []MessageRef

func (*ChatChainStore) GetLastSignature

func (c *ChatChainStore) GetLastSignature(playerUUID ns.UUID) []byte

func (*ChatChainStore) GetNextMessageIndex

func (c *ChatChainStore) GetNextMessageIndex() int32

func (*ChatChainStore) GetPendingAckCount

func (c *ChatChainStore) GetPendingAckCount(playerUUID ns.UUID) int

func (*ChatChainStore) GetPlayerPublicKey

func (c *ChatChainStore) GetPlayerPublicKey(playerUUID ns.UUID) *rsa.PublicKey

type ChatSessionData

type ChatSessionData struct {
	SessionID ns.UUID
	PublicKey *rsa.PublicKey
	KeyExpiry time.Time
	Signature []byte
}

type ChatSigner

type ChatSigner struct {
	ChatChainStore
	// contains filtered or unexported fields
}

func NewChatSigner

func NewChatSigner() *ChatSigner

func (*ChatSigner) CreateChatHeader

func (cs *ChatSigner) CreateChatHeader(msg SignedMessage) []byte

func (*ChatSigner) GenerateSessionData

func (cs *ChatSigner) GenerateSessionData() (*ChatSessionData, error)

func (*ChatSigner) LogSentMessageFromPeer

func (cs *ChatSigner) LogSentMessageFromPeer(playerUUID ns.UUID, msg SignedMessage) error

func (*ChatSigner) ProcessAcknowledgement

func (cs *ChatSigner) ProcessAcknowledgement(playerUUID ns.UUID, signatures [][]byte)

func (*ChatSigner) SetKeys

func (cs *ChatSigner) SetKeys(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey)

func (*ChatSigner) ShouldKickForPendingAcks

func (cs *ChatSigner) ShouldKickForPendingAcks(playerUUID ns.UUID) bool

func (*ChatSigner) SignMessage

func (cs *ChatSigner) SignMessage(message string, timestamp time.Time, salt int64, lastSeenMessages []MessageRef) (*SignedMessage, error)

func (*ChatSigner) VerifyChain

func (cs *ChatSigner) VerifyChain(playerUUID ns.UUID, currentSig []byte, previousSig []byte) bool

func (*ChatSigner) VerifyMessage

func (cs *ChatSigner) VerifyMessage(msg SignedMessage, publicKey *rsa.PublicKey) error

type MessageRef

type MessageRef struct {
	PlayerUUID ns.UUID
	Signature  []byte
}

type PlayerChatState

type PlayerChatState struct {
	UUID          ns.UUID
	PublicKey     *rsa.PublicKey
	LastSignature []byte
	MessageChain  []SignedMessage
	PendingAcks   []SignedMessage
}

type SignedMessage

type SignedMessage struct {
	PlayerUUID        ns.UUID
	Timestamp         time.Time
	Salt              int64
	MessageHash       []byte
	Signature         []byte
	PreviousSignature []byte
	LastSeenMessages  []MessageRef
	PlainMessage      string
	Acknowledged      bool
}

Jump to

Keyboard shortcuts

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