nodecommon

package
v0.0.0-...-96491ad Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualNID

func EqualNID(nid1 context.NodeID, nid2 context.NodeID) bool

EqualNID : 2 个 NID 是否相等

func EqualSID

func EqualSID(sid1 *protocol.SERVER_ID, sid2 *protocol.SERVER_ID) bool

EqualSID : 2 个 SID 是否相等

func NewNID

func NewNID(ctx *common.Context, t config.NodeType) context.NodeID

NewNID : 生成一个NID

func NodeID2ServerID

func NodeID2ServerID(nid context.NodeID) *protocol.SERVER_ID

NodeID2ServerID : context.NodeID 转化为 protocol.SERVER_ID

func ServerID2NodeID

func ServerID2NodeID(sid *protocol.SERVER_ID) context.NodeID

ServerID2NodeID : protocol.SERVER_ID 转化为 context.NodeID

Types

type DefaultNodeInterfaceImpl

type DefaultNodeInterfaceImpl struct {
	Info *protocol.SERVER_INFO

	SessMgr *SessionMgr
	// contains filtered or unexported fields
}

DefaultNodeInterfaceImpl : 缺省的节点接口实现

func (*DefaultNodeInterfaceImpl) EnableMessageRelay

func (impl *DefaultNodeInterfaceImpl) EnableMessageRelay(v bool)

EnableMessageRelay : 开启消息中继功能。开启该功能的节点,会连接 Gateway 。 C -> Gateway -> Node ; Node1 -> Gateway -> Node2(s)

func (*DefaultNodeInterfaceImpl) FuncOnLoseAccount

func (impl *DefaultNodeInterfaceImpl) FuncOnLoseAccount() context.FuncTypeOnLoseAccount

FuncOnLoseAccount : 获取`自定义处理丢失账号`的函数句柄

func (*DefaultNodeInterfaceImpl) FuncOnRelayMsg

func (impl *DefaultNodeInterfaceImpl) FuncOnRelayMsg() context.FuncTypeOnRelayMsg

FuncOnRelayMsg : 获取`自定义处理Gateway中继过来的消息`的函数句柄

func (*DefaultNodeInterfaceImpl) GetID

func (impl *DefaultNodeInterfaceImpl) GetID() context.NodeID

GetID : 获取本节点信息,节点ID

func (*DefaultNodeInterfaceImpl) GetIP

GetIP : 获取本节点信息,IP

func (*DefaultNodeInterfaceImpl) GetNode

func (impl *DefaultNodeInterfaceImpl) GetNode(nodeID context.NodeID) *SessionBase

GetNode : 获取节点

func (*DefaultNodeInterfaceImpl) GetNodeAll

func (impl *DefaultNodeInterfaceImpl) GetNodeAll() []*SessionBase

GetNodeAll : 获取所有节点

func (*DefaultNodeInterfaceImpl) GetNodeList

func (impl *DefaultNodeInterfaceImpl) GetNodeList(nodeType config.NodeType) []*SessionBase

GetNodeList : 获取某类型节点列表

func (*DefaultNodeInterfaceImpl) GetNodeOne

func (impl *DefaultNodeInterfaceImpl) GetNodeOne(nodeType config.NodeType) *SessionBase

GetNodeOne : 根据节点类型,随机选择 1 节点

func (*DefaultNodeInterfaceImpl) GetOverload

func (impl *DefaultNodeInterfaceImpl) GetOverload(i int) uint32

GetOverload : 获取本节点信息,负载

func (*DefaultNodeInterfaceImpl) GetPort

func (impl *DefaultNodeInterfaceImpl) GetPort(i int) int32

GetPort : 获取本节点信息,端口

func (*DefaultNodeInterfaceImpl) GetSID

GetSID : 获取 SID

func (*DefaultNodeInterfaceImpl) GetType

func (impl *DefaultNodeInterfaceImpl) GetType() config.NodeType

GetType : 获取节点类型

