68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package base
|
|
|
|
import (
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/protocol/machine"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"mongo.games.com/goserver/core/netlib"
|
|
"mongo.games.com/goserver/core/timer"
|
|
"mongo.games.com/goserver/srvlib"
|
|
"mongo.games.com/goserver/srvlib/protocol"
|
|
"time"
|
|
)
|
|
|
|
var SrvSessMgrSington = &SrvSessMgr{}
|
|
|
|
type SrvSessMgr struct {
|
|
}
|
|
|
|
// 注册事件
|
|
func (this *SrvSessMgr) OnRegiste(s *netlib.Session) {
|
|
attr := s.GetAttribute(srvlib.SessionAttributeServerInfo)
|
|
if attr != nil {
|
|
if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
|
|
if srvInfo.GetType() == srvlib.WorldServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (WorldSrv):", s)
|
|
} else if srvInfo.GetType() == srvlib.GateServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (GateSrv):", s)
|
|
} else if srvInfo.GetType() == srvlib.RankServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (RankSrv):", s)
|
|
} else if srvInfo.GetType() == int32(common.RobotServerType) {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (RobotSrv):", s)
|
|
NpcServerAgentSingleton.OnConnected()
|
|
} else if srvInfo.GetType() == 10 {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (Machine):", s)
|
|
timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
|
|
s.Send(int(machine.PacketID_Test), &machine.CSTest{
|
|
Ts: time.Now().Unix(),
|
|
})
|
|
return true
|
|
}), nil, 3*time.Second, 100)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 注销事件
|
|
func (this *SrvSessMgr) OnUnregiste(s *netlib.Session) {
|
|
attr := s.GetAttribute(srvlib.SessionAttributeServerInfo)
|
|
if attr != nil {
|
|
if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
|
|
if srvInfo.GetType() == srvlib.WorldServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnUnregiste (WorldSrv):", s)
|
|
} else if srvInfo.GetType() == srvlib.GateServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnUnregiste (GateSrv):", s)
|
|
} else if srvInfo.GetType() == srvlib.RankServerType {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnUnregiste (GateSrv):", s)
|
|
} else if srvInfo.GetType() == int32(common.RobotServerType) {
|
|
logger.Logger.Warn("(this *SrvSessMgr) OnUnregiste (RobotSrv):", s)
|
|
NpcServerAgentSingleton.OnDisconnected()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
srvlib.ServerSessionMgrSington.AddListener(SrvSessMgrSington)
|
|
}
|