local BattleLogSetter = require("Battle/BattleLogSetter") local battle_compare_pb = require 'Proto/battle_compare_pb' local CompareSyncLogManager = { } local private = { --pvp 打印客户端log openClientLog = false, --pvp 上传对比log needSendToServerCompareLog = false } local FunctionDic = {} local ConvertFunctionDic = {} function CompareSyncLogManager.SetNeedSendToServerLog(isSend) --[[对性能影响过大轻易不要开启,确实有必要时再恢复private.needSendToServerCompareLog = isSend if isSend then NetManager.RegisterMsgCB(MessageEnums.MessageG2CNeedUploadFrameData, private.OnG2CNeedUploadFrameData) BattleLogSetter.CreateLogDir() else NetManager.RegisterMsgCB(MessageEnums.MessageG2CNeedUploadFrameData, private.NotUploadFrameLogFunction) end]] end function private.NotUploadFrameLogFunction() logging.log(LTAG.LOG, "[gws] : 服务器让上传对比日志 ,但是GM上的开关没开着,就不传了!") end function private.OnG2CNeedUploadFrameData(msg) --有可能是在还没战斗结束的时候就要发送 CompareSyncLogManager.TryColectLog(LuaConst.CheckBattleLogType.CollectEid2HeroID) BattleLogSetter.ForceWriteLog() local cloudType = msg.cloudType local endpoint = msg.ossEndPoint local ossKey = msg.ossKey local bucket = msg.ossBucket local ossSecret = msg.ossSecret local path = msg.path print("[GWS] 需要上传不一致log,bucket=" , bucket) BattleLogSetter.UploadFile(cloudType, bucket,endpoint,path,ossKey,ossSecret) end function CompareSyncLogManager.FrameEndLog() if private.openClientLog or private.needSendToServerCompareLog then if LevelManager.ShouldKeepSyncLevel() then for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do CompareSyncLogManager.TryColectLog( LuaConst.CheckBattleLogType.State , entity) end for i,entity in ipairs(LogicUpdateManager.EntityList_Normal) do CompareSyncLogManager.TryColectLog( LuaConst.CheckBattleLogType.State , entity) end end end end function CompareSyncLogManager.ClearLog() if private.needSendToServerCompareLog then if LevelManager.ShouldKeepSyncLevel() then BattleLogSetter.ClearLog() end end end function CompareSyncLogManager.TryColectLog( logType , ... ) if LevelManager.ShouldKeepSyncLevel() then FunctionDic[logType](...) end end --仅给C#调用,data是bytes function CompareSyncLogManager.ConvertLogListBytesToString( data ) local result = "" local compareListData = battle_compare_pb.CompareListData() compareListData:ParseFromString(data) for _,clientFrameData in ipairs(compareListData.datas) do local str = CompareSyncLogManager.ConvertLogBytesToString( clientFrameData ) result = result .. str .. "\n" end return result end function CompareSyncLogManager.ConvertLogListBytesToStringServer( data ) local result = {} local compareListData = battle_compare_pb.CompareListData() compareListData:ParseFromString(data) for _,clientFrameData in ipairs(compareListData.datas) do local str = CompareSyncLogManager.ConvertLogBytesToString( clientFrameData ) table.insert(result,str) end return result end function CompareSyncLogManager.ConvertLogBytesToString( clientFrameData ) --local clientFrameData = battle_compare_pb.ClientFrameData() --clientFrameData:ParseFromString(data) local type = clientFrameData.Type local func = ConvertFunctionDic[type] if func then local string = func(clientFrameData) return string end return "" end FunctionDic[LuaConst.CheckBattleLogType.State] = function (entity) local move = entity.components.move local targetID = -1 if entity.components.target and entity.components.target.Target then targetID = entity.components.target.Target._logicInitData.EntityID end if private.openClientLog then local logResult = string.format("eID:%d,f:%d,px:%d,pz:%d,fx:%d,fz:%d,mx:%d,mz:%d,Anim:%s, hp:%d,sa:%d ,tid:%d ,OL:%d", entity._logicInitData.EntityID, BattleDataGetter.GetCurFrameIndex(), move.LogicPos.x[1], move.LogicPos.z[1], move.LogicRotateDir.x[1], move.LogicRotateDir.z[1], move.LogicMoveDir.x[1], move.LogicMoveDir.z[1], entity.components.anim.CurAnimID, entity.components.attr.hp[1], entity.components.attr.sa[1], targetID, LevelPlayerManager.IsOnline(entity:GetPlayerID()) and 1 or 0 ) logging.crit(LTAG.PVP, logResult) end if private.needSendToServerCompareLog then local compareData = battle_compare_pb.ClientFrameData() compareData.EntityID = entity._logicInitData.EntityID compareData.CurFrame = BattleDataGetter.GetCurFrameIndex() compareData.Posx = move.LogicPos.x[1] compareData.Posz = move.LogicPos.z[1] compareData.Forwardx = move.LogicRotateDir.x[1] compareData.Forwardz = move.LogicRotateDir.z[1] compareData.MoveDirx = move.LogicMoveDir.x[1] compareData.MoveDirz = move.LogicMoveDir.z[1] compareData.CurAnimID = entity.components.anim.CurAnimID or "" compareData.CurHp = entity.components.attr.hp[1] compareData.IntParam1 = entity.components.attr.sa[1] compareData.IsOnLine = LevelPlayerManager.IsOnline(entity:GetPlayerID()) or false compareData.SetTarget = targetID compareData.Type = LuaConst.CheckBattleLogType.State BattleLogSetter.AddCompareDataToLogList(compareData) end end ConvertFunctionDic[LuaConst.CheckBattleLogType.State] = function (clientFrameData) local logResult = string.format("eID:%d,frame:%d,posX:%d,posZ:%d,forwardX:%d,forwardZ:%d,moveDirX:%d,moveDirZ:%d,Anim:%s, attr_hp:%d, attr_sa:%d ,targetEid:%d ,onLine:%d", clientFrameData.EntityID, clientFrameData.CurFrame, clientFrameData.Posx, clientFrameData.Posz, clientFrameData.Forwardx, clientFrameData.Forwardz, clientFrameData.MoveDirx, clientFrameData.MoveDirz, clientFrameData.CurAnimID, clientFrameData.CurHp, clientFrameData.IntParam1, clientFrameData.SetTarget, clientFrameData.IsOnLine and 1 or 0 ) return logResult end FunctionDic[LuaConst.CheckBattleLogType.OriginCmd] = function (...) local playerID, command = ... if private.needSendToServerCompareLog then local compareData = battle_compare_pb.ClientFrameData() compareData.EntityID = playerID compareData.CurFrame = command.Frame compareData.OriginMoveX = command.MoveDir.x[1] compareData.OriginMoveZ = command.MoveDir.z[1] compareData.OriginSkillPos = command.SkillIndex compareData.OriginSpecialCommand = command.SpecialCommand --compareData.result.OriginStickAngle = command.SkillJoystickDirAngle[1] compareData.OriginStickPosX = command.SkillJoystickPosX[1] compareData.OriginStickPosZ = command.SkillJoystickPosZ[1] compareData.Type = LuaConst.CheckBattleLogType.OriginCmd BattleLogSetter.AddCompareDataToLogList(compareData) end if private.openClientLog then local msg = string.format("G2C: playerID:%d,f:%d,mx:%d,mz:%d ,sid:%d" ,playerID ,command.Frame ,command.MoveDir.x[1],command.MoveDir.z[1] ,command.SkillIndex) logging.crit(LTAG.PVP, msg) end end ConvertFunctionDic[LuaConst.CheckBattleLogType.OriginCmd] = function (clientFrameData) local string = string.format("OriginCmd: playerID:%d,frame:%d,moveX:%d,moveZ:%d ,skill:%d ,SpecialCmd:%d,StickPx:%d ,StickPz:%d" , clientFrameData.EntityID , clientFrameData.CurFrame , clientFrameData.OriginMoveX, clientFrameData.OriginMoveZ , clientFrameData.OriginSkillPos, clientFrameData.OriginSpecialCommand, --clientFrameData.OriginStickAngle, clientFrameData.OriginStickPosX, clientFrameData.OriginStickPosZ) return string end FunctionDic[LuaConst.CheckBattleLogType.AfterCmd] = function (...) local playerID, command = ... if private.needSendToServerCompareLog then local compareData = battle_compare_pb.ClientFrameData() compareData.EntityID = playerID compareData.CurFrame = command.Frame compareData.AfterMoveX = command.MoveDir.x[1] compareData.AfterMoveZ = command.MoveDir.z[1] compareData.AfterSkillPos = command.SkillIndex compareData.Type = LuaConst.CheckBattleLogType.AfterCmd BattleLogSetter.AddCompareDataToLogList(compareData) end if private.openClientLog then local msg = string.format("G2C-Late: playerID:%d,frame:%d,mx:%d,mz:%d ,sid:%d" ,playerID ,command.Frame ,command.MoveDir.x[1],command.MoveDir.z[1] ,command.SkillIndex) logging.crit(LTAG.PVP, msg) end end ConvertFunctionDic[LuaConst.CheckBattleLogType.AfterCmd] = function (clientFrameData) local str = string.format("AfterAutoAICmd: playerID:%d,frame:%d,moveX:%d,moveZ:%d ,skill:%d" ,clientFrameData.EntityID , clientFrameData.CurFrame , clientFrameData.AfterMoveX, clientFrameData.AfterMoveZ, clientFrameData.AfterSkillPos) return str end FunctionDic[LuaConst.CheckBattleLogType.RandomNum] = function (...) local entity, index ,markid ,value = ... if private.needSendToServerCompareLog then local compareData = battle_compare_pb.ClientFrameData() compareData.RandomIndex = index compareData.EntityID = entity and entity._logicInitData.EntityID or -1 compareData.IntParam1 = markid compareData.StrParam = string.format("k-v:%d = %d",index ,value) compareData.Type = LuaConst.CheckBattleLogType.RandomNum BattleLogSetter.AddCompareDataToLogList(compareData) end if private.openClientLog then local eid = entity and entity._logicInitData.EntityID or -1 local msg = string.format("R:%d ,eid:%d ,mid:%d ,k-v:%d=%d", index,eid,markid,index,value) logging.crit(LTAG.PVP, msg) end end ConvertFunctionDic[LuaConst.CheckBattleLogType.RandomNum] = function (clientFrameData) local str= string.format("Random:%d ,entityId:%d ,frame:%d,markId:%d ,%s", clientFrameData.RandomIndex,clientFrameData.EntityID,clientFrameData.CurFrame ,clientFrameData.IntParam1 ,clientFrameData.StrParam) return str end FunctionDic[LuaConst.CheckBattleLogType.Missile] = function (...) local missile,hitEntityList = ... if #hitEntityList >0 then if private.openClientLog then local str = missile.Attacker._logicInitData.EntityID .. "的".. missile.MissileData.ID .."子弹,撞到的人有:" for i , hitEntity in ipairs(hitEntityList) do str = str .. hitEntity._logicInitData.EntityID end logging.crit(LTAG.PVP, str) end if private.needSendToServerCompareLog then local str = "" for i , hitEntity in ipairs(hitEntityList) do str = str .. hitEntity._logicInitData.EntityID .."|" end local compareData = battle_compare_pb.ClientFrameData() compareData.EntityID = missile.Attacker._logicInitData.EntityID compareData.IntParam1 = missile.MissileData.ID compareData.StrParam = str compareData.Type = LuaConst.CheckBattleLogType.Missile BattleLogSetter.AddCompareDataToLogList(compareData) end end end ConvertFunctionDic[LuaConst.CheckBattleLogType.Missile] = function (clientFrameData) local str = string.format("MissileTrigger: missileOwner_eid:%d ,missileID:%d ,beTrigger_entityIds:%s", clientFrameData.EntityID ,clientFrameData.IntParam1 ,clientFrameData.StrParam) return str end FunctionDic[LuaConst.CheckBattleLogType.CollectEid2HeroID] = function (...) if private.needSendToServerCompareLog then local str = "" for _,playerID in ipairs(LevelPlayerManager.SyncPlayerIDList) do local entitys = LevelPlayerManager.PlayersEntityTable[playerID] if entitys then for i,entity in ipairs(entitys) do str = str .. string.format("%d-%d |" ,entity.EntityID , entity:GetOriginCharacterData().ID) local adjutant = entity.components.adjutant.AdjutantEntity if adjutant then str = str .. string.format("%d-%d |" ,adjutant.EntityID , adjutant:GetOriginCharacterData().ID ) end end end end local compareData = battle_compare_pb.ClientFrameData() compareData.StrParam = str compareData.Type = LuaConst.CheckBattleLogType.CollectEid2HeroID BattleLogSetter.AddCompareDataToLogList(compareData) end if private.openClientLog then local str = "" for _,playerID in ipairs(LevelPlayerManager.SyncPlayerIDList) do local entitys = LevelPlayerManager.PlayersEntityTable[playerID] for i,entity in ipairs(entitys) do str = str .. string.format("%d-%d |" ,entity.EntityID , entity:GetOriginCharacterData().ID ) local adjutant = entity.components.adjutant.AdjutantEntity if adjutant then str = str .. string.format("%d-%d |" ,adjutant.EntityID , adjutant:GetOriginCharacterData().ID ) end end end logging.crit(LTAG.PVP, "entityID 与heroID关系:" .. str) end end ConvertFunctionDic[LuaConst.CheckBattleLogType.CollectEid2HeroID] = function (clientFrameData) local str= string.format("entity id to heroID ,%s", clientFrameData.StrParam) return str end return CompareSyncLogManager