Documentation ¶
Index ¶
- Constants
- type Channel
- type Client
- type Message
- type Server
- func (s *Server) Broadcast(message *Message, targets []uint32)
- func (s *Server) BroadcastAll(message *Message)
- func (s *Server) BroadcastAllExclude(message *Message, exclude uint32)
- func (s *Server) BroadcastSingle(message *Message, target uint32)
- func (s *Server) PlayerOnline(id uint32) bool
- func (s *Server) Register(client *Client)
- func (s *Server) Unregister(client *Client)
Constants ¶
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 ¶
CreateClient will create and return a Client instance.
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 (*Server) BroadcastAll ¶
BroadcastAll will send the message to all clients.
func (*Server) BroadcastAllExclude ¶
BroadcastAllExclude will broadcast the message to every client except the specified one.
func (*Server) BroadcastSingle ¶
BroadcastSingle will send the message to the specified client.
func (*Server) PlayerOnline ¶
PlayerOnline will return true if the player has an active connection. Can be safely called from other goroutines.
func (*Server) Unregister ¶
Unregister removes the client from the server's client map.