communication

package
v0.0.0-...-a10a6d9 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeSay   = message.MessageTypeCustom + 1
	MessageTypeShout = message.MessageTypeCustom + 2
	MessageTypeEmote = message.MessageTypeCustom + 3
	MessageTypeTell  = message.MessageTypeCustom + 4
)

Message types for world communication

Variables

This section is empty.

Functions

func CreateEmoteMessage

func CreateEmoteMessage(playerID, playerName, action string) *message.Message

CreateEmoteMessage creates an emote message

func CreateSayMessage

func CreateSayMessage(playerID, playerName, text string) *message.Message

CreateSayMessage creates a say message

func CreateShoutMessage

func CreateShoutMessage(playerID, playerName, text string) *message.Message

CreateShoutMessage creates a shout message

func CreateTellMessage

func CreateTellMessage(senderID, senderName, targetID, targetName, text string) *message.Message

CreateTellMessage creates a tell message

func FormatCommunicationMessage

func FormatCommunicationMessage(msg *message.Message) (string, error)

FormatCommunicationMessage formats a communication message for display

Types

type Channel

type Channel struct {
	ID         string
	Name       string
	Type       string          // "room", "world", "global", "private"
	WorldID    string          // For world-specific channels
	RoomID     string          // For room-specific channels
	Members    map[string]bool // playerID -> active
	CreatedAt  time.Time
	Properties map[string]interface{}
}

Channel represents a communication channel

type CommunicationBuilder

type CommunicationBuilder struct {
	// contains filtered or unexported fields
}

CommunicationBuilder provides a fluent API for building communication messages

func Emote

func Emote() *CommunicationBuilder

Emote creates an "emote" message builder

func NewCommunicationMessage

func NewCommunicationMessage(messageType int64) *CommunicationBuilder

NewCommunicationMessage creates a new communication message builder

func Say

func Say() *CommunicationBuilder

Say creates a "say" message builder

func Shout

func Shout() *CommunicationBuilder

Shout creates a "shout" message builder

func Tell

func Tell() *CommunicationBuilder

Tell creates a "tell" message builder

func (*CommunicationBuilder) Build

func (b *CommunicationBuilder) Build() *message.Message

Build returns the constructed message

func (*CommunicationBuilder) FromPlayer

func (b *CommunicationBuilder) FromPlayer(playerID, playerName string) *CommunicationBuilder

FromPlayer sets the sender information

func (*CommunicationBuilder) InRoom

func (b *CommunicationBuilder) InRoom(worldID, roomID string) *CommunicationBuilder

InRoom sets the room context

func (*CommunicationBuilder) RequireAck

func (b *CommunicationBuilder) RequireAck(timeout time.Duration) *CommunicationBuilder

RequireAck enables acknowledgment requirement

func (*CommunicationBuilder) ToPlayer

func (b *CommunicationBuilder) ToPlayer(playerID, playerName string) *CommunicationBuilder

ToPlayer sets the target player for tells

func (*CommunicationBuilder) WithText

WithText sets the message text

func (*CommunicationBuilder) WithTimestamp

func (b *CommunicationBuilder) WithTimestamp(timestamp time.Time) *CommunicationBuilder

WithTimestamp sets the timestamp

type CommunicationData

type CommunicationData struct {
	Message    string `cbor:"message"`
	SenderID   string `cbor:"sender_id"`
	SenderName string `cbor:"sender_name"`
	RoomID     string `cbor:"room_id,omitempty"`
	WorldID    string `cbor:"world_id,omitempty"`
	TargetID   string `cbor:"target_id,omitempty"`   // For tells
	TargetName string `cbor:"target_name,omitempty"` // For tells
	Timestamp  int64  `cbor:"timestamp"`
}

CommunicationData represents the data structure for communication messages

func ParseCommunicationMessage

func ParseCommunicationMessage(msg *message.Message) (*CommunicationData, error)

ParseCommunicationMessage parses a communication message

type CommunicationManager

type CommunicationManager struct {
	// contains filtered or unexported fields
}

