gatebase

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package basegate handler

Package basegate gate.Session

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSession

func NewSession(data []byte) (gate.ISession, error)

NewSession data必须要有效

func NewSessionByMap

func NewSessionByMap(data map[string]any) (gate.ISession, error)

NewSessionByMap data可以为空则构造一个空的Session

func NewTCPConnAgent

func NewTCPConnAgent() gate.IConnAgent

func NewWSConnAgent

func NewWSConnAgent() gate.IConnAgent

Types

type Delegate

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

Delegate Delegate(gate.IAgentLearner,gate.IDelegater)

func NewDelegate

func NewDelegate(gate gate.IGate) *Delegate

NewDelegate NewDelegate

func (*Delegate) Connect

func (this *Delegate) Connect(a gate.IConnAgent)

当连接建立(握手成功)

func (*Delegate) DisConnect

func (this *Delegate) DisConnect(a gate.IConnAgent)

当连接关闭(客户端主动关闭或者异常断开)

func (*Delegate) GetAgent

func (this *Delegate) GetAgent(sessionId string) (gate.IConnAgent, error)

GetAgent

func (*Delegate) GetAgentNum

func (this *Delegate) GetAgentNum() int

GetAgentNum

func (*Delegate) OnDestroy

func (this *Delegate) OnDestroy()

OnDestroy

func (*Delegate) OnRpcBind

func (this *Delegate) OnRpcBind(ctx context.Context, sessionId string, userId string) (gate.ISession, error)

Bind the session with the the userId.

func (*Delegate) OnRpcBroadcast

func (this *Delegate) OnRpcBroadcast(ctx context.Context, topic string, body []byte) (int64, error)

broadcast message to all session of the gate

func (*Delegate) OnRpcClose

func (this *Delegate) OnRpcClose(ctx context.Context, sessionId string) (bool, error)

Proactively close the connection of session

func (*Delegate) OnRpcConnected

func (this *Delegate) OnRpcConnected(ctx context.Context, sessionId string) (bool, error)

check connect is normal for the session

func (*Delegate) OnRpcDel

func (this *Delegate) OnRpcDel(ctx context.Context, sessionId string, key string) (gate.ISession, error)

Del value from the session.

func (*Delegate) OnRpcLoad

func (this *Delegate) OnRpcLoad(ctx context.Context, sessionId string) (gate.ISession, error)

Load the latest session

func (*Delegate) OnRpcPush

func (this *Delegate) OnRpcPush(ctx context.Context, sessionId string, settings map[string]string) (gate.ISession, error)

Push the session with the the userId.

func (*Delegate) OnRpcSend

func (this *Delegate) OnRpcSend(ctx context.Context, sessionId string, topic string, body []byte) (bool, error)

Send message to the session.

func (*Delegate) OnRpcSet

func (this *Delegate) OnRpcSet(ctx context.Context, sessionId string, key string, value string) (gate.ISession, error)

Set values (one or many) for the session.

func (*Delegate) OnRpcUnBind

func (this *Delegate) OnRpcUnBind(ctx context.Context, sessionId string) (gate.ISession, error)

UnBind the session with the the userId.

type GateBase

type GateBase struct {
	module.ModuleBase
	// contains filtered or unexported fields
}

func (*GateBase) GetAgentLearner

func (this *GateBase) GetAgentLearner() gate.IAgentLearner

SetAgentLearner 获取客户端连接和断开的监听器(建议用 SetSessionLearner)

func (*GateBase) GetDelegater

func (this *GateBase) GetDelegater() gate.IDelegater

GetDelegater 获取代理处理器

func (*GateBase) GetGuestJudger

func (this *GateBase) GetGuestJudger() func(session gate.ISession) bool

GetGuestJudger 获取是否游客的判定器

func (*GateBase) GetRouteHandler

func (this *GateBase) GetRouteHandler() gate.RouteHandler

GetRouteHandler 获取路由接口

func (*GateBase) GetSendMessageHook

func (this *GateBase) GetSendMessageHook() gate.SendMessageHook

