ws

package
v0.0.0-...-56dc94b Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Chat channel for receiving chat messages.
	Chat = Channel(iota)
	// Position channel for sending player positions.
	Position
	// PlayerData channel for sending player data on login.
	PlayerData
	// Destination channel for receiving player destinations.
	Destination
	// PlayerConnected channel for sending player connected events.
	PlayerConnected
	// PlayerDisconnected channel for sending player disconnected events.
	PlayerDisconnected
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel uint16

Channel is used to determine how a WebSocket message will be handled.

type Client

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

Client represents a player's WebSocket connection.

func CreateClient

func CreateClient(id uint32, conn *websocket.Conn) *Client

CreateClient will create and return a Client instance.

func (*Client) ReadPump

func (c *Client) ReadPump(server *Server)

ReadPump will continually read data from the conn and add it to the server.incoming channel.

func (*Client) WritePump

func (c *Client) WritePump()

WritePump will receive data from the client.send channel and write it to the conn.

type Message

type Message struct {
	PlayerID uint32 // The player ID of the message sender.
	Channel  Channel
	Data     []byte
}

Message is used to easily parse data received and sent over the WebSocket connections.

type Server

type Server struct {
	Incoming chan *Message // Incoming data is sent to this channel.
	// contains filtered or unexported fields
}

Server tracks the clients

func CreateServer

func CreateServer() *Server

CreateServer will return a Server instance.

func (*Server) Broadcast

func (s *Server) Broadcast(message *Message, targets []uint32)

Broadcast will send the message to the given targets.

func (*Server) BroadcastAll

func (s *Server) BroadcastAll(message *Message)

BroadcastAll will send the message to all clients.

func (*Server) BroadcastAllExclude

func (s *Server) BroadcastAllExclude(message *Message, exclude uint32)

BroadcastAllExclude will broadcast the message to every client except the specified one.

func (*Server) BroadcastSingle

func (s *Server) BroadcastSingle(message *Message, target uint32)

BroadcastSingle will send the message to the specified client.

func (*Server) PlayerOnline

func (s *Server) PlayerOnline(id uint32) bool

PlayerOnline will return true if the player has an active connection. Can be safely called from other goroutines.

func (*Server) Register

func (s *Server) Register(client *Client)

Register adds the client to the server's client map.

func (*Server) Unregister

func (s *Server) Unregister(client *Client)

Unregister removes the client from the server's client map.

Jump to

Keyboard shortcuts

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