service

package
v0.0.0-...-1dc25d0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: BSD-4-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetTitle

func SetTitle(title string)

func SrvSetEntities

func SrvSetEntities(v *entity.Entities) optionF

初始化对象管理器

func SrvSetIsHavePlayer

func SrvSetIsHavePlayer(v bool) optionF

设置是否有玩家协程

func SrvSetNetSrv

func SrvSetNetSrv(v *sess.NetSrv) optionF

初始化网络服务

func SrvSetTimer

func SrvSetTimer(v *timerwheel.Timer) optionF

初始化定时器

Types

type IDGenerater

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

IDGenerater 获取唯一的ID号

func NewIDGenerater

func NewIDGenerater(srvID uint64) *IDGenerater

func (*IDGenerater) GenerateID

func (srv *IDGenerater) GenerateID() uint64

type IServiceReal

type IServiceReal interface {
	global.IsrvInst
	entity.IEntities
	sess.INetServer
	timerwheel.ITimer
	serverMgr.IExt

	/* 生命周期 */
	//所有子系统的初始化
	Init() error
	//循环调用
	Loop()
	//循环调用中间
	Looping()
	//循环调用结尾
	Looped()
	//结束服务
	Destroy()

	//监听需要主动连接的服务器逻辑
	WatchServer()
	// 服务器连接断开
	OnServerSessDisconnect(sid uint64)
	// 服务器连接成功
	OnServerSessConnect(srvid uint64, srvtype global.ServerTypeEnum)
}

后代service接口

type NetSess_Proc

type NetSess_Proc struct {
	Srv   *Service
	Sess  sess.INetSess
	SInfo serverMgr.IServerInfo
}

这个是主动链接别的服务器进的消息处理,验证完成后,就会跟换msghandler 用来处理主动连接别的服务器时候,验证逻辑的部分消息

func (*NetSess_Proc) MsgProc_ClientVerifyFailedRet

func (this *NetSess_Proc) MsgProc_ClientVerifyFailedRet(msg *protomsg.ClientVerifyFailedRet)

func (*NetSess_Proc) MsgProc_ClientVerifySucceedRet

func (this *NetSess_Proc) MsgProc_ClientVerifySucceedRet(msg *protomsg.ClientVerifySucceedRet)

连接别的服务器,对方验证过了

func (*NetSess_Proc) MsgProc_SessClosed

func (this *NetSess_Proc) MsgProc_SessClosed(msg *protomsg.SessClosed)

连接关闭的时候,会自己给自己发一个关闭的消息,这个消息还没有protomsg化 然后在service还有netsess还有user中都需要对这个进行处理

type Service

type Service struct {
	entity.DelayCallHost
	*sess.NetSrv
	*entity.Entities
	*timerwheel.Timer

	//每次Tick的时候的当前时间
	NowTime atomic.Pointer[time.Time]
	//时间偏移步长
	TimeStep time.Duration

	//每个服务器启动的时候自动生成的值
	Token string
	// 服务器状态
	Status atomic.Int32

	//服务器信息
	Sinfo *global.GlobalConfig
	// 监听地址
	ListenMap map[string]string

	//etcd
	Etcd *etcd.EtcdAccess
	//服务器信息管理器
	DisMgr *serverMgr.DiscoveryMgr

	// 所有等回复的消息
	WaitList sync.Map
	// 是否有玩家协程 默认为true
	IsHavePlayer bool
	// contains filtered or unexported fields
}

服务器基类

func NewService

func NewService(sinfo *global.GlobalConfig, real IServiceReal, opts ...optionF) (result *Service)

func (*Service) CallDelay

func (this *Service) CallDelay(f entity.CallDelayF)

func (*Service) CheckClose

func (this *Service) CheckClose(...interface{})

定时判断服务器是否需要关闭

func (*Service) Destroy

func (this *Service) Destroy()

结束服务

func (*Service) GetClientSess

func (this *Service) GetClientSess(id uint64) (result *sess.NetSess)

获取会话

func (*Service) GetDirMgr

func (this *Service) GetDirMgr() *serverMgr.DiscoveryMgr

获取服务器负载器

func (*Service) GetEtcd

func (this *Service) GetEtcd() *etcd.EtcdAccess

获取ETCD的实例

func (*Service) GetLoad

func (this *Service) GetLoad() int

获取服务器当前繁忙状态0-100

func (*Service) GetNewEID

func (this *Service) GetNewEID() uint64

获取新的EntityID

func (*Service) GetNowTime

func (this *Service) GetNowTime() time.Time

Loop时的时间

func (*Service) GetSelfInfo

func (this *Service) GetSelfInfo() serverMgr.IServerInfo

获取自己服务器需要注册的信息

func (*Service) GetThreadGo

func (this *Service) GetThreadGo() *threads.ThreadGo

操作子协程的管理器

func (*Service) GetWaitMap

func (this *Service) GetWaitMap() *sync.Map

获取等待回复的map

func (*Service) Init

func (this *Service) Init() (err error)

所有子系统的初始化

func (*Service) IsSrvValid

func (this *Service) IsSrvValid() bool

IsSrvValid 服务是否可用

func (*Service) Loop

func (this *Service) Loop()

循环调用

func (*Service) Looped

func (this *Service) Looped()

循环调用结尾

func (*Service) Looping

func (this *Service) Looping()

循环调用中间

