| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- local GameWorldController = class("GameWorldController", function ()
- return cc.Layer:create()
- end)
- local SCENE_GRAPH_FILE = "scene/GameWorld.csb"
- local CHECK_GAME_ACTIVE_TIME = 1800
- function GameWorldController:ctor()
- self.mSpeedCheatCount = 0
- self.mElapsedT = 0
- self.mLastElapsedT = 0
- self.mLoopCount = 0
- self.mHeartBeatT = os.time()
- self.mActiveT = os.time()
- self.mUnActiveState = false
- self._restart = false
- self._leaveWorld = false
- self:RegisterMsgHandler()
- end
- function GameWorldController:destory()
- end
- function GameWorldController.create()
- local layer = GameWorldController.new()
- if layer:Init() then
- return layer
- else
- return nil
- end
- end
- -----------------------------------------------------------------------------
- function GameWorldController:Init()
- --********* Mis
- self:scheduleUpdateWithPriorityLua(handler(self, self.update), 0)
- return true
- end
- -----------------------------------------------------------------------------
- function GameWorldController:handleMessage(msg)
- -- Message 885, anti SPEED cheat
- local hdr = msg:GetHeader()
- local dataSourceSize = msg:GetDataLength()
- local dataSource = msg:GetData()
- local sliceStr = dataSource:ReadString( dataSourceSize )
- local jsonData = string.split(sliceStr , "/")
- local localElapsedSinceLastMsg = self.mElapsedT - self.mLastElapsedT
- local serverElapsedSinceLastMsg = tonumber( jsonData[3] )
- local serverCurrTime = tonumber( jsonData[2] )
-
- local timeDiff = localElapsedSinceLastMsg - serverElapsedSinceLastMsg;
-
- --云真机启动
- if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
- return
- end
- if self.mElapsedT == self.mLastElapsedT and self.mLastElapsedT > 0 then -- 885 message may be accumulated ( e.g. app process be suspend by onStop/onResume ) -- Make sure it is not initial state.
-
- self.mSpeedCheatCount = 0
- return 1
- end
- if self.s_isRoot and timeDiff >= hdr.param2 and 0 < self.mElapsedT and 1 == hdr.param1 and self.mLoopCount < 200 then
- self.mSpeedCheatCount = self.mSpeedCheatCount + 1
- if hdr.param3 <= self.mSpeedCheatCount then
- if not global.isDebugMode then
- -- issue, can not restart in handle msg
- self._restart = true
- else
- print( "Speed cheat has detected" )
- end
- end
- else
- -- cold down
- self.mSpeedCheatCount = ( 0 >= self.mSpeedCheatCount ) and 0 or (self.mSpeedCheatCount - 1)
- end
-
- -- Sync time line
- self.mElapsedT = serverCurrTime
- self.mLastElapsedT = self.mElapsedT
- self.mLoopCount = 0
- return 1
- end
- function GameWorldController:RespGameWorldInfoInit(msg)
- global.Facade:sendNotification(global.NoticeTable.GameWorldInfoInitBegin)
- -- 开始初始化
- local jsonData = ParseRawMsgToJson( msg )
- local header = msg:GetHeader()
- local data = {
- jsonData = jsonData,
- header = header
- }
- global.Facade:sendNotification(global.NoticeTable.GameWorldInfoInit, data)
- local LoginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
- LoginProxy:SyncVersion()
-
- if LoginProxy and LoginProxy.SendDeviceInfo then
- LoginProxy:SendDeviceInfo()
- end
- if LoginProxy and LoginProxy.SendSDKInfo then
- LoginProxy:SendSDKInfo()
- end
- end
- function GameWorldController:RegisterMsgHandler()
- LuaRegisterMsgHandler(885, handler( self, self.handleMessage) )
- -----------------------------------------------------------------------------
- LuaRegisterMsgHandler(global.MsgType.MSG_SC_GAME_WORLD_INFO_INIT, handler(self, self.RespGameWorldInfoInit))
- end
- -----------------------------------------------------------------------------
- function GameWorldController:CheckHeartBeat()
- local dValue = math.abs(os.time() - self.mHeartBeatT)
- if dValue >= 60 then
- self.mHeartBeatT = os.time()
- end
- if os.time() - self.mHeartBeatT < 10 then
- return
- end
- self.mHeartBeatT = os.time()
- -- 发心跳
- LuaSendMsg( global.MsgType.MSG_CS_HEART_BEAT_KEEP, self.mHeartBeatT )
- end
- function GameWorldController:OnGameSuspend()
- -- 暂停前发心跳 发心跳
- -- 重置时间戳
- self.mHeartBeatT = os.time()
- -- 发心跳
- LuaSendMsg( global.MsgType.MSG_CS_HEART_BEAT_KEEP, self.mHeartBeatT )
- end
- function GameWorldController:OnGameLeaveWorld()
- -- issue, can not leaveWorld in handle msg
- self._leaveWorld = true
- end
- -----------------------
- function GameWorldController:GetFilterMsgTime()
- if not self._filterMsgTime then
- local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
- self._filterMsgTime = envProxy:GetCustomDataByKey("filterMsgTime") or CHECK_GAME_ACTIVE_TIME
- end
- return self._filterMsgTime
- end
- function GameWorldController:CheckGameUnActive()
- local dT = os.time() - self.mActiveT
- if not self.mUnActiveState and dT > self:GetFilterMsgTime() then
- local loginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
- loginProxy:SyncVersion(true)
- self.mUnActiveState = true
- end
- end
- function GameWorldController:OnGameActive()
- self.mActiveT = os.time()
- if self.mUnActiveState then
- local loginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
- loginProxy:SyncVersion(false)
- self.mUnActiveState = false
- end
- end
- function GameWorldController:update(delta)
- local dI = math.floor( delta * 1000.0 )
- self.mElapsedT = self.mElapsedT + dI
- self.mLoopCount = self.mLoopCount + 1
- if self._restart then
- self._restart = false
- global.L_NativeBridgeManager:GN_accountLogout()
- global.Facade:sendNotification(global.NoticeTable.RestartGame)
- return
- end
- if self._leaveWorld then
- self._leaveWorld = false
- global.Facade:sendNotification(global.NoticeTable.LeaveWorld)
- return
- end
- -----------------------------------------------------------------------------
- -- 网络收发消息包
- global.gameEnvironment:GetNetClient():Tick()
- -----------------------------------------------------------------------------
- -- drop item
- global.dropItemController:Tick( delta )
- -----------------------------------------------------------------------------
- -- 技能CD
- global.CalcSkillCDMediator:Tick( delta )
- -- 连击技能CD
- global.CalcComboSkillCDMediator:Tick(delta)
- -- 角色
- global.actorManager:Tick( delta )
- -- 场景
- global.sceneManager:Tick(delta)
-
- --
- global.gameMapController:Tick( delta )
- -- actor refresh
- global.actorRefreshController:Tick(delta)
- -----------------------------------------------------------------------------
- -- 技能
- global.skillManager:Tick( delta )
- -- buff
- global.BuffManager:Tick(delta)
- -- effect
- global.ActorEffectManager:Tick(delta)
-
- -----------------------------------------------------------------------------
- -- sequence animation manager
- global.FrameAnimManager:Tick( delta )
- -- downloader
- global.ResDownloader:Tick( delta )
- -- heartBeat
- self:CheckHeartBeat()
- -- active
- self:CheckGameUnActive()
- end
- return GameWorldController
|