Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Global = New()
Global represents a global chat. Players will write in this chat by default when they send any message in the chat.
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat represents the in-game chat. Messages may be written to it to send a message to all subscribers. The zero value of Chat is a chat ready to use. Methods on Chat may be called from multiple goroutines concurrently. Chat implements the io.Writer and io.StringWriter interfaces. fmt.Fprintf and fmt.Fprint may be used to write formatted messages to the chat.
func (*Chat) Subscribe ¶
func (chat *Chat) Subscribe(s Subscriber)
Subscribe adds a subscriber to the chat, sending it every message written to the chat. In order to remove it again, use Chat.Unsubscribe().
func (*Chat) Subscribed ¶ added in v0.2.0
func (chat *Chat) Subscribed(s Subscriber) bool
Subscribed checks if a subscriber is currently subscribed to the chat.
func (*Chat) Unsubscribe ¶
func (chat *Chat) Unsubscribe(s Subscriber)
Unsubscribe removes a subscriber from the chat, so that messages written to the chat will no longer be sent to it.
type StdoutSubscriber ¶
type StdoutSubscriber struct{}
StdoutSubscriber is an implementation of Subscriber that forwards messages sent to the chat to the stdout.
type Subscriber ¶
type Subscriber interface { // Message sends a formatted message to the subscriber. The message is formatted as it would when using // fmt.Println. Message(a ...any) }
Subscriber represents an entity that may subscribe to a Chat. In order to do so, the Subscriber must implement methods to send messages to it.