GetSendMessageHook 获取发送消息时的钩子回调

func (*GateBase) GetSessionLearner

func (this *GateBase) GetSessionLearner() gate.ISessionLearner

GetSessionLearner 获取客户端连接和断开的监听器

func (*GateBase) GetShakeHandler

func (this *GateBase) GetShakeHandler() func(r *http.Request) error

GetShakeHandler 获取建立连接时鉴权器(ws)

func (*GateBase) GetStorageHandler

func (this *GateBase) GetStorageHandler() (storager gate.StorageHandler)

GetStorageHandler 获取Session信息持久化接口

func (*GateBase) GetType

func (this *GateBase) GetType() string

func (*GateBase) Init

func (this *GateBase) Init(subclass app.IRPCModule, settings *conf.ModuleSettings, opts ...gate.Option)

func (*GateBase) OnAppConfigurationLoaded

func (this *GateBase) OnAppConfigurationLoaded()

func (*GateBase) OnConfChanged

func (this *GateBase) OnConfChanged(settings *conf.ModuleSettings)

func (*GateBase) OnDestroy

func (this *GateBase) OnDestroy()

func (*GateBase) Options

func (this *GateBase) Options() gate.Options

func (*GateBase) Run

func (this *GateBase) Run(closeSig chan bool)

func (*GateBase) SetAgentCreater

func (this *GateBase) SetAgentCreater(cfunc func(netTyp string) gate.IConnAgent) error

设置创建客户端Agent的函数

func (*GateBase) SetAgentLearner

func (this *GateBase) SetAgentLearner(learner gate.IAgentLearner) error

SetAgentLearner 设置客户端连接和断开的监听器(内部用)

func (*GateBase) SetGateHandler

func (this *GateBase) SetGateHandler(handler gate.IDelegater) error

SetGateHandler 设置代理处理器

func (*GateBase) SetGuestJudger

func (this *GateBase) SetGuestJudger(judger func(session gate.ISession) bool) error

SetGuestJudger 设置是否游客的判定器

func (*GateBase) SetRouteHandler

func (this *GateBase) SetRouteHandler(router gate.RouteHandler) error

SetRouteHandler 设置路由接口

func (*GateBase) SetSendMessageHook

func (this *GateBase) SetSendMessageHook(hook gate.SendMessageHook) error

SetsendMessageHook 设置发送消息时的钩子回调

func (*GateBase) SetSessionLearner

func (this *GateBase) SetSessionLearner(learner gate.ISessionLearner) error

SetSessionLearner 设置客户端连接和断开的监听器

func (*GateBase) SetShakeHandler

func (this *GateBase) SetShakeHandler(handler func(r *http.Request) error) error

SetShakeHandler 设置建立连接时鉴权器(ws)

func (*GateBase) SetStorageHandler

func (this *GateBase) SetStorageHandler(storager gate.StorageHandler) error

SetStorageHandler 设置Session信息持久化接口

func (*GateBase) Version

func (this *GateBase) Version() string

type SessionImp

type SessionImp struct {
	IP        string            `msgpack:"ip,omitempty" json:"ip,omitempty"`
	Network   string            `msgpack:"network,omitempty" json:"network,omitempty"`
	UserId    string            `msgpack:"user_id,omitempty" json:"user_id,omitempty"`
	SessionId string            `msgpack:"session_id,omitempty" json:"session_id,omitempty"`
	ServerId  string            `msgpack:"server_id,omitempty" json:"server_id,omitempty"`
	TraceId   string            `msgpack:"trace_id,omitempty" json:"trace_id,omitempty"`
	SpanId    string            `msgpack:"span_id,omitempty" json:"span_id,omitempty"`
	Settings  map[string]string `msgpack:"settings,omitempty" json:"settings,omitempty"`
}

type TCPConnAgent

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

func (*TCPConnAgent) Close

func (this *TCPConnAgent) Close()

func (*TCPConnAgent) ConnTime

func (this *TCPConnAgent) ConnTime() time.Time