func (*DefaultNodeInterfaceImpl) GetVersion

func (impl *DefaultNodeInterfaceImpl) GetVersion() string

GetVersion : 获取本节点信息,版本号

func (*DefaultNodeInterfaceImpl) HaveNode

func (impl *DefaultNodeInterfaceImpl) HaveNode(nodeID context.NodeID) bool

HaveNode : 是否有节点

func (*DefaultNodeInterfaceImpl) IsEnableMessageRelay

func (impl *DefaultNodeInterfaceImpl) IsEnableMessageRelay() bool

IsEnableMessageRelay : 是否开启了消息中继功能

func (*DefaultNodeInterfaceImpl) PrintAllNodeInfo

func (impl *DefaultNodeInterfaceImpl) PrintAllNodeInfo(log context.ILogger)

PrintAllNodeInfo : 打印节点信息

func (*DefaultNodeInterfaceImpl) PrintNodeInfo

func (impl *DefaultNodeInterfaceImpl) PrintNodeInfo(log context.ILogger, nodeType config.NodeType)

PrintNodeInfo : 打印节点信息

func (*DefaultNodeInterfaceImpl) RegisterFuncOnLoseAccount

func (impl *DefaultNodeInterfaceImpl) RegisterFuncOnLoseAccount(f context.FuncTypeOnLoseAccount)

RegisterFuncOnLoseAccount : 注册自定义处理`丢失账号`

func (*DefaultNodeInterfaceImpl) RegisterFuncOnRelayMsg

func (impl *DefaultNodeInterfaceImpl) RegisterFuncOnRelayMsg(f context.FuncTypeOnRelayMsg)

RegisterFuncOnRelayMsg : 注册自定义处理Gateway中继过来的消息

func (*DefaultNodeInterfaceImpl) SendAll

func (impl *DefaultNodeInterfaceImpl) SendAll(cmd uint64, msg proto.Message, excludeSelf bool)

SendAll : 对服务器组,广播数据

func (*DefaultNodeInterfaceImpl) SendByID

func (impl *DefaultNodeInterfaceImpl) SendByID(nodeID context.NodeID, cmd uint64, msg proto.Message) bool

SendByID : 往指定节点,发送数据

func (*DefaultNodeInterfaceImpl) SendByType

func (impl *DefaultNodeInterfaceImpl) SendByType(nodeType config.NodeType, cmd uint64, msg proto.Message, excludeSelf bool)

SendByType : 对某类型节点,广播数据

func (*DefaultNodeInterfaceImpl) SendOne

func (impl *DefaultNodeInterfaceImpl) SendOne(nodeType config.NodeType, cmd uint64, msg proto.Message) bool

SendOne : 根据节点类型,随机选择 1 节点,发送数据

type ISessionDerived

type ISessionDerived interface {
	DoVerify(msg *protocol.MSG_MGR_REGISTER_SERVER)
	DoRegister(msg *protocol.MSG_MGR_REGISTER_SERVER)
	DoLose(msg *protocol.MSG_MGR_LOSE_SERVER)
	DoClose(sessbase *SessionBase)
	DoRecv(cmd uint64, data []byte, flag byte) (done bool)
}

ISessionDerived : SessionBase 派生类接口定义

type Node

type Node struct {
	Ctx *common.Context
	DefaultNodeInterfaceImpl
	// contains filtered or unexported fields
}

Node : 管理节点基类

func NewNode

func NewNode(ctx *common.Context, nodeType config.NodeType) *Node

NewNode : 管理节点基类实现类的构造函数

func (*Node) BroadcastMsgToClient

func (node *Node) BroadcastMsgToClient(cmd uint64, data []byte, flag uint8) bool

BroadcastMsgToClient : 广播消息给客户端,通过 Gateway 中继

func (*Node) BroadcastMsgToServer

func (node *Node) BroadcastMsgToServer(t config.NodeType, cmd uint64, data []byte, flag uint8) bool

BroadcastMsgToServer : 广播消息给某类型服务

