chat

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func New

func New() *Chat

New returns a new chat. A zero value is, however, usually sufficient for use.

func (*Chat) Close

func (chat *Chat) Close() error

Close closes the chat, removing all subscribers from it.

func (*Chat) Printf

func (chat *Chat) Printf(format string, a ...interface{})

Printf prints a formatted message using a specific format to the chat. The message is formatted according to the fmt.Sprintf formatting rules.

func (*Chat) Println

func (chat *Chat) Println(a ...interface{})

Println prints a formatted message to the chat. The message is formatted according to the fmt.Sprintln formatting rules.

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) 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.

func (*Chat) Write

func (chat *Chat) Write(p []byte) (n int, err error)

Write writes the byte slice p as a string to the chat. It is equivalent to calling Chat.WriteString(string(p)).

func (*Chat) WriteString

func (chat *Chat) WriteString(s string) (n int, err error)

WriteString writes a string s to the chat.

type StdoutSubscriber

type StdoutSubscriber struct{}

StdoutSubscriber is an implementation of Subscriber that forwards messages sent to the chat to the stdout.

func (StdoutSubscriber) Message

func (c StdoutSubscriber) Message(a ...interface{})

Message ...

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 ...interface{})
}

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.

Jump to

Keyboard shortcuts

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