Documentation
¶
Index ¶
- func SetTitle(title string)
- func SrvSetEntities(v *entity.Entities) optionF
- func SrvSetIsHavePlayer(v bool) optionF
- func SrvSetNetSrv(v *sess.NetSrv) optionF
- func SrvSetTimer(v *timerwheel.Timer) optionF
- type IDGenerater
- type IServiceReal
- type NetSess_Proc
- type Service
- func (this *Service) CallDelay(f entity.CallDelayF)
- func (this *Service) CheckClose(...interface{})
- func (this *Service) Destroy()
- func (this *Service) GetClientSess(id uint64) (result *sess.NetSess)
- func (this *Service) GetDirMgr() *serverMgr.DiscoveryMgr
- func (this *Service) GetEtcd() *etcd.EtcdAccess
- func (this *Service) GetLoad() int
- func (this *Service) GetNewEID() uint64
- func (this *Service) GetNowTime() time.Time
- func (this *Service) GetSelfInfo() serverMgr.IServerInfo
- func (this *Service) GetThreadGo() *threads.ThreadGo
- func (this *Service) GetWaitMap() *sync.Map
- func (this *Service) Init() (err error)
- func (this *Service) IsSrvValid() bool
- func (this *Service) Loop()
- func (this *Service) Looped()
- func (this *Service) Looping()
- func (this *Service) NewInfo(stype global.ServerTypeEnum) serverMgr.IServerInfo
- func (this *Service) OnMsgBefore(name string, msg msgdef.IMsg)
- func (this *Service) OnMsged(name string, msg msgdef.IMsg)
- func (this *Service) OnPanic(err error)
- func (this *Service) OnRpcBefore(name string, msg msgdef.IMsg)
- func (this *Service) OnRpcReturn(msg msgdef.IMsg, err error)
- func (this *Service) OnRpced(name string, msg msgdef.IMsg)
- func (this *Service) OnServerSessConnect(srvid uint64, srvtype global.ServerTypeEnum)
- func (this *Service) OnServerSessDisconnect(sid uint64)
- func (this *Service) OnSrvReturn(req, msg msgdef.IMsg, err error)
- func (this *Service) PostMsgToClient(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)
- func (this *Service) PostMsgToClientBuf(srvid, spid, eid uint64, data []byte) (err error)
- func (this *Service) PostMsgToEntity(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)
- func (this *Service) PostSess(srvid uint64, msg msgdef.IMsg)
- func (this *Service) RangeSess(f func(sess sess.INetSess) bool)
- func (this *Service) Run()
- func (this *Service) SessClosed(sessmd sess.INetSess)
- func (this *Service) String() string
- func (this *Service) WatchInfoCallBack(sinfo serverMgr.IServerInfo)
- func (this *Service) WatchInfoDeleteCallBack(stype global.ServerTypeEnum, groupid uint64, sid uint64)
- func (this *Service) WatchServer()
- type Service_Proc
- func (this *Service_Proc) MsgProc_EntityBroadcastMsgSrvReq(msg *protomsg.EntityBroadcastMsgSrvReq)
- func (this *Service_Proc) MsgProc_EntityMsgRet(msg *protomsg.EntityMsgRet)
- func (this *Service_Proc) MsgProc_ForwardMsgSrv(msg *protomsg.ForwardMsgSrv)
- func (this *Service_Proc) MsgProc_ForwardRPCSrv(msg *protomsg.ForwardRPCSrv)
- func (this *Service_Proc) MsgProc_RouteMsgSrvReq(msg *protomsg.RouteMsgSrvReq)
- func (this *Service_Proc) MsgProc_RouteMsgSrvRet(msg *protomsg.RouteMsgSrvRet)
- func (this *Service_Proc) MsgProc_SessClosed(msg *protomsg.SessClosed)
- func (this *Service_Proc) MsgProc_SetServerStatusReq(msg *protomsg.SetServerStatusReq)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) GetClientSess ¶
获取会话
func (*Service) GetSelfInfo ¶
func (this *Service) GetSelfInfo() serverMgr.IServerInfo
获取自己服务器需要注册的信息
func (*Service) NewInfo ¶
func (this *Service) NewInfo(stype global.ServerTypeEnum) serverMgr.IServerInfo
根据类型生成一个新的IServerInfo对象,用与从etcd读出来后进行填充
func (*Service) OnRpcBefore ¶
处理RPC消息前
func (*Service) OnRpcReturn ¶
处理Srv消息回复
func (*Service) OnServerSessConnect ¶
func (this *Service) OnServerSessConnect(srvid uint64, srvtype global.ServerTypeEnum)
服务器连接成功
func (*Service) OnServerSessDisconnect ¶
服务器连接断开
func (*Service) OnSrvReturn ¶
处理Srv消息回复
func (*Service) PostMsgToClient ¶
通过目标服务器发消息给客户端
func (*Service) PostMsgToClientBuf ¶
通过目标服务器发消息给客户端
func (*Service) PostMsgToEntity ¶
发消息给其他服务器的对象
func (*Service) Run ¶
func (this *Service) Run()
//////////////////////////////////////////////////////////// 主协程调用
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)
设置服务器状态