func (*Node) Close

func (node *Node) Close()

Close : 关闭节点

func (*Node) Init

func (node *Node) Init(sessType interface{}, components []utils.IComponent) bool

Init : 初始化节点

func (*Node) ReplyMsgToServer

func (node *Node) ReplyMsgToServer(targetID context.NodeID, cmd uint64, data []byte, flag uint8) bool

ReplyMsgToServer : 回发消息给请求服务器

func (*Node) SendMsgToClient

func (node *Node) SendMsgToClient(account string, cmd uint64, data []byte, flag uint8) bool

SendMsgToClient : 发送消息给客户端,通过 Gateway 中继

func (*Node) SendMsgToServer

func (node *Node) SendMsgToServer(t config.NodeType, cmd uint64, data []byte, flag uint8) bool

SendMsgToServer : 发送消息给某类型服务(随机一个)

func (*Node) Start

func (node *Node) Start() bool

Start : 节点开始工作

type SessionBase

type SessionBase struct {
	DefaultNodeInterfaceImpl
	*gotcp.Session
	Ctx              *common.Context
	CacheRegisterMsg *protocol.MSG_MGR_REGISTER_SERVER
	// contains filtered or unexported fields
}

SessionBase : 网络会话类

func NewSessionBase

func NewSessionBase(ctx *common.Context, derived ISessionDerived) *SessionBase

NewSessionBase : 网络会话类的构造函数

func (*SessionBase) OnClose

func (sessbase *SessionBase) OnClose()

OnClose : 断开连接,被触发

func (*SessionBase) OnRecv

func (sessbase *SessionBase) OnRecv(data []byte, flag byte)

OnRecv : 接收到网络数据包,被触发

func (*SessionBase) RegisterSelf

func (sessbase *SessionBase) RegisterSelf(id context.NodeID, selfType config.NodeType, targetServerType config.NodeType, targetServerID *protocol.SERVER_ID)

RegisterSelf : 注册自己

type SessionMgr

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

SessionMgr : 网络会话对象管理类

func NewSessionMgr

func NewSessionMgr(ctx *common.Context) *SessionMgr

NewSessionMgr : 实例化网络会话对象管理类

func (*SessionMgr) ForAll

func (sessmgr *SessionMgr) ForAll(f func(*SessionBase))

ForAll : 遍历所有网络会话节点

func (*SessionMgr) ForByType

func (sessmgr *SessionMgr) ForByType(t config.NodeType, f func(*SessionBase))

ForByType : 根据类型遍历网络会话节点

func (*SessionMgr) GetAll

func (sessmgr *SessionMgr) GetAll() []*SessionBase

GetAll : 获取所有网络会话节点列表

func (*SessionMgr) GetByID

func (sessmgr *SessionMgr) GetByID(nid context.NodeID) *SessionBase

GetByID : 根据 NID 获取网络会话节点

func (*SessionMgr) GetByType

func (sessmgr *SessionMgr) GetByType(t config.NodeType) []*SessionBase

GetByType : 根据节点类型,获取某类网络会话节点列表

func (*SessionMgr) Lose1

func (sessmgr *SessionMgr) Lose1(sess *SessionBase)

Lose1 : 丢失网络会话节点

func (*SessionMgr) Lose2

func (sessmgr *SessionMgr) Lose2(sid *protocol.SERVER_ID, t config.NodeType)

Lose2 : 丢失网络会话节点

func (*SessionMgr) Register

func (sessmgr *SessionMgr) Register(sess *SessionBase)

Register : 有网络会话节点加入

func (*SessionMgr) SelectOne

func (sessmgr *SessionMgr) SelectOne(t config.NodeType) *SessionBase

SelectOne : 选择 1 个某类型的网络会话节点

type UserData

type UserData struct {
	Ctx     *common.Context
	SessMgr *SessionMgr
}

UserData : 传递给 Session 的数据

Jump to

Keyboard shortcuts

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