communications

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelsAlreadyClosed = errors.New("error channels already closed")
)

All kind of errors for game

Functions

This section is empty.

Types

type Command

type Command interface {
	GetMsgType() uint8
	Decode(msg []byte)
	Encode() []byte
	Execute(ctx context.Context) error
}

Command interface for standard command

type CommandParser

type CommandParser interface {
	Parse(msg []byte) (cmd Command, err error)
}

CommandParser command parser

type CommunicateComponent

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

CommunicateComponent communication component

func NewCommunicateComponent

func NewCommunicateComponent(conn net.Conn) *CommunicateComponent

NewCommunicateComponent return new communication component

func (*CommunicateComponent) AddMessageToQueue

func (c *CommunicateComponent) AddMessageToQueue(m OutgoingMessage)

AddMessageToQueue add message to queue

func (*CommunicateComponent) Close

func (c *CommunicateComponent) Close() (err error)

Close close channels

func (*CommunicateComponent) GetIncoming

func (c *CommunicateComponent) GetIncoming() chan []byte

GetIncoming return incoming channel

func (*CommunicateComponent) GetOutgoing

func (c *CommunicateComponent) GetOutgoing() chan []byte

GetOutgoing return outgoing channel

func (*CommunicateComponent) GetParser

func (c *CommunicateComponent) GetParser() CommandParser

GetParser return command parser

func (*CommunicateComponent) GetQueue

func (c *CommunicateComponent) GetQueue() [][]byte

GetQueue retun copy of queue

func (*CommunicateComponent) InitChannels

func (c *CommunicateComponent) InitChannels()

InitChannels init channels

func (*CommunicateComponent) IsWaiting

func (c *CommunicateComponent) IsWaiting() bool

IsWaiting return true if still wait

func (*CommunicateComponent) ProcessIncomingMessages

func (c *CommunicateComponent) ProcessIncomingMessages(ctx context.Context, e []byte) error

ProcessIncomingMessages execute commands

func (*CommunicateComponent) ProcessOutgoingQueue

func (c *CommunicateComponent) ProcessOutgoingQueue()

ProcessOutgoingQueue processing cache

func (*CommunicateComponent) Send

Send send message for player

func (*CommunicateComponent) SetParser

func (c *CommunicateComponent) SetParser(parser CommandParser)

SetParser set command parser

func (*CommunicateComponent) StartReadingMessages

func (c *CommunicateComponent) StartReadingMessages(ctx context.Context)

StartReadingMessages starting processing incoming messages

func (*CommunicateComponent) Wait

func (c *CommunicateComponent) Wait(w bool)

Wait mark connection waiting

func (*CommunicateComponent) Write

func (c *CommunicateComponent) Write(d []byte)

Write write data in chan

type Communication

type Communication interface {
	ProcessOutgoingQueue()
	AddMessageToQueue(m OutgoingMessage)
	GetIncoming() chan []byte
	GetOutgoing() chan []byte
	ProcessIncomingMessages(ctx context.Context, e []byte) error
	Close() error
	Write(d []byte)
}

Communication describe communication

type CommunicationSystem

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

CommunicationSystem contains moveable entities

func NewCommunicationSystem

func NewCommunicationSystem(
	reg *registry.Registry[any, any, any],
	workersCount int,
	keys ...interface{},
) *CommunicationSystem

NewCommunicationSystem return new CommunicationSystem

func (*CommunicationSystem) EntitiesKeys

func (c *CommunicationSystem) EntitiesKeys() []interface{}

EntitiesKeys return entities keys

func (*CommunicationSystem) Update

func (c *CommunicationSystem) Update(ctx context.Context) error

Update update move

type OutgoingMessage

type OutgoingMessage interface {
	GetMessageType() uint8
	Encode() []byte
}

OutgoingMessage describe outgoing message

Jump to

Keyboard shortcuts

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