net

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

TypedMessageMap is a map of all defined types->TypedMessageHandlers

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Name string

	OtherName string
	// contains filtered or unexported fields
}

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

type HenloMessage struct {
	Greeting string `json:"g"`
	Name     string `json:"n"`
}

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

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.

Jump to

Keyboard shortcuts

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