| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838 |
- local LoginMgr = class('LoginMgr')
- local LoginStatus = {
- Error = 0,
- Clear = 1,
- OpenLoading = 2,
- OpenLoaded = 3,
- SdkInit = 4,
- SdkLogin = 5,
- CheckSpecialInfo = 6,
- CheckServer = 7,
- WaitClickEnter = 8,
- UpdateCheck = 9,
- CanEnterServerCheck = 10,
- ConnectGate = 11,
- GameLogin = 12,
- EnterGame = 13,
- InternalRelogin = 20,
- }
- local UseLoacdServerIDState =
- {
- None = -1, --沒有用
- Error = 0, --用了錯誤的ID
- Used = 1, -- 用了
- Success = 2,
- }
- function LoginMgr:ctor()
- self:RegisterNetEvents()
- self.UseLoacdServerIDState = UseLoacdServerIDState.None
- end
- function LoginMgr:Clear()
- self:Exit()
- end
- function LoginMgr:Destroy()
- self:Clear()
- self:UnRegisterNetEvents()
- end
- function LoginMgr:RegisterNetEvents()
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LOGIN_ACK, self.OnLoginAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LOGOUT_NTF, self.OnLogoutNtf,self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_KICK_OUT_NTF, self.OnKickoutNtf,self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_RECONNECT_ACK, self.OnReconnectAck,self)
- end
- function LoginMgr:UnRegisterNetEvents()
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_LOGIN_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_LOGOUT_NTF)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_KICK_OUT_NTF)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_RECONNECT_ACK)
- end
- function LoginMgr:OnLoginAck(data)
- self.logined = true
- self.loginErrorCode = data and data.error or nil
- if self.loginStatus == LoginStatus.GameLogin then
- self:StartEnterGame()
- end
- end
- function LoginMgr:OnLogoutNtf()
- ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- local data = {"LoginTips8", nil, nil, self, self.ReLogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:OnKickoutNtf(msgData)
- local noticeKey = 'LoginTips8'
- local noticeContent = nil
- if msgData then
- local remainTime = msgData.ban_end_time
- if remainTime and remainTime > 0 then
- remainTime = type(remainTime) == "number" and remainTime or #remainTime
- noticeContent = {DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, true)}
- end
- if msgData.error == Enum.NetErrorCode.ERROR_RELOGIN then
- noticeKey = 'LoginTips6'
- elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_BANED then
- if noticeContent then
- noticeKey = 'LoginTips10'
- end
- elseif msgData.error == Enum.NetErrorCode.ERROR_SERVER_KICK_CHEAT then
- if noticeContent then
- noticeKey = 'LoginTips10'
- end
- elseif msgData.error == Enum.NetErrorCode.ERROR_SERVER_MAINAIN then
- noticeKey = 'LoginTips7'
- elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_BANED_TYPE_PERSONALCHAT then
- noticeKey = 'LoginTips11'
- end
- end
- ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- local data = {noticeKey, noticeContent, nil, self, self.ReLogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:OnReconnectAck(msgData)
- if msgData then
- if msgData.error == Enum.NetErrorCode.ERROR_OK then
- ManagerContainer.LuaBattleMgr:SetReconnected(true)
- ManagerContainer.LuaBattleMgr:SendGetServerTimeReq()
- if ManagerContainer.FSMMgr:IsFightingState() then
- local battleMode = LuaBattleBridge.CurrentBattleMode()
- local battleSubMode = LuaBattleBridge.CurrentBattleSubMode()
- if battleMode == BattleMode.Versus
- or battleMode == BattleMode.Boss
- or battleMode == BattleMode.Time then
- local cmdId = nil
- if battleSubMode == BattleSubMode.Guild then
- cmdId = ProtoMsgId.CS_GUILD_BOSS_CHALLENGE_REQ
- elseif battleSubMode == BattleSubMode.ClimbingTower then
- cmdId = ProtoMsgId.CS_CLIMBING_TOWER_END_REQ
- elseif battleSubMode == BattleSubMode.Arena then
- cmdId = ProtoMsgId.CS_ARENA_RESULT_REQ
- elseif battleSubMode == BattleSubMode.HundredDojo then
- cmdId = ProtoMsgId.CS_DAO_CHANG100_CHALLENGE_RESULT_REQ
- end
- if not cmdId or not ManagerContainer.NetManager:HasCmdIdAtConfirmQueue(cmdId) then
- ManagerContainer.LuaGameMgr:EnterBattle(false)
- end
- end
- end
- elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_INVALID then
- self:ReconnectRefuse(true)
- else
- self:ReconnectRefuse()
- end
- else
- self:ReconnectRefuse()
- end
- end
- function LoginMgr:ReconnectRefuse(logout)
- ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- local data = {logout and "LoginTips12" or 'LoginTips13', nil, logout, self, self.ReLogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:ReconnectFail()
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- local data = {"LoginTips1", nil, nil, self, self.TryReconnect, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:TryReconnect()
- ManagerContainer.NetManager:StartReconnect()
- end
- ----------------------------- 以下是第一次登录或重新登录的流程 -----------------------------
- function LoginMgr:Enter(relogin)
- self:Exit()
- self.relogin = relogin
- self.preLoginStatus = nil
- self.loginStatus = LoginStatus.Clear
- self.logined = nil
- self.loginErrorCode = nil
- self.waitClicked = nil
- self.checkServerAgain = nil
- local leBianSDK = nil --Wenting.Lebian.LeBianSDK.instance
- if leBianSDK then
- local clientChId = leBianSDK:GetClientChId()
- if not clientChId then
- clientChId = ''
- end
- ManagerContainer.LuaGameMgr.channelName = clientChId
- end
- self.agreement = nil
- self.showNotify = true
- end
- function LoginMgr:Exit()
- self.relogin = nil
- self.stayTime = nil
- self.preLoginStatus = nil
- self.loginStatus = nil
- if self.checkWWW then
- self.checkWWW:Dispose()
- end
- self.checkWWW = nil
- self.logined = nil
- self.loginErrorCode = nil
- self.waitClicked = nil
- self.checkServerAgain = nil
- self.serverPorts = nil
- if self.endUpdateCheckCB then
- local leBianSDK = nil--Wenting.Lebian.LeBianSDK.instance
- if leBianSDK then
- leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback - self.endUpdateCheckCB
- self.endUpdateCheckCB = nil
- end
- end
- self.showNotify = nil
- end
- function LoginMgr:Update()
- if self.loginStatus == LoginStatus.Error then
- return
- end
- if self.loginStatus == LoginStatus.Clear then
- ManagerContainer:Reset()
- self:StartStartLoading()
- elseif ManagerContainer.LuaGameMgr.NetStatus == eNetType.NetType_None then
- self:NetWorkError()
- return
- elseif self.loginStatus == LoginStatus.OpenLoading then
- if ManagerContainer.LuaGameMgr.loadingPageOk then
- self:StartStartLoaded()
- end
- elseif self.loginStatus == LoginStatus.OpenLoaded then
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime <= 0 then
- self:StartSdkInit()
- end
- elseif self.loginStatus == LoginStatus.SdkInit then
- if ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Success then
- self:StartSdkLogin()
- elseif ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Fail then
- self:SdkInitFail()
- else
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime <= 0 then
- self:SdkInitFail()
- end
- end
- elseif self.loginStatus == LoginStatus.SdkLogin then
- if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
- self:StartCheckSpecialInfo()
- elseif ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Fail then
- self:SdkLoginFail()
- else
- if self.stayTime > 0 then
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime < 0 then
- self.waitClicked = nil
- end
- else
- if self.waitClicked then
- self:InternalRelogin()
- end
- end
- end
- elseif self.loginStatus == LoginStatus.CheckSpecialInfo then
- if self.checkWWW then
- if self.checkWWW.isDone then
- self:CheckSpecialInfoSuccess()
- else
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime <= 0 then
- self:CheckSpecialInfoFail()
- end
- end
- else
- self:CheckSpecialInfoFail()
- end
- elseif self.loginStatus == LoginStatus.CheckServer then
- if self.checkWWW then
- if self.checkWWW.isDone then
- self:CheckServerSuccess()
- else
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime <= 0 then
- self:CheckServerFail()
- end
- end
- else
- self:CheckServerFail()
- end
- elseif self.loginStatus == LoginStatus.WaitClickEnter then
- if self.waitClicked then
- self:EndWaitClickEnter()
- end
- elseif self.loginStatus == LoginStatus.UpdateCheck then
- elseif self.loginStatus == LoginStatus.CanEnterServerCheck then
- if ManagerContainer.LuaGameMgr.canEnterServerState == Enum.ParamState.Success then
- self:CheckCanEnterServerStateSuccess()
- elseif ManagerContainer.LuaGameMgr.canEnterServerState == Enum.ParamState.Fail then
- self:CheckCanEnterServerStateFail()
- end
- elseif self.loginStatus == LoginStatus.ConnectGate then
- if ManagerContainer.NetManager.connectGated == Enum.ParamState.Success then
- self:StartLoginGame()
- elseif ManagerContainer.NetManager.connectGated == Enum.ParamState.Fail then
- self:ReConnectGate()
- end
- elseif self.loginStatus == LoginStatus.GameLogin then
- if self.logined then
- self:StartEnterGame()
- else
- self.stayTime = self.stayTime - Time.deltaTime
- if self.stayTime <= 0 then
- self:LoginGameFail()
- end
- end
- elseif self.loginStatus == LoginStatus.InternalRelogin then
- self:StartStartLoading()
- end
- end
- function LoginMgr:GetTask()
- return nil
- end
- function LoginMgr:StartStartLoading()
- if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILanuch) then
- self:StartStartLoaded()
- else
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.OpenLoading
- ManagerContainer.LuaGameMgr:OpenLoading(Enum.UIPageName.UILanuch)
- end
- end
- function LoginMgr:StartStartLoaded()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.OpenLoaded
- self.stayTime = 0.5
- if self.relogin then
- ManagerContainer.LuaGameMgr:ReLoginClearData()
- end
- ManagerContainer.LuaUIMgr:CloseAllPagesExceptId(Enum.UIPageName.UILanuch)
- end
- function LoginMgr:StartSdkInit()
- if ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Success then
- self:StartSdkLogin()
- else
- SDKMgr.Instance:SetHttpCheckUrl(PlatformPack.URL_KEY)
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.SdkInit
- self.stayTime = 5
- ManagerContainer.LuaGameMgr.sdkInited = Enum.ParamState.None
- ManagerContainer.LuaGameMgr:SdkInit()
- end
- end
- function LoginMgr:SdkInitFail()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- local data = {"LoginTips2", nil, nil, self, self.InternalRelogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:StartSdkLogin()
- if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
- self:StartCheckSpecialInfo()
- else
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.SdkLogin
- self.stayTime = 5
- ManagerContainer.LuaGameMgr.sdkLogined = Enum.ParamState.None
- ManagerContainer.LuaGameMgr:SdkLogin()
- end
- end
- function LoginMgr:SdkLoginFail()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- local data = {"LoginTips3", nil, nil, self, self.InternalRelogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:StartCheckSpecialInfo()
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.CheckSpecialInfo
- self.stayTime = 5
- if self.checkWWW then
- self.checkWWW:Dispose()
- end
- local url = PlatformPack.SPECIAL_INFO_URL .. '?timesamp=' .. tostring(os.time())
- local platform = ManagerContainer.LuaGameMgr.platform
- if platform and platform ~= '' then
- url = url .. '&platform=' .. tostring(platform)
- end
- local subplatform = ManagerContainer.LuaGameMgr.channelName
- if subplatform and subplatform ~= '' then
- url = url .. '&sub_platform=' .. tostring(subplatform)
- end
- self.checkWWW = UnityEngine.WWW(url)
- end
- function LoginMgr:CheckSpecialInfoSuccess()
- if not self.checkWWW then
- self:CheckSpecialInfoFail()
- return
- end
- if self.checkWWW.error and self.checkWWW.error ~= '' then
- self:CheckSpecialInfoFail()
- return
- end
- local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, self.checkWWW.text)
- if ok then
- self.agreement = result.agreement
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SPECIAL_INFO_CHANGED)
- self:StartCheckServer()
- else
- LogError("[wboy] CheckSpecialInfoFail " .. tostring(self.checkWWW.text))
- self:CheckSpecialInfoFail()
- end
- end
- function LoginMgr:CheckSpecialInfoFail()
- if self.checkWWW then
- self.checkWWW:Dispose()
- end
- self.checkWWW = nil
- self:StartCheckServer()
- end
- function generateDeviceId()
- local seed = tostring({}):sub(7)
- math.randomseed(seed)
- math.random(); math.random(); math.random()
- local hexChars = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}
- local deviceId = ""
- for i=1,8 do
- deviceId = deviceId .. hexChars[math.random(16)]
- end
- for i=1,4 do
- deviceId = deviceId .. "-" .. hexChars[math.random(16)] .. hexChars[math.random(16)] .. hexChars[math.random(16)] .. hexChars[math.random(16)]
- end
- return deviceId
- end
- function LoginMgr:StartCheckServer(isAgain)
- self.checkServerAgain = isAgain
- local openId = ManagerContainer.LuaGameMgr.openId --"8bb8f18b-aeef-1b79-db12-a825"--generateDeviceId()--
- --LogError("OpenID = "..openId);
- if not openId or openId == '' then
- openId = UnityEngine.PlayerPrefs.GetString("LoginName")
- end
- if not openId or openId == '' then
- openId = ManagerContainer.LuaGameMgr.DeviceId
- end
- ManagerContainer.LuaGameMgr.openId = openId
- if Constant.SERVER_FORCE_INFO then
- self:SetServerInfo(Constant.SERVER_FORCE_INFO)
- if isAgain then
- self:StartCheckCanEnterServerState()
- else
- self:StartWaitClickEnter()
- end
- return
- end
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- self.stayTime = 5
- local serverId = ManagerContainer.LuaGameMgr.serverData.id
- --LogWarning('serverId-----'..serverId)
- if(serverId == nil and self.UseLoacdServerIDState ~= UseLoacdServerIDState.Error)then
- serverId = ManagerContainer.LuaGameMgr:GetServerID()
- --serverId = 3;
- --LogWarning('serverId-----'..serverId)
- self.UseLoacdServerIDState = UseLoacdServerIDState.Used;
- end
- local url = PlatformPack.SERVERLIST_URL
- if serverId and serverId > 0 then
- url = url .. "?type=21&id=" .. tostring(serverId)
- else
- url = url .. "?"
- end
- url = ManagerContainer.LuaGameMgr:ComposeCommonServerInfo(url)
-
- if self.checkWWW then
- self.checkWWW:Dispose()
- end
- LogWarning('checkWWW-----'..url)
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.CheckServer
- self.checkWWW = UnityEngine.WWW(url)
- end
- function LoginMgr:CheckServerFail()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- if self.checkWWW then
- self.checkWWW:Dispose()
- end
- self.checkWWW = nil
- self.checkServerAgain = nil
-
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- local data = {"LoginTips4", nil, nil, self, self.InternalRelogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- ManagerContainer.LuaGameMgr:ClearServerData()
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
- end
- function LoginMgr:CheckServerSuccess()
- if not self.checkWWW then
- self:CheckServerFail()
- return
- end
- if self.checkWWW.error and self.checkWWW.error ~= '' then
- self:CheckServerFail()
- return
- end
- local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, self.checkWWW.text)
- LogError("[wboy] CheckServer " .. tostring(self.checkWWW.text))
- if ok then
-
- self:SetServerInfo(result)
- self.checkWWW:Dispose()
- self.checkWWW = nil
- if result.err and self.UseLoacdServerIDState == UseLoacdServerIDState.Used then
- self.UseLoacdServerIDState = UseLoacdServerIDState.Error
- ManagerContainer.LuaGameMgr:SetServerID(-1)
- elseif self.UseLoacdServerIDState == UseLoacdServerIDState.Used or self.UseLoacdServerIDState == UseLoacdServerIDState.Error then
- self.UseLoacdServerIDState = UseLoacdServerIDState.Success
- end
-
- if self.checkServerAgain then
- self.checkServerAgain = nil
- self:StartCheckCanEnterServerState()
- else
- self:StartWaitClickEnter()
- end
- else
- LogError("[wboy] CheckServerFail " .. tostring(self.checkWWW.text))
- self:CheckServerFail()
- end
- end
- function LoginMgr:SetServerInfo(server)
- ManagerContainer.LuaGameMgr:InitServerData(server.ServerId, server.ServerName, server.Ip, server.Port, server.State)
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
- end
- function LoginMgr:StartWaitClickEnter()
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.WaitClickEnter
- self.waitClicked = nil
- local serverData = ManagerContainer.LuaGameMgr.serverData
- if serverData and serverData.id and serverData.id > 0 and self.showNotify then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINotifyTips)
- self.showNotify = false
- end
- end
- function LoginMgr:EndWaitClickEnter()
- if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
- if self:IsAgreement() then
- local isOn = ManagerContainer.PlayerPrefsMgr:GetGlobalBoolean(Constant.AGREEMENT_RECORD_KEY, false)
- if not isOn then
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GameLogin19')
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.WaitClickEnter
- self.waitClicked = nil
- return
- end
- end
- self:StartUpdateCheck()
- else
- self:InternalRelogin()
- end
- end
- function LoginMgr:StartUpdateCheck()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.UpdateCheck
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- local leBianSDK = nil --Wenting.Lebian.LeBianSDK.instance
- if leBianSDK then
- if not self.endUpdateCheckCB then
- self.endUpdateCheckCB = System.Action_Wenting_Lebian_QueryUpdateErrorCode(self.EndUpdateCheck, self)
- end
- leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback + self.endUpdateCheckCB
- leBianSDK:QueryUpdate()
- else
- self:EndUpdateCheck(Wenting.Lebian.QueryUpdateErrorCode.Error)
- end
- end
- function LoginMgr:EndUpdateCheck(resultCode)
- local leBianSDK = nil -- Wenting.Lebian.LeBianSDK.instance
- if leBianSDK then
- if self.endUpdateCheckCB then
- leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback - self.endUpdateCheckCB
- self.endUpdateCheckCB = nil
- end
- local QueryUpdateErrorCode = Wenting.Lebian.QueryUpdateErrorCode
- if resultCode == QueryUpdateErrorCode.NoUpdate then
- self:StartCheckServer(true)
- return
- elseif resultCode == QueryUpdateErrorCode.Update then
- self:StartCheckServer(true)
- return
- elseif resultCode == QueryUpdateErrorCode.ForceUpdate then
- -- 停止后续流程
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- return
- end
- end
- -- self:ResetClickState()
- --self:ErrorNoticeDisplay('GameLogin20')
- self:StartCheckServer(true)
- end
- function LoginMgr:StartCheckCanEnterServerState()
- if not SDKMgr.Instance:HasCanEnterServerJudge() then
- self:StartConnectGate()
- return
- end
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.CanEnterServerCheck
- ManagerContainer.LuaGameMgr.canEnterServerState = Enum.ParamState.None
- local serverData = ManagerContainer.LuaGameMgr.serverData
- SDKMgr.Instance:CanEnterServerJudge(serverData.id, serverData.name)
- end
- function LoginMgr:CheckCanEnterServerStateSuccess()
- self:StartConnectGate()
- end
- function LoginMgr:CheckCanEnterServerStateFail()
- self:ResetClickState()
- end
- function LoginMgr:StartConnectGate()
- local serverData = ManagerContainer.LuaGameMgr.serverData
- if serverData.state == Enum.ServerState.Maintain then
- self:StartMaintain()
- return
- elseif serverData.state == Enum.ServerState.Full then
- self:ConnectGateFail()
- return
- end
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.ConnectGate
- ManagerContainer.NetManager.connectGated = Enum.ParamState.None
- self.logined = nil
- self.loginErrorCode = nil
- local serverPorts = serverData.ports
- local len = serverPorts and #serverPorts or 0
- if len <= 0 then
- self:ConnectGateFail()
- elseif len <= 1 then
- serverData.portidx = 1
- ManagerContainer.NetManager:ConnectGate(serverData.ip, serverPorts[1])
- else
- math.randomseed(os.time())
- local serverPortIdx = math.random(len)
- serverData.portidx = serverPortIdx
- self.serverPorts = clone(serverData.ports)
- ManagerContainer.NetManager:ConnectGate(serverData.ip, serverPorts[serverPortIdx])
- end
- end
- function LoginMgr:ReConnectGate()
- ManagerContainer.NetManager.connectGated = Enum.ParamState.None
- self.logined = nil
- self.loginErrorCode = nil
- local serverData = ManagerContainer.LuaGameMgr.serverData
- if serverData.state == Enum.ServerState.Maintain then
- self:StartMaintain()
- return
- elseif serverData.state == Enum.ServerState.Full then
- self:ConnectGateFail()
- return
- end
- local len = self.serverPorts and #self.serverPorts or 0
- if len <= 0 then
- self:ConnectGateFail()
- else
- local serverPortIdx = serverData.portidx
- if serverPortIdx then
- table.remove(self.serverPorts, serverPortIdx)
- end
- len = #self.serverPorts
- if len <= 0 then
- self:ConnectGateFail()
- else
- serverPortIdx = math.random(len)
- serverData.portidx = serverPortIdx
- ManagerContainer.NetManager:ConnectGate(serverData.ip, self.serverPorts[serverPortIdx])
- end
- end
- end
- function LoginMgr:ConnectGateFail()
- self:ResetClickState()
- self:ErrorNoticeDisplay('GameLogin21')
- end
- function LoginMgr:StartMaintain()
- self:ResetClickState()
- self:ErrorNoticeDisplay('GameLogin11')
- end
- function LoginMgr:StartLoginGame()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.GameLogin
- self.stayTime = 10
- end
- function LoginMgr:LoginGameFail(error,...)
- self:ResetClickState()
- if not error then
- error = 'GameLogin14'
- end
- self:ErrorNoticeDisplay(error, ...)
- end
- function LoginMgr:StartEnterGame()
- local loginErrorCode = self.loginErrorCode
- if loginErrorCode == Enum.NetErrorCode.ERROR_OK then
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.EnterGame
- ManagerContainer.LuaUIMgr:CloseAllPagesExceptId(Enum.UIPageName.UILanuch)
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin)
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_NOT_FOUND then
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.EnterGame
- ManagerContainer.LuaGameMgr:EnterCreateRole(false)
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_NOT_FOUND_NEED_ACTIVE_CODE then
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.EnterGame
- ManagerContainer.LuaGameMgr:EnterCreateRole(true)
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_SDK_ACCOUNT_INVALID then
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- local data = {"LoginTips9", nil, true, self, self.ReLogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_GAME_VERSION then
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- local data = {"LoginTips5", nil, nil, self, self.InternalRelogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_BANED then
- self:GameBanedError()
- elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_BANED_TYPE_PERSONALCHAT then
- self:GameBanedError()
- else
- local langStr = string.formatbykey(loginErrorCode)
- if not langStr or langStr == '' then
- self:LoginGameFail(loginErrorCode)
- else
- self:ResetClickState()
- end
- end
- end
- function LoginMgr:GameBanedError()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- end
- function LoginMgr:ResetClickState()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- self:StartWaitClickEnter()
- end
- function LoginMgr:IsLoginWaiting()
- return (not self.loginStatus or self.loginStatus == LoginStatus.WaitClickEnter)
- end
- function LoginMgr:NetWorkError()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.Error
- ManagerContainer.NetManager:ResetNetMgr()
- ManagerContainer.LuaUIMgr:CloseNetWaiting()
- local data = {"LoginTips1", nil, nil, self, self.InternalRelogin, self.QuitGame}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
- end
- function LoginMgr:ErrorNoticeDisplay(error, ...)
- if not ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIErrorTips) then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIErrorTips, {errorId=error,params = {...}}, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 11)
- else
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ERROR_DESC_DISPLAY, {errorId=error,params = {...}})
- end
- end
- function LoginMgr:InternalRelogin()
- self.preLoginStatus = self.loginStatus
- self.loginStatus = LoginStatus.InternalRelogin
- ManagerContainer.LuaUIMgr:ShowNetWaiting()
- ManagerContainer.LuaGameMgr:ClearServerData()
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
- end
- function LoginMgr:ReLogin(logout)
- if logout and ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
- ManagerContainer.LuaGameMgr:SdkLogout()
- else
- ManagerContainer.LuaGameMgr:ClearServerData()
- ManagerContainer.LuaGameMgr:ReLogin()
- end
- end
- function LoginMgr:QuitGame()
- ManagerContainer.LuaGameMgr:QuitGame(true)
- return true
- end
- function LoginMgr:IsAgreement()
- return self.agreement and self.agreement ~= '' or false
- end
- function LoginMgr:GetAgreement()
- return self.agreement
- end
- return LoginMgr
|