cnet

package
v0.0.0-...-cafca90 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USE_E = iota
	USE_FE
)

Variables

This section is empty.

Functions

func RandomPort

func RandomPort() (int, error)

func StubbedPacket

func StubbedPacket(_ *Peer, _ protocol.Packet) error

Types

type PacketEvent

type PacketEvent struct {
	Type  int
	Pkt   *bytes.Buffer
	PktID uint32
}

type PacketHandler

type PacketHandler func(peer *Peer, pkt protocol.Packet) error

type Peer

type Peer struct {

	// May not be set while Send() or Handler() are concurrently running.
	E_key []byte

	// May not be set while Send() or Handler() are concurrently running.
	FE_key []byte
	// contains filtered or unexported fields
}

Peer is a simple wrapper for net.Conn connections to send/recv packets over the Fusionfall packet protocol.

func NewPeer

func NewPeer(ctx context.Context, conn net.Conn) *Peer

func (*Peer) Handler

func (peer *Peer) Handler(eRecv chan<- *PacketEvent) error

meant to be invoked as a goroutine

func (*Peer) Kill

func (peer *Peer) Kill()

func (*Peer) Send

func (peer *Peer) Send(typeID uint32, data ...interface{}) error

func (*Peer) SetActiveKey

func (peer *Peer) SetActiveKey(whichKey int)

func (*Peer) SetUserData

func (peer *Peer) SetUserData(uData interface{})

func (*Peer) UserData

func (peer *Peer) UserData() interface{}

type Service

type Service struct {
	Name string

	// OnDisconnect is called when a peer disconnects from the service.
	// uData is the stored value of the key/value pair in the peer map.
	// It may not be set while the service is running. (eg. srvc.Start() has been called)
	OnDisconnect func(peer *Peer)

	// OnConnect is called when a peer connects to the service.
	// return value is used as the value in the peer map.
	// It may not be set while the service is running. (eg. srvc.Start() has been called)
	OnConnect func(peer *Peer)
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, name string, port int) *Service

func (*Service) AddPacketHandler

func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler)

may not be called while the service is running (eg. srvc.Start() has been called)

func (*Service) Lock

func (srvc *Service) Lock()

locks the peer map.

func (*Service) RangePeers

func (srvc *Service) RangePeers(f func(peer *Peer) bool)

calls f for each peer in the service passing the peer and the stored uData. if f returns false, the iteration is stopped. NOTE: the peer map is not locked while iterating, if you're calling this outside of the service's event loop, you'll need to lock the peer map yourself.

func (*Service) Reset

func (srvc *Service) Reset(ctx context.Context)

func (*Service) Start

func (srvc *Service) Start() error

func (*Service) Started

func (srvc *Service) Started() <-chan struct{}

returns a channel that is closed when the service has started. this is useful if you need to wait until after the service has started.

func (*Service) Stopped

func (srvc *Service) Stopped() <-chan struct{}

returns a channel that is closed when the service has stopped. this is useful if you need wait until after the service has stopped.

func (*Service) Unlock

func (srvc *Service) Unlock()

unlocks the peer map.

Directories

Path Synopsis
generated via genstructs.py - All structure padding and member alignment verified
generated via genstructs.py - All structure padding and member alignment verified

Jump to

Keyboard shortcuts

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