ConnTime 建立连接的时间

func (*TCPConnAgent) GetError

func (this *TCPConnAgent) GetError() error

获取最后发生的错误

func (*TCPConnAgent) GetSession

func (this *TCPConnAgent) GetSession() gate.ISession

GetSession 管理的ClientSession

func (*TCPConnAgent) Init

func (this *TCPConnAgent) Init(impl gate.IConnAgent, gt gate.IGate, conn network.Conn) error

func (*TCPConnAgent) IsClosed

func (this *TCPConnAgent) IsClosed() bool

IsClosed 是否关闭了

func (*TCPConnAgent) IsShaked

func (this *TCPConnAgent) IsShaked() bool

IsShaked 连接就绪(握手/认证...)

func (*TCPConnAgent) OnClose

func (this *TCPConnAgent) OnClose() error

func (*TCPConnAgent) OnHandRecvPack

func (this *TCPConnAgent) OnHandRecvPack(pack *gate.Pack) error

实现如何处理收到的数据包

func (*TCPConnAgent) OnReadDecodingPack

func (this *TCPConnAgent) OnReadDecodingPack() (*gate.Pack, error)

读取数据并解码出Pack

func (*TCPConnAgent) OnWriteEncodingPack

func (this *TCPConnAgent) OnWriteEncodingPack(pack *gate.Pack) []byte

OnWriteEncodingPack 处理Pack数据的编码用于发送

func (*TCPConnAgent) RecvNum

func (this *TCPConnAgent) RecvNum() int64

RecvNum 接收消息的数量

func (*TCPConnAgent) Run

func (this *TCPConnAgent) Run() (err error)

func (*TCPConnAgent) SendNum

func (this *TCPConnAgent) SendNum() int64

SendNum 发送消息的数量

func (*TCPConnAgent) SendPack

func (this *TCPConnAgent) SendPack(pack *gate.Pack) error

SendPack 提供发送数据包的方法

type WSConnAgent

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

func (*WSConnAgent) Close

func (this *WSConnAgent) Close()

func (*WSConnAgent) ConnTime

func (this *WSConnAgent) ConnTime() time.Time

ConnTime 建立连接的时间

func (*WSConnAgent) GetError

func (this *WSConnAgent) GetError() error

获取最后发生的错误

func (*WSConnAgent) GetSession

func (this *WSConnAgent) GetSession() gate.ISession

GetSession 管理的ClientSession

func (*WSConnAgent) Init

func (this *WSConnAgent) Init(impl gate.IConnAgent, gt gate.IGate, conn network.Conn) error

func (*WSConnAgent) IsClosed

func (this *WSConnAgent) IsClosed() bool

IsClosed 是否关闭了

func (*WSConnAgent) IsShaked

func (this *WSConnAgent) IsShaked() bool

IsShaked 连接就绪(握手/认证...)

func (*WSConnAgent) OnClose

func (this *WSConnAgent) OnClose() error

func (*WSConnAgent) OnHandRecvPack

func (this *WSConnAgent) OnHandRecvPack(pack *gate.Pack) error

实现如何处理收到的数据包

func (*WSConnAgent) OnReadDecodingPack

func (this *WSConnAgent) OnReadDecodingPack() (*gate.Pack, error)

读取数据并解码出Pack

func (*WSConnAgent) OnWriteEncodingPack

func (this *WSConnAgent) OnWriteEncodingPack(pack *gate.Pack) []byte

OnWriteEncodingPack 处理Pack数据的编码用于发送

func (*WSConnAgent) RecvNum

func (this *WSConnAgent) RecvNum() int64

RecvNum 接收消息的数量

func (*WSConnAgent) Run

func (this *WSConnAgent) Run() (err error)

func (*WSConnAgent) SendNum

func (this *WSConnAgent) SendNum() int64

SendNum 发送消息的数量

func (*WSConnAgent) SendPack

func (this *WSConnAgent) SendPack(pack *gate.Pack) error

SendPack 提供发送数据包的方法

Jump to

Keyboard shortcuts

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