LoginMgr.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. local LoginMgr = class('LoginMgr')
  2. local LoginStatus = {
  3. Error = 0,
  4. Clear = 1,
  5. OpenLoading = 2,
  6. OpenLoaded = 3,
  7. SdkInit = 4,
  8. SdkLogin = 5,
  9. CheckSpecialInfo = 6,
  10. CheckServer = 7,
  11. WaitClickEnter = 8,
  12. UpdateCheck = 9,
  13. CanEnterServerCheck = 10,
  14. ConnectGate = 11,
  15. GameLogin = 12,
  16. EnterGame = 13,
  17. InternalRelogin = 20,
  18. }
  19. local UseLoacdServerIDState =
  20. {
  21. None = -1, --沒有用
  22. Error = 0, --用了錯誤的ID
  23. Used = 1, -- 用了
  24. Success = 2,
  25. }
  26. function LoginMgr:ctor()
  27. self:RegisterNetEvents()
  28. self.UseLoacdServerIDState = UseLoacdServerIDState.None
  29. end
  30. function LoginMgr:Clear()
  31. self:Exit()
  32. end
  33. function LoginMgr:Destroy()
  34. self:Clear()
  35. self:UnRegisterNetEvents()
  36. end
  37. function LoginMgr:RegisterNetEvents()
  38. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LOGIN_ACK, self.OnLoginAck, self)
  39. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LOGOUT_NTF, self.OnLogoutNtf,self)
  40. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_KICK_OUT_NTF, self.OnKickoutNtf,self)
  41. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_RECONNECT_ACK, self.OnReconnectAck,self)
  42. end
  43. function LoginMgr:UnRegisterNetEvents()
  44. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_LOGIN_ACK)
  45. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_LOGOUT_NTF)
  46. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_KICK_OUT_NTF)
  47. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_RECONNECT_ACK)
  48. end
  49. function LoginMgr:OnLoginAck(data)
  50. self.logined = true
  51. self.loginErrorCode = data and data.error or nil
  52. if self.loginStatus == LoginStatus.GameLogin then
  53. self:StartEnterGame()
  54. end
  55. end
  56. function LoginMgr:OnLogoutNtf()
  57. ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
  58. ManagerContainer.NetManager:ResetNetMgr()
  59. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  60. local data = {"LoginTips8", nil, nil, self, self.ReLogin, self.QuitGame}
  61. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  62. end
  63. function LoginMgr:OnKickoutNtf(msgData)
  64. local noticeKey = 'LoginTips8'
  65. local noticeContent = nil
  66. if msgData then
  67. local remainTime = msgData.ban_end_time
  68. if remainTime and remainTime > 0 then
  69. remainTime = type(remainTime) == "number" and remainTime or #remainTime
  70. noticeContent = {DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, true)}
  71. end
  72. if msgData.error == Enum.NetErrorCode.ERROR_RELOGIN then
  73. noticeKey = 'LoginTips6'
  74. elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_BANED then
  75. if noticeContent then
  76. noticeKey = 'LoginTips10'
  77. end
  78. elseif msgData.error == Enum.NetErrorCode.ERROR_SERVER_KICK_CHEAT then
  79. if noticeContent then
  80. noticeKey = 'LoginTips10'
  81. end
  82. elseif msgData.error == Enum.NetErrorCode.ERROR_SERVER_MAINAIN then
  83. noticeKey = 'LoginTips7'
  84. elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_BANED_TYPE_PERSONALCHAT then
  85. noticeKey = 'LoginTips11'
  86. end
  87. end
  88. ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
  89. ManagerContainer.NetManager:ResetNetMgr()
  90. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  91. local data = {noticeKey, noticeContent, nil, self, self.ReLogin, self.QuitGame}
  92. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  93. end
  94. function LoginMgr:OnReconnectAck(msgData)
  95. if msgData then
  96. if msgData.error == Enum.NetErrorCode.ERROR_OK then
  97. ManagerContainer.LuaBattleMgr:SetReconnected(true)
  98. ManagerContainer.LuaBattleMgr:SendGetServerTimeReq()
  99. if ManagerContainer.FSMMgr:IsFightingState() then
  100. local battleMode = LuaBattleBridge.CurrentBattleMode()
  101. local battleSubMode = LuaBattleBridge.CurrentBattleSubMode()
  102. if battleMode == BattleMode.Versus
  103. or battleMode == BattleMode.Boss
  104. or battleMode == BattleMode.Time then
  105. local cmdId = nil
  106. if battleSubMode == BattleSubMode.Guild then
  107. cmdId = ProtoMsgId.CS_GUILD_BOSS_CHALLENGE_REQ
  108. elseif battleSubMode == BattleSubMode.ClimbingTower then
  109. cmdId = ProtoMsgId.CS_CLIMBING_TOWER_END_REQ
  110. elseif battleSubMode == BattleSubMode.Arena then
  111. cmdId = ProtoMsgId.CS_ARENA_RESULT_REQ
  112. elseif battleSubMode == BattleSubMode.HundredDojo then
  113. cmdId = ProtoMsgId.CS_DAO_CHANG100_CHALLENGE_RESULT_REQ
  114. end
  115. if not cmdId or not ManagerContainer.NetManager:HasCmdIdAtConfirmQueue(cmdId) then
  116. ManagerContainer.LuaGameMgr:EnterBattle(false)
  117. end
  118. end
  119. end
  120. elseif msgData.error == Enum.NetErrorCode.ERROR_ROLE_INVALID then
  121. self:ReconnectRefuse(true)
  122. else
  123. self:ReconnectRefuse()
  124. end
  125. else
  126. self:ReconnectRefuse()
  127. end
  128. end
  129. function LoginMgr:ReconnectRefuse(logout)
  130. ManagerContainer.LuaBattleMgr:StopSyncServerTimeTimer()
  131. ManagerContainer.NetManager:ResetNetMgr()
  132. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  133. local data = {logout and "LoginTips12" or 'LoginTips13', nil, logout, self, self.ReLogin, self.QuitGame}
  134. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  135. end
  136. function LoginMgr:ReconnectFail()
  137. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  138. local data = {"LoginTips1", nil, nil, self, self.TryReconnect, self.QuitGame}
  139. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  140. end
  141. function LoginMgr:TryReconnect()
  142. ManagerContainer.NetManager:StartReconnect()
  143. end
  144. ----------------------------- 以下是第一次登录或重新登录的流程 -----------------------------
  145. function LoginMgr:Enter(relogin)
  146. self:Exit()
  147. self.relogin = relogin
  148. self.preLoginStatus = nil
  149. self.loginStatus = LoginStatus.Clear
  150. self.logined = nil
  151. self.loginErrorCode = nil
  152. self.waitClicked = nil
  153. self.checkServerAgain = nil
  154. local leBianSDK = nil --Wenting.Lebian.LeBianSDK.instance
  155. if leBianSDK then
  156. local clientChId = leBianSDK:GetClientChId()
  157. if not clientChId then
  158. clientChId = ''
  159. end
  160. ManagerContainer.LuaGameMgr.channelName = clientChId
  161. end
  162. self.agreement = nil
  163. self.showNotify = true
  164. end
  165. function LoginMgr:Exit()
  166. self.relogin = nil
  167. self.stayTime = nil
  168. self.preLoginStatus = nil
  169. self.loginStatus = nil
  170. if self.checkWWW then
  171. self.checkWWW:Dispose()
  172. end
  173. self.checkWWW = nil
  174. self.logined = nil
  175. self.loginErrorCode = nil
  176. self.waitClicked = nil
  177. self.checkServerAgain = nil
  178. self.serverPorts = nil
  179. if self.endUpdateCheckCB then
  180. local leBianSDK = nil--Wenting.Lebian.LeBianSDK.instance
  181. if leBianSDK then
  182. leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback - self.endUpdateCheckCB
  183. self.endUpdateCheckCB = nil
  184. end
  185. end
  186. self.showNotify = nil
  187. end
  188. function LoginMgr:Update()
  189. if self.loginStatus == LoginStatus.Error then
  190. return
  191. end
  192. if self.loginStatus == LoginStatus.Clear then
  193. ManagerContainer:Reset()
  194. self:StartStartLoading()
  195. elseif ManagerContainer.LuaGameMgr.NetStatus == eNetType.NetType_None then
  196. self:NetWorkError()
  197. return
  198. elseif self.loginStatus == LoginStatus.OpenLoading then
  199. if ManagerContainer.LuaGameMgr.loadingPageOk then
  200. self:StartStartLoaded()
  201. end
  202. elseif self.loginStatus == LoginStatus.OpenLoaded then
  203. self.stayTime = self.stayTime - Time.deltaTime
  204. if self.stayTime <= 0 then
  205. self:StartSdkInit()
  206. end
  207. elseif self.loginStatus == LoginStatus.SdkInit then
  208. if ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Success then
  209. self:StartSdkLogin()
  210. elseif ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Fail then
  211. self:SdkInitFail()
  212. else
  213. self.stayTime = self.stayTime - Time.deltaTime
  214. if self.stayTime <= 0 then
  215. self:SdkInitFail()
  216. end
  217. end
  218. elseif self.loginStatus == LoginStatus.SdkLogin then
  219. if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
  220. self:StartCheckSpecialInfo()
  221. elseif ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Fail then
  222. self:SdkLoginFail()
  223. else
  224. if self.stayTime > 0 then
  225. self.stayTime = self.stayTime - Time.deltaTime
  226. if self.stayTime < 0 then
  227. self.waitClicked = nil
  228. end
  229. else
  230. if self.waitClicked then
  231. self:InternalRelogin()
  232. end
  233. end
  234. end
  235. elseif self.loginStatus == LoginStatus.CheckSpecialInfo then
  236. if self.checkWWW then
  237. if self.checkWWW.isDone then
  238. self:CheckSpecialInfoSuccess()
  239. else
  240. self.stayTime = self.stayTime - Time.deltaTime
  241. if self.stayTime <= 0 then
  242. self:CheckSpecialInfoFail()
  243. end
  244. end
  245. else
  246. self:CheckSpecialInfoFail()
  247. end
  248. elseif self.loginStatus == LoginStatus.CheckServer then
  249. if self.checkWWW then
  250. if self.checkWWW.isDone then
  251. self:CheckServerSuccess()
  252. else
  253. self.stayTime = self.stayTime - Time.deltaTime
  254. if self.stayTime <= 0 then
  255. self:CheckServerFail()
  256. end
  257. end
  258. else
  259. self:CheckServerFail()
  260. end
  261. elseif self.loginStatus == LoginStatus.WaitClickEnter then
  262. if self.waitClicked then
  263. self:EndWaitClickEnter()
  264. end
  265. elseif self.loginStatus == LoginStatus.UpdateCheck then
  266. elseif self.loginStatus == LoginStatus.CanEnterServerCheck then
  267. if ManagerContainer.LuaGameMgr.canEnterServerState == Enum.ParamState.Success then
  268. self:CheckCanEnterServerStateSuccess()
  269. elseif ManagerContainer.LuaGameMgr.canEnterServerState == Enum.ParamState.Fail then
  270. self:CheckCanEnterServerStateFail()
  271. end
  272. elseif self.loginStatus == LoginStatus.ConnectGate then
  273. if ManagerContainer.NetManager.connectGated == Enum.ParamState.Success then
  274. self:StartLoginGame()
  275. elseif ManagerContainer.NetManager.connectGated == Enum.ParamState.Fail then
  276. self:ReConnectGate()
  277. end
  278. elseif self.loginStatus == LoginStatus.GameLogin then
  279. if self.logined then
  280. self:StartEnterGame()
  281. else
  282. self.stayTime = self.stayTime - Time.deltaTime
  283. if self.stayTime <= 0 then
  284. self:LoginGameFail()
  285. end
  286. end
  287. elseif self.loginStatus == LoginStatus.InternalRelogin then
  288. self:StartStartLoading()
  289. end
  290. end
  291. function LoginMgr:GetTask()
  292. return nil
  293. end
  294. function LoginMgr:StartStartLoading()
  295. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILanuch) then
  296. self:StartStartLoaded()
  297. else
  298. self.preLoginStatus = self.loginStatus
  299. self.loginStatus = LoginStatus.OpenLoading
  300. ManagerContainer.LuaGameMgr:OpenLoading(Enum.UIPageName.UILanuch)
  301. end
  302. end
  303. function LoginMgr:StartStartLoaded()
  304. self.preLoginStatus = self.loginStatus
  305. self.loginStatus = LoginStatus.OpenLoaded
  306. self.stayTime = 0.5
  307. if self.relogin then
  308. ManagerContainer.LuaGameMgr:ReLoginClearData()
  309. end
  310. ManagerContainer.LuaUIMgr:CloseAllPagesExceptId(Enum.UIPageName.UILanuch)
  311. end
  312. function LoginMgr:StartSdkInit()
  313. if ManagerContainer.LuaGameMgr.sdkInited == Enum.ParamState.Success then
  314. self:StartSdkLogin()
  315. else
  316. SDKMgr.Instance:SetHttpCheckUrl(PlatformPack.URL_KEY)
  317. self.preLoginStatus = self.loginStatus
  318. self.loginStatus = LoginStatus.SdkInit
  319. self.stayTime = 35
  320. ManagerContainer.LuaGameMgr.sdkInited = Enum.ParamState.None
  321. ManagerContainer.LuaGameMgr:SdkInit()
  322. end
  323. end
  324. function LoginMgr:SdkInitFail()
  325. self.preLoginStatus = self.loginStatus
  326. self.loginStatus = LoginStatus.Error
  327. local data = {"LoginTips2", nil, nil, self, self.InternalRelogin, self.QuitGame}
  328. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  329. end
  330. function LoginMgr:StartSdkLogin()
  331. if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
  332. self:StartCheckSpecialInfo()
  333. else
  334. self.preLoginStatus = self.loginStatus
  335. self.loginStatus = LoginStatus.SdkLogin
  336. self.stayTime = 5
  337. ManagerContainer.LuaGameMgr.sdkLogined = Enum.ParamState.None
  338. ManagerContainer.LuaGameMgr:SdkLogin()
  339. end
  340. end
  341. function LoginMgr:SdkLoginFail()
  342. self.preLoginStatus = self.loginStatus
  343. self.loginStatus = LoginStatus.Error
  344. local data = {"LoginTips3", nil, nil, self, self.InternalRelogin, self.QuitGame}
  345. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  346. end
  347. function LoginMgr:StartCheckSpecialInfo()
  348. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  349. self.preLoginStatus = self.loginStatus
  350. self.loginStatus = LoginStatus.CheckSpecialInfo
  351. self.stayTime = 5
  352. if self.checkWWW then
  353. self.checkWWW:Dispose()
  354. end
  355. local url = PlatformPack.SPECIAL_INFO_URL-- .. '?timesamp=' .. tostring(os.time())
  356. -- local platform = ManagerContainer.LuaGameMgr.platform
  357. -- if platform and platform ~= '' then
  358. -- url = url .. '&platform=' .. tostring(platform)
  359. -- end
  360. -- local subplatform = ManagerContainer.LuaGameMgr.channelName
  361. -- if subplatform and subplatform ~= '' then
  362. -- url = url .. '&sub_platform=' .. tostring(subplatform)
  363. -- end
  364. --LogError(url)
  365. --self.agreement = "我已详细阅读并同意<link=https://www.i7game.com/mobile/user/protocol.html>《用户协议》</link>和<link=https://www.i7game.com/mobile/user/privacy.html>《隐私政策》</link>"--
  366. self.checkWWW = UnityEngine.WWW(url)
  367. end
  368. function LoginMgr:CheckSpecialInfoSuccess()
  369. if not self.checkWWW then
  370. self:CheckSpecialInfoFail()
  371. return
  372. end
  373. if self.checkWWW.error and self.checkWWW.error ~= '' then
  374. self:CheckSpecialInfoFail()
  375. return
  376. end
  377. local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, self.checkWWW.text)
  378. if ok then
  379. self.agreement = result.agreement
  380. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SPECIAL_INFO_CHANGED)
  381. self:StartCheckServer()
  382. else
  383. LogError("[wboy] CheckSpecialInfoFail " .. tostring(self.checkWWW.text))
  384. self:CheckSpecialInfoFail()
  385. end
  386. end
  387. function LoginMgr:CheckSpecialInfoFail()
  388. if self.checkWWW then
  389. self.checkWWW:Dispose()
  390. end
  391. self.checkWWW = nil
  392. self:StartCheckServer()
  393. end
  394. function generateDeviceId()
  395. local seed = tostring({}):sub(7)
  396. math.randomseed(seed)
  397. math.random(); math.random(); math.random()
  398. local hexChars = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}
  399. local deviceId = ""
  400. for i=1,8 do
  401. deviceId = deviceId .. hexChars[math.random(16)]
  402. end
  403. for i=1,4 do
  404. deviceId = deviceId .. "-" .. hexChars[math.random(16)] .. hexChars[math.random(16)] .. hexChars[math.random(16)] .. hexChars[math.random(16)]
  405. end
  406. return deviceId
  407. end
  408. function LoginMgr:StartCheckServer(isAgain)
  409. ManagerContainer.LuaBattleMgr:ResetBattleMode()
  410. self.checkServerAgain = isAgain
  411. local openId = ManagerContainer.LuaGameMgr.openId --"8bb8f18b-aeef-1b79-db12-a825"--generateDeviceId()--
  412. LogError("OpenID = "..openId);
  413. if not openId or openId == '' then
  414. openId = UnityEngine.PlayerPrefs.GetString("LoginName")
  415. end
  416. if not openId or openId == '' then
  417. openId = ManagerContainer.LuaGameMgr.DeviceId
  418. end
  419. ManagerContainer.LuaGameMgr.openId = openId
  420. if Constant.SERVER_FORCE_INFO then
  421. self:SetServerInfo(Constant.SERVER_FORCE_INFO)
  422. if isAgain then
  423. self:StartCheckCanEnterServerState()
  424. else
  425. self:StartWaitClickEnter()
  426. end
  427. return
  428. end
  429. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  430. self.stayTime = 5
  431. local serverId = ManagerContainer.LuaGameMgr.serverData.id
  432. --LogWarning('serverId-----'..serverId)
  433. if(serverId == nil and self.UseLoacdServerIDState ~= UseLoacdServerIDState.Error)then
  434. serverId = ManagerContainer.LuaGameMgr:GetServerID()
  435. --serverId = 3;
  436. --LogWarning('serverId-----'..serverId)
  437. self.UseLoacdServerIDState = UseLoacdServerIDState.Used;
  438. end
  439. local url = PlatformPack.SERVERLIST_URL
  440. if serverId and serverId > 0 then
  441. url = url .. "?type=21&id=" .. tostring(serverId)
  442. else
  443. url = url .. "?"
  444. end
  445. url = ManagerContainer.LuaGameMgr:ComposeCommonServerInfo(url)
  446. if self.checkWWW then
  447. self.checkWWW:Dispose()
  448. end
  449. --LogWarning('checkWWW-----'..url)
  450. self.preLoginStatus = self.loginStatus
  451. self.loginStatus = LoginStatus.CheckServer
  452. --url = "http://103.239.245.64:81/serverlist/test"
  453. self.checkWWW = UnityEngine.WWW(url)
  454. end
  455. function LoginMgr:CheckServerFail()
  456. self.preLoginStatus = self.loginStatus
  457. self.loginStatus = LoginStatus.Error
  458. local error = self.checkWWW.error
  459. if self.checkWWW then
  460. self.checkWWW:Dispose()
  461. end
  462. self.checkWWW = nil
  463. self.checkServerAgain = nil
  464. if error == "429 Too Many Requests" then
  465. --data = {"LoginTips14", nil, nil, self, self.InternalRelogin, self.QuitGame}
  466. ManagerContainer.LuaGameMgr:ClearServerData()
  467. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  468. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
  469. self.waitNoticeTimer = ManagerContainer.LuaTimerMgr:AddLuaTimer(500, 1,function ()
  470. local seed = tostring({}):sub(7)
  471. math.randomseed(seed)
  472. math.random(); math.random(); math.random()
  473. local waitTime = math.random(2,10)
  474. local waitData ={2,"LoginGetServerListErrorString",{waitTime,1,function ()
  475. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  476. self.waitCloseNoticeTimer = ManagerContainer.LuaTimerMgr:AddLuaTimer(200, 1,function ()
  477. self:InternalRelogin()
  478. ManagerContainer.LuaTimerMgr:RemoveTimer(self.waitCloseNoticeTimer)
  479. end,nil)
  480. end}}
  481. ManagerContainer.LuaUIMgr:ShowNetWaiting_New(waitData)
  482. ManagerContainer.LuaTimerMgr:RemoveTimer(self.waitNoticeTimer)
  483. end, nil)
  484. return
  485. end
  486. --LoginTips14
  487. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  488. local data = {"LoginTips4", nil, nil, self, self.InternalRelogin, self.QuitGame}
  489. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  490. ManagerContainer.LuaGameMgr:ClearServerData()
  491. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
  492. end
  493. function LoginMgr:CheckServerSuccess()
  494. if not self.checkWWW then
  495. self:CheckServerFail()
  496. return
  497. end
  498. if self.checkWWW.error and self.checkWWW.error ~= '' then
  499. LogError("[wboy] CheckServer error = " .. tostring(self.checkWWW.error))
  500. LogError("[wboy] CheckServer Text = " .. tostring(self.checkWWW.text))
  501. self:CheckServerFail()
  502. return
  503. end
  504. local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, self.checkWWW.text)
  505. --LogError("[wboy] CheckServer " .. tostring(self.checkWWW.text))
  506. if ok then
  507. self:SetServerInfo(result)
  508. self.checkWWW:Dispose()
  509. self.checkWWW = nil
  510. if result.err and self.UseLoacdServerIDState == UseLoacdServerIDState.Used then
  511. self.UseLoacdServerIDState = UseLoacdServerIDState.Error
  512. ManagerContainer.LuaGameMgr:SetServerID(-1)
  513. elseif self.UseLoacdServerIDState == UseLoacdServerIDState.Used or self.UseLoacdServerIDState == UseLoacdServerIDState.Error then
  514. self.UseLoacdServerIDState = UseLoacdServerIDState.Success
  515. end
  516. if self.checkServerAgain then
  517. self.checkServerAgain = nil
  518. self:StartCheckCanEnterServerState()
  519. else
  520. self:StartWaitClickEnter()
  521. end
  522. else
  523. LogError("[wboy] CheckServerFail " .. tostring(self.checkWWW.text))
  524. self:CheckServerFail()
  525. end
  526. end
  527. function LoginMgr:SetServerInfo(server)
  528. ManagerContainer.LuaGameMgr:InitServerData(server.ServerId, server.ServerName, server.Ip, server.Port, server.State)
  529. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
  530. end
  531. function LoginMgr:StartWaitClickEnter()
  532. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  533. self.preLoginStatus = self.loginStatus
  534. self.loginStatus = LoginStatus.WaitClickEnter
  535. self.waitClicked = nil
  536. local serverData = ManagerContainer.LuaGameMgr.serverData
  537. if serverData and serverData.id and serverData.id > 0 and self.showNotify then
  538. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINotifyTips)
  539. self.showNotify = false
  540. end
  541. end
  542. function LoginMgr:EndWaitClickEnter()
  543. if ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
  544. if self:IsAgreement() then
  545. local isOn = ManagerContainer.PlayerPrefsMgr:GetGlobalBoolean(Constant.AGREEMENT_RECORD_KEY, false)
  546. if not isOn then
  547. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('GameLogin19')
  548. self.preLoginStatus = self.loginStatus
  549. self.loginStatus = LoginStatus.WaitClickEnter
  550. self.waitClicked = nil
  551. return
  552. end
  553. end
  554. self:StartUpdateCheck()
  555. else
  556. self:InternalRelogin()
  557. end
  558. end
  559. function LoginMgr:StartUpdateCheck()
  560. self.preLoginStatus = self.loginStatus
  561. self.loginStatus = LoginStatus.UpdateCheck
  562. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  563. local leBianSDK = nil --Wenting.Lebian.LeBianSDK.instance
  564. if leBianSDK then
  565. if not self.endUpdateCheckCB then
  566. self.endUpdateCheckCB = System.Action_Wenting_Lebian_QueryUpdateErrorCode(self.EndUpdateCheck, self)
  567. end
  568. leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback + self.endUpdateCheckCB
  569. leBianSDK:QueryUpdate()
  570. else
  571. self:EndUpdateCheck(nil)
  572. --self:EndUpdateCheck(Wenting.Lebian.QueryUpdateErrorCode.Error)
  573. end
  574. end
  575. function LoginMgr:EndUpdateCheck(resultCode)
  576. local leBianSDK = nil -- Wenting.Lebian.LeBianSDK.instance
  577. if leBianSDK then
  578. if self.endUpdateCheckCB then
  579. leBianSDK.queryUpdateCallback = leBianSDK.queryUpdateCallback - self.endUpdateCheckCB
  580. self.endUpdateCheckCB = nil
  581. end
  582. local QueryUpdateErrorCode = Wenting.Lebian.QueryUpdateErrorCode
  583. if resultCode == QueryUpdateErrorCode.NoUpdate then
  584. self:StartCheckServer(true)
  585. return
  586. elseif resultCode == QueryUpdateErrorCode.Update then
  587. self:StartCheckServer(true)
  588. return
  589. elseif resultCode == QueryUpdateErrorCode.ForceUpdate then
  590. -- 停止后续流程
  591. self.preLoginStatus = self.loginStatus
  592. self.loginStatus = LoginStatus.Error
  593. return
  594. end
  595. end
  596. -- self:ResetClickState()
  597. --self:ErrorNoticeDisplay('GameLogin20')
  598. self:StartCheckServer(true)
  599. end
  600. function LoginMgr:StartCheckCanEnterServerState()
  601. if not SDKMgr.Instance:HasCanEnterServerJudge() then
  602. self:StartConnectGate()
  603. return
  604. end
  605. self.preLoginStatus = self.loginStatus
  606. self.loginStatus = LoginStatus.CanEnterServerCheck
  607. ManagerContainer.LuaGameMgr.canEnterServerState = Enum.ParamState.None
  608. local serverData = ManagerContainer.LuaGameMgr.serverData
  609. SDKMgr.Instance:CanEnterServerJudge(serverData.id, serverData.name)
  610. end
  611. function LoginMgr:CheckCanEnterServerStateSuccess()
  612. self:StartConnectGate()
  613. end
  614. function LoginMgr:CheckCanEnterServerStateFail()
  615. self:ResetClickState()
  616. end
  617. function LoginMgr:StartConnectGate()
  618. local serverData = ManagerContainer.LuaGameMgr.serverData
  619. if serverData.state == Enum.ServerState.Maintain then
  620. self:StartMaintain()
  621. return
  622. elseif serverData.state == Enum.ServerState.Full then
  623. self:ConnectGateFail()
  624. return
  625. end
  626. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  627. self.preLoginStatus = self.loginStatus
  628. self.loginStatus = LoginStatus.ConnectGate
  629. ManagerContainer.NetManager.connectGated = Enum.ParamState.None
  630. self.logined = nil
  631. self.loginErrorCode = nil
  632. local serverPorts = serverData.ports
  633. local len = serverPorts and #serverPorts or 0
  634. if len <= 0 then
  635. self:ConnectGateFail()
  636. elseif len <= 1 then
  637. serverData.portidx = 1
  638. ManagerContainer.NetManager:ConnectGate(serverData.ip, serverPorts[1])
  639. else
  640. math.randomseed(os.time())
  641. local serverPortIdx = math.random(len)
  642. serverData.portidx = serverPortIdx
  643. self.serverPorts = clone(serverData.ports)
  644. ManagerContainer.NetManager:ConnectGate(serverData.ip, serverPorts[serverPortIdx])
  645. end
  646. end
  647. function LoginMgr:ReConnectGate()
  648. ManagerContainer.NetManager.connectGated = Enum.ParamState.None
  649. self.logined = nil
  650. self.loginErrorCode = nil
  651. local serverData = ManagerContainer.LuaGameMgr.serverData
  652. if serverData.state == Enum.ServerState.Maintain then
  653. self:StartMaintain()
  654. return
  655. elseif serverData.state == Enum.ServerState.Full then
  656. self:ConnectGateFail()
  657. return
  658. end
  659. local len = self.serverPorts and #self.serverPorts or 0
  660. if len <= 0 then
  661. self:ConnectGateFail()
  662. else
  663. local serverPortIdx = serverData.portidx
  664. if serverPortIdx then
  665. table.remove(self.serverPorts, serverPortIdx)
  666. end
  667. len = #self.serverPorts
  668. if len <= 0 then
  669. self:ConnectGateFail()
  670. else
  671. serverPortIdx = math.random(len)
  672. serverData.portidx = serverPortIdx
  673. ManagerContainer.NetManager:ConnectGate(serverData.ip, self.serverPorts[serverPortIdx])
  674. end
  675. end
  676. end
  677. function LoginMgr:ConnectGateFail()
  678. self:ResetClickState()
  679. self:ErrorNoticeDisplay('GameLogin21')
  680. end
  681. function LoginMgr:StartMaintain()
  682. self:ResetClickState()
  683. self:ErrorNoticeDisplay('GameLogin11')
  684. end
  685. function LoginMgr:StartLoginGame()
  686. self.preLoginStatus = self.loginStatus
  687. self.loginStatus = LoginStatus.GameLogin
  688. self.stayTime = 10
  689. end
  690. function LoginMgr:LoginGameFail(error,...)
  691. self:ResetClickState()
  692. if not error then
  693. error = 'GameLogin14'
  694. end
  695. self:ErrorNoticeDisplay(error, ...)
  696. end
  697. function LoginMgr:StartEnterGame()
  698. local loginErrorCode = self.loginErrorCode
  699. if loginErrorCode == Enum.NetErrorCode.ERROR_OK then
  700. self.preLoginStatus = self.loginStatus
  701. self.loginStatus = LoginStatus.EnterGame
  702. ManagerContainer.LuaUIMgr:CloseAllPagesExceptId(Enum.UIPageName.UILanuch)
  703. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin)
  704. elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_NOT_FOUND then
  705. self.preLoginStatus = self.loginStatus
  706. self.loginStatus = LoginStatus.EnterGame
  707. ManagerContainer.LuaGameMgr:EnterCreateRole(false)
  708. elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_NOT_FOUND_NEED_ACTIVE_CODE then
  709. self.preLoginStatus = self.loginStatus
  710. self.loginStatus = LoginStatus.EnterGame
  711. ManagerContainer.LuaGameMgr:EnterCreateRole(true)
  712. elseif loginErrorCode == Enum.NetErrorCode.ERROR_SDK_ACCOUNT_INVALID then
  713. self.preLoginStatus = self.loginStatus
  714. self.loginStatus = LoginStatus.Error
  715. ManagerContainer.NetManager:ResetNetMgr()
  716. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  717. local data = {"LoginTips9", nil, true, self, self.ReLogin, self.QuitGame}
  718. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  719. elseif loginErrorCode == Enum.NetErrorCode.ERROR_GAME_VERSION then
  720. self.preLoginStatus = self.loginStatus
  721. self.loginStatus = LoginStatus.Error
  722. ManagerContainer.NetManager:ResetNetMgr()
  723. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  724. local data = {"LoginTips5", nil, nil, self, self.InternalRelogin, self.QuitGame}
  725. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  726. elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_BANED then
  727. self:GameBanedError()
  728. elseif loginErrorCode == Enum.NetErrorCode.ERROR_ROLE_BANED_TYPE_PERSONALCHAT then
  729. self:GameBanedError()
  730. else
  731. local langStr = string.formatbykey(loginErrorCode)
  732. if not langStr or langStr == '' then
  733. self:LoginGameFail(loginErrorCode)
  734. else
  735. self:ResetClickState()
  736. end
  737. end
  738. end
  739. function LoginMgr:GameBanedError()
  740. self.preLoginStatus = self.loginStatus
  741. self.loginStatus = LoginStatus.Error
  742. end
  743. function LoginMgr:ResetClickState()
  744. self.preLoginStatus = self.loginStatus
  745. self.loginStatus = LoginStatus.Error
  746. ManagerContainer.NetManager:ResetNetMgr()
  747. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  748. self:StartWaitClickEnter()
  749. end
  750. function LoginMgr:IsLoginWaiting()
  751. return (not self.loginStatus or self.loginStatus == LoginStatus.WaitClickEnter)
  752. end
  753. function LoginMgr:NetWorkError()
  754. self.preLoginStatus = self.loginStatus
  755. self.loginStatus = LoginStatus.Error
  756. ManagerContainer.NetManager:ResetNetMgr()
  757. ManagerContainer.LuaUIMgr:CloseNetWaiting()
  758. local data = {"LoginTips1", nil, nil, self, self.InternalRelogin, self.QuitGame}
  759. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
  760. end
  761. function LoginMgr:ErrorNoticeDisplay(error, ...)
  762. if not ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIErrorTips) then
  763. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIErrorTips, {errorId=error,params = {...}}, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 11)
  764. else
  765. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ERROR_DESC_DISPLAY, {errorId=error,params = {...}})
  766. end
  767. end
  768. function LoginMgr:InternalRelogin()
  769. self.preLoginStatus = self.loginStatus
  770. self.loginStatus = LoginStatus.InternalRelogin
  771. ManagerContainer.LuaUIMgr:ShowNetWaiting()
  772. ManagerContainer.LuaGameMgr:ClearServerData()
  773. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
  774. end
  775. function LoginMgr:ReLogin(logout)
  776. if logout and ManagerContainer.LuaGameMgr.sdkLogined == Enum.ParamState.Success then
  777. ManagerContainer.LuaGameMgr:SdkLogout()
  778. else
  779. ManagerContainer.LuaGameMgr:ClearServerData()
  780. ManagerContainer.LuaGameMgr:ReLogin()
  781. end
  782. end
  783. function LoginMgr:QuitGame()
  784. ManagerContainer.LuaGameMgr:QuitGame(true)
  785. return true
  786. end
  787. function LoginMgr:IsAgreement()
  788. return self.agreement and self.agreement ~= '' or false
  789. end
  790. function LoginMgr:GetAgreement()
  791. return self.agreement
  792. end
  793. return LoginMgr