This commit is contained in:
flswld
2023-03-29 17:48:03 +08:00
parent ef271412c6
commit b94a60d65b

View File

@@ -124,42 +124,42 @@ func NewHandle(messageQueue *mq.MessageQueue) (r *Handle) {
r = new(Handle) r = new(Handle)
r.messageQueue = messageQueue r.messageQueue = messageQueue
r.playerAcCtxMap = make(map[uint32]*AnticheatContext) r.playerAcCtxMap = make(map[uint32]*AnticheatContext)
r.run() go r.run()
return r return r
} }
func (h *Handle) run() { func (h *Handle) run() {
go func() { logger.Info("start handle")
for { for {
netMsg := <-h.messageQueue.GetNetMsg() netMsg := <-h.messageQueue.GetNetMsg()
switch netMsg.MsgType { switch netMsg.MsgType {
case mq.MsgTypeGame: case mq.MsgTypeGame:
if netMsg.OriginServerType != api.GATE { if netMsg.OriginServerType != api.GATE {
continue continue
} }
if netMsg.EventId != mq.NormalMsg { if netMsg.EventId != mq.NormalMsg {
continue continue
} }
gameMsg := netMsg.GameMsg gameMsg := netMsg.GameMsg
switch gameMsg.CmdId { switch gameMsg.CmdId {
case cmd.CombatInvocationsNotify: case cmd.CombatInvocationsNotify:
h.CombatInvocationsNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage) h.CombatInvocationsNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
case cmd.ToTheMoonEnterSceneReq: case cmd.ToTheMoonEnterSceneReq:
h.ToTheMoonEnterSceneReq(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage) h.ToTheMoonEnterSceneReq(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
} }
case mq.MsgTypeServer: case mq.MsgTypeServer:
serverMsg := netMsg.ServerMsg serverMsg := netMsg.ServerMsg
switch netMsg.EventId { switch netMsg.EventId {
case mq.ServerUserOnlineStateChangeNotify: case mq.ServerUserOnlineStateChangeNotify:
if serverMsg.IsOnline { logger.Info("player online state change, state: %v, uid: %v", serverMsg.IsOnline, serverMsg.UserId)
h.AddPlayerAcCtx(serverMsg.UserId) if serverMsg.IsOnline {
} else { h.AddPlayerAcCtx(serverMsg.UserId)
h.DelPlayerAcCtx(serverMsg.UserId) } else {
} h.DelPlayerAcCtx(serverMsg.UserId)
} }
} }
} }
}() }
} }
func (h *Handle) CombatInvocationsNotify(userId uint32, gateAppId string, payloadMsg pb.Message) { func (h *Handle) CombatInvocationsNotify(userId uint32, gateAppId string, payloadMsg pb.Message) {
@@ -170,12 +170,13 @@ func (h *Handle) CombatInvocationsNotify(userId uint32, gateAppId string, payloa
entityMoveInfo := new(proto.EntityMoveInfo) entityMoveInfo := new(proto.EntityMoveInfo)
err := pb.Unmarshal(entry.CombatData, entityMoveInfo) err := pb.Unmarshal(entry.CombatData, entityMoveInfo)
if err != nil { if err != nil {
logger.Error("parse EntityMoveInfo error: %v, uid: %v", err, userId)
continue continue
} }
if GetEntityType(entityMoveInfo.EntityId) != constant.ENTITY_TYPE_AVATAR { if GetEntityType(entityMoveInfo.EntityId) != constant.ENTITY_TYPE_AVATAR {
continue continue
} }
if entityMoveInfo.MotionInfo.Pos != nil { if entityMoveInfo.MotionInfo.Pos == nil {
continue continue
} }
// 玩家超速移动检测 // 玩家超速移动检测
@@ -209,6 +210,7 @@ func (h *Handle) ToTheMoonEnterSceneReq(userId uint32, gateAppId string, payload
return return
} }
ctx.sceneId = req.SceneId ctx.sceneId = req.SceneId
logger.Info("player enter scene: %v, uid: %v", req.SceneId, userId)
} }
func GetEntityType(entityId uint32) int { func GetEntityType(entityId uint32) int {