func (*Service) NewInfo

func (this *Service) NewInfo(stype global.ServerTypeEnum) serverMgr.IServerInfo

根据类型生成一个新的IServerInfo对象,用与从etcd读出来后进行填充

func (*Service) OnMsgBefore

func (this *Service) OnMsgBefore(name string, msg msgdef.IMsg)

处理消息前

func (*Service) OnMsged

func (this *Service) OnMsged(name string, msg msgdef.IMsg)

处理消息后

func (*Service) OnPanic

func (this *Service) OnPanic(err error)

发生Panic的时候,做的处理

func (*Service) OnRpcBefore

func (this *Service) OnRpcBefore(name string, msg msgdef.IMsg)

处理RPC消息前

func (*Service) OnRpcReturn

func (this *Service) OnRpcReturn(msg msgdef.IMsg, err error)

处理Srv消息回复

func (*Service) OnRpced

func (this *Service) OnRpced(name string, msg msgdef.IMsg)

处理RPC消息后

func (*Service) OnServerSessConnect

func (this *Service) OnServerSessConnect(srvid uint64, srvtype global.ServerTypeEnum)

服务器连接成功

func (*Service) OnServerSessDisconnect

func (this *Service) OnServerSessDisconnect(sid uint64)

服务器连接断开

func (*Service) OnSrvReturn

func (this *Service) OnSrvReturn(req, msg msgdef.IMsg, err error)

处理Srv消息回复

func (*Service) PostMsgToClient

func (this *Service) PostMsgToClient(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)

通过目标服务器发消息给客户端

func (*Service) PostMsgToClientBuf

func (this *Service) PostMsgToClientBuf(srvid, spid, eid uint64, data []byte) (err error)

通过目标服务器发消息给客户端

func (*Service) PostMsgToEntity

func (this *Service) PostMsgToEntity(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)

发消息给其他服务器的对象

func (*Service) PostSess

func (this *Service) PostSess(srvid uint64, msg msgdef.IMsg)

发这消息到目标服务器

func (*Service) RangeSess

func (this *Service) RangeSess(f func(sess sess.INetSess) bool)

遍历所有被动连接,返回false就退出遍历

func (*Service) Run

func (this *Service) Run()

//////////////////////////////////////////////////////////// 主协程调用

func (*Service) SessClosed

func (this *Service) SessClosed(sessmd sess.INetSess)

连接被关闭的时候

func (*Service) String

func (this *Service) String() string

func (*Service) WatchInfoCallBack

func (this *Service) WatchInfoCallBack(sinfo serverMgr.IServerInfo)

获取到新的服务器信息的时候回调,一般用来判断是否需要连接这个服务器

func (*Service) WatchInfoDeleteCallBack

func (this *Service) WatchInfoDeleteCallBack(stype global.ServerTypeEnum, groupid uint64, sid uint64)

ETCD中一个服务器信息被删除的时候回调

func (*Service) WatchServer

func (this *Service) WatchServer()

监听需要主动连接的服务器逻辑 做服发现一般有二个目的:

1、主动连接对方服务器;
2、管理用户去对应服务器时候,使用什么负载均衡的逻辑;
默认系统给他们分配的都是随机负载均衡器;
如果你想修改,可以重载这个函数;
同一个stype+groupid的key只能watch一次;
所以上层使用新的负载均衡器Watch之后,这里就不会重新Watch了

type Service_Proc

type Service_Proc struct {
	*Service
}

func (*Service_Proc) MsgProc_EntityBroadcastMsgSrvReq

func (this *Service_Proc) MsgProc_EntityBroadcastMsgSrvReq(msg *protomsg.EntityBroadcastMsgSrvReq)

处理广播消息给多个实体的请求 通常由 Space 服务器发给 Gateway 服务器,Gateway 转发给对应客户端

func (*Service_Proc) MsgProc_EntityMsgRet

func (this *Service_Proc) MsgProc_EntityMsgRet(msg *protomsg.EntityMsgRet)

处理其他服务器要发给客户的消息

func (*Service_Proc) MsgProc_ForwardMsgSrv

func (this *Service_Proc) MsgProc_ForwardMsgSrv(msg *protomsg.ForwardMsgSrv)

处理转发过来的信息

func (*Service_Proc) MsgProc_ForwardRPCSrv

func (this *Service_Proc) MsgProc_ForwardRPCSrv(msg *protomsg.ForwardRPCSrv)

处理转发过来的RPC

func (*Service_Proc) MsgProc_RouteMsgSrvReq

func (this *Service_Proc) MsgProc_RouteMsgSrvReq(msg *protomsg.RouteMsgSrvReq)

处理转发过来需要回包的服务器消息

func (*Service_Proc) MsgProc_RouteMsgSrvRet

func (this *Service_Proc) MsgProc_RouteMsgSrvRet(msg *protomsg.RouteMsgSrvRet)

处理转发过来的服务器消息返回

func (*Service_Proc) MsgProc_SessClosed

func (this *Service_Proc) MsgProc_SessClosed(msg *protomsg.SessClosed)

处理连接被关的时候的消息,一般只需要输出信息就好

func (*Service_Proc) MsgProc_SetServerStatusReq

func (this *Service_Proc) MsgProc_SetServerStatusReq(msg *protomsg.SetServerStatusReq)

设置服务器状态

Jump to

Keyboard shortcuts

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