Documentation
¶
Index ¶
- Variables
- type Connection
- func (c *Connection) Active() bool
- func (c *Connection) AwaitDirect(local string, target string) error
- func (c *Connection) AwaitHandshake(handshaker string, local string, target string) error
- func (c *Connection) AwaitLAN(joiner bool) error
- func (c *Connection) Close()
- func (c *Connection) Connected() bool
- func (c *Connection) Disconnected() bool
- func (c *Connection) Hosting() bool
- func (c *Connection) Loop()
- func (c *Connection) Messages() (m []Message)
- func (c *Connection) Send(msg Message) error
- func (c *Connection) SendReliable(msg Message) error
- type HandshakeMessage
- type HenloMessage
- type Message
- type PingMessage
- type ReliableTypedMessage
- type TravelMessage
- type TypedMessage
- type TypedMessageHandler
- type TypedMessageType
Constants ¶
This section is empty.
Variables ¶
var TypedMessageMap = make(map[TypedMessageType]TypedMessageHandler)
TypedMessageMap is a map of all defined types->TypedMessageHandlers
Functions ¶
This section is empty.
Types ¶
type Connection ¶
func NewConnection ¶
func NewConnection(name string) Connection
func (*Connection) Active ¶
func (c *Connection) Active() bool
Active returns if the connection should be connected.
func (*Connection) AwaitDirect ¶
func (c *Connection) AwaitDirect(local string, target string) error
AwaitDirect attempts to set up a client-to-client connection without any handshaking.
func (*Connection) AwaitHandshake ¶
func (c *Connection) AwaitHandshake(handshaker string, local string, target string) error
func (*Connection) AwaitLAN ¶
func (c *Connection) AwaitLAN(joiner bool) error
func (*Connection) Close ¶
func (c *Connection) Close()
func (*Connection) Connected ¶
func (c *Connection) Connected() bool
Connected returns if the connection is actually connected.
func (*Connection) Disconnected ¶
func (c *Connection) Disconnected() bool
Connected returns if the connection was disconnected.
func (*Connection) Hosting ¶
func (c *Connection) Hosting() bool
Hosting returns if the connection is acting as a host.
func (*Connection) Loop ¶
func (c *Connection) Loop()
func (*Connection) Messages ¶
func (c *Connection) Messages() (m []Message)
Messages returns the current contents of the messages channel as a slice.
func (*Connection) Send ¶
func (c *Connection) Send(msg Message) error
Send sends the given message interface to the other player.
func (*Connection) SendReliable ¶
func (c *Connection) SendReliable(msg Message) error
SendReliable sends the given message with special resending until a confirmation is received.
type HandshakeMessage ¶
type HandshakeMessage int
HandshakeMessage represents the type for the handshake step of networking.
const ( RegisterMessage HandshakeMessage = iota AwaitMessage ArrivedMessage HelloMessage HandshakerMessage BroadcastMessage )
These are our base types for handshaking.
type HenloMessage ¶
HenloMessage is our basic greeting message.
func (HenloMessage) Type ¶
func (m HenloMessage) Type() TypedMessageType
Type returns HenloMessage's corresponding type number.
type Message ¶
type Message interface {
Type() TypedMessageType
}
Message represents a message that can be sent as a typed message's data.
type PingMessage ¶
type PingMessage struct { }
PingMessage is used to send periodic pings.
func (PingMessage) Type ¶
func (m PingMessage) Type() TypedMessageType
Type returns PingMessage's corresponding type number.
type ReliableTypedMessage ¶
type ReliableTypedMessage struct { TypedMessage InboundID int `json:"i"` OutboundID int `json:"o"` }
type TravelMessage ¶
type TravelMessage struct {
Destination string `json:"d"`
}
TravelMessage is sent by the host to clients to enforce travel.
func (TravelMessage) Type ¶
func (m TravelMessage) Type() TypedMessageType
Type returns TravelMessage's corresponding type number.
type TypedMessage ¶
type TypedMessage struct { Type TypedMessageType `json:"t"` Data json.RawMessage `json:"d"` // contains filtered or unexported fields }
TypedMessage wraps a Message.
func (*TypedMessage) Message ¶
func (t *TypedMessage) Message() Message
Message returns the typed message's wrapped data as a Message.
type TypedMessageHandler ¶
type TypedMessageHandler struct {
Unwrap func(data json.RawMessage) Message
}
TypedMessageHandler represents a dynamically defined unmarshaller for a message.
type TypedMessageType ¶
type TypedMessageType int
TypedMessageType represents the contained type within a TypedMessage.
const ( MissingMessageType TypedMessageType = iota HenloMessageType PingMessageType TravelMessageType MoveMessageType )
These are our typed message types.
func AddTypedMessage ¶
func AddTypedMessage(typeIndex int, unwrapper func(data json.RawMessage) Message) TypedMessageType
AddTypedMessage adds the given unwrapper func as a Message unmarshaler. If typeIndex is 0, then an automatic index is generated and returned.