CommunicationManager handles world-aware communication

func NewCommunicationManager

func NewCommunicationManager(storageManager *storage.Manager, eventManager events.EventManager) *CommunicationManager

NewCommunicationManager creates a new communication manager

func (*CommunicationManager) CreateChannel

func (cm *CommunicationManager) CreateChannel(id, name, channelType string) *Channel

CreateChannel creates a new communication channel

func (*CommunicationManager) FilterMessage

func (cm *CommunicationManager) FilterMessage(msg *message.Message, recipientID string) (*message.Message, error)

FilterMessage filters messages based on player permissions or settings

func (*CommunicationManager) GetChannel

func (cm *CommunicationManager) GetChannel(id string) (*Channel, bool)

GetChannel returns a channel by ID

func (*CommunicationManager) GetChannelMembers

func (cm *CommunicationManager) GetChannelMembers(channelID string) []string

GetChannelMembers returns all members of a channel

func (*CommunicationManager) GetMessageHistory

func (cm *CommunicationManager) GetMessageHistory(contextType, contextID string, limit int) ([]*message.Message, error)

GetMessageHistory returns recent messages for a specific context

func (*CommunicationManager) GetPlayerLocation

func (cm *CommunicationManager) GetPlayerLocation(playerID string) (PlayerLocation, bool)

GetPlayerLocation returns a player's current location

func (*CommunicationManager) GetPlayersInRoom

func (cm *CommunicationManager) GetPlayersInRoom(worldID, roomID string) []string

GetPlayersInRoom returns all players in the specified room

func (*CommunicationManager) GetPlayersInWorld

func (cm *CommunicationManager) GetPlayersInWorld(worldID string) []string

GetPlayersInWorld returns all players in the specified world

func (*CommunicationManager) HandleMessage

func (cm *CommunicationManager) HandleMessage(msg *message.Message, senderID string) error

HandleMessage processes a communication message

func (*CommunicationManager) JoinChannel

func (cm *CommunicationManager) JoinChannel(channelID, playerID string) error

JoinChannel adds a player to a channel

func (*CommunicationManager) LeaveChannel

func (cm *CommunicationManager) LeaveChannel(channelID, playerID string) error

LeaveChannel removes a player from a channel

func (*CommunicationManager) RegisterMessageHandler

func (cm *CommunicationManager) RegisterMessageHandler(messageType int64, handler func(*message.Message, string) error)

RegisterMessageHandler registers a custom message handler

func (*CommunicationManager) RemovePlayerLocation

func (cm *CommunicationManager) RemovePlayerLocation(playerID string)

RemovePlayerLocation removes a player's location (when they disconnect)

func (*CommunicationManager) SendToChannel

func (cm *CommunicationManager) SendToChannel(channelID string, msg *message.Message) error

SendToChannel sends a message to all members of a channel

func (*CommunicationManager) SendToPlayer

func (cm *CommunicationManager) SendToPlayer(playerID string, msg *message.Message) error

SendToPlayer sends a message to a specific player

func (*CommunicationManager) SendToRoom

func (cm *CommunicationManager) SendToRoom(worldID, roomID string, msg *message.Message) error

SendToRoom sends a message to all players in a room

func (*CommunicationManager) SendToWorld

func (cm *CommunicationManager) SendToWorld(worldID string, msg *message.Message) error

SendToWorld sends a message to all players in a world

func (*CommunicationManager) UpdatePlayerLocation

func (cm *CommunicationManager) UpdatePlayerLocation(playerID, worldID, roomID string)

UpdatePlayerLocation updates a player's location

func (*CommunicationManager) ValidateMessage

func (cm *CommunicationManager) ValidateMessage(msg *message.Message, senderID string) error

ValidateMessage validates a message before processing

type PlayerLocation

type PlayerLocation struct {
	PlayerID  string
	WorldID   string
	RoomID    string
	UpdatedAt time.Time
}

PlayerLocation tracks where a player is located

Jump to

Keyboard shortcuts

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