core

package
v0.0.0-...-16132a2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InternalRPCPerStepTimeout = 10 * time.Second

Functions

func Bind

func Bind[S Server, C HandlerConstructor[S, H, T, U], H Handler[T], T RequestPtr[U], U any](server S)

func ExecutePacketHandler

func ExecutePacketHandler(actorCtx actor.Context, server Server, client Client, opcode int, data []byte, logicActorPID *actor.PID) error

func GetFileDescriptor

func GetFileDescriptor(conn net.Conn) (int, error)

func GetPacketLogEnabled

func GetPacketLogEnabled() bool

func SetPacketLogEnabled

func SetPacketLogEnabled(b bool)

Types

type BaseClient

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

func NewBaseClient

func NewBaseClient(conn net.Conn, clientID int, fd int, sendEncryption, recvEncryption *crypt.Encryption) BaseClient

func (*BaseClient) GetConnection

func (c *BaseClient) GetConnection() net.Conn

func (*BaseClient) GetFd

func (c *BaseClient) GetFd() int

func (*BaseClient) GetRecvEncryption

func (c *BaseClient) GetRecvEncryption() *crypt.Encryption

func (*BaseClient) GetSendEncryption

func (c *BaseClient) GetSendEncryption() *crypt.Encryption

func (*BaseClient) MarkPongReceived

func (c *BaseClient) MarkPongReceived()

func (*BaseClient) NextPingAction

func (c *BaseClient) NextPingAction(now time.Time, interval time.Duration) (sendPing bool, disconnect bool)

func (*BaseClient) Send

func (c *BaseClient) Send(packet types.Packet, policy types.SendPolicy) error

type Client

type Client = client.Client

type ClientContext

type ClientContext struct {
	Client        Client
	Server        *ServerCore
	LogicActorPID *actor.PID
	ActorContext  actor.Context
}

type Handler

type Handler[T Request] interface {
	Handle(ctx *ClientContext, req T) error
}

type HandlerConstructor

type HandlerConstructor[S any, H Handler[T], T RequestPtr[U], U any] interface {
	New(S) H
}

type PacketHandler

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

func NewPacketHandler

func NewPacketHandler() *PacketHandler

func (*PacketHandler) GetHandler

func (h *PacketHandler) GetHandler(opcode int) func(ctx *ClientContext, data []byte) error

func (*PacketHandler) GetHandlerCount

func (h *PacketHandler) GetHandlerCount() int

func (*PacketHandler) GetRegisteredOpcodes

func (h *PacketHandler) GetRegisteredOpcodes() []int

func (*PacketHandler) Handle

func (h *PacketHandler) Handle(ctx *ClientContext, opcode int, data []byte) error

func (*PacketHandler) RegisterHandler

func (h *PacketHandler) RegisterHandler(opcode int, handler func(ctx *ClientContext, data []byte) error)

type RepeatingTimer

type RepeatingTimer struct {
	ID         uint64
	Interval   time.Duration
	Logic      func() error
	Callback   func(bool, error)
	CancelChan chan struct{}
	CreatedAt  time.Time
	IsRunning  bool
}

func (*RepeatingTimer) Cancel

func (rt *RepeatingTimer) Cancel()

type Request

type Request interface {
	Deserialize(reader *stream.StreamReader)
	Opcode() byte
}

type RequestPtr

type RequestPtr[T any] interface {
	Request
	*T
}

type Server

type Server interface {
	ensure.EnsureCoordinator
	GetPacketHandler() *PacketHandler
}

type ServerConfig

type ServerConfig struct {
	Host               string
	Port               int
	OnClientConnect    func(Client)
	OnClientDisconnect func(Client)
	ClientFactory      func(net.Conn, int) (Client, error)
}

type ServerCore

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

func NewServer

func NewServer(config *ServerConfig) (*ServerCore, error)

func (*ServerCore) GetPacketHandler

func (s *ServerCore) GetPacketHandler() *PacketHandler

func (*ServerCore) GetRootContext

func (s *ServerCore) GetRootContext() *actor.RootContext

func (*ServerCore) GetStats

func (s *ServerCore) GetStats() map[string]interface{}

func (*ServerCore) RegisterPacketHandler

func (s *ServerCore) RegisterPacketHandler(opcode int, handler func(ctx *ClientContext, data []byte) error)

func (*ServerCore) SetNilMapActorPID

func (s *ServerCore) SetNilMapActorPID(pid *actor.PID)

func (*ServerCore) SetOnClientDisconnect

func (s *ServerCore) SetOnClientDisconnect(callback func(Client))

func (*ServerCore) SetRootContext

func (s *ServerCore) SetRootContext(root *actor.RootContext)

func (*ServerCore) Start

func (s *ServerCore) Start(host string, port int) error

func (*ServerCore) Stop

func (s *ServerCore) Stop() error

type Timer

type Timer struct {
	ID         uint64
	Logic      func() error
	Callback   func(bool, error)
	CancelChan chan struct{}
	CreatedAt  time.Time
}

func (*Timer) Cancel

func (t *Timer) Cancel()

type TimerManager

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

func NewTimerManager

func NewTimerManager() *TimerManager

func (*TimerManager) CancelAllTimers

func (tm *TimerManager) CancelAllTimers()

func (*TimerManager) CancelRepeatingTimer

func (tm *TimerManager) CancelRepeatingTimer(timerID uint64) error

func (*TimerManager) GetRepeatingTimerCount

func (tm *TimerManager) GetRepeatingTimerCount() int

func (*TimerManager) GetTimerCount

func (tm *TimerManager) GetTimerCount() int

func (*TimerManager) RemoveRepeatingTimer

func (tm *TimerManager) RemoveRepeatingTimer(timerID uint64)

func (*TimerManager) RemoveTimer

func (tm *TimerManager) RemoveTimer(timerID uint64)

func (*TimerManager) Schedule

func (tm *TimerManager) Schedule(duration time.Duration, logic func() error, callback func(bool, error)) *Timer

func (*TimerManager) SetRepeatingTimer

func (tm *TimerManager) SetRepeatingTimer(interval time.Duration, logic func() error, callback func(bool, error)) *RepeatingTimer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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