重连逻辑

This commit is contained in:
chenxi 2023-06-16 21:33:09 +08:00
parent 7aee1712ac
commit 1a07576816

View File

@ -220,40 +220,44 @@ function NetManager:connect(domain, port, callback, socketName)
if ok and pbData then if ok and pbData then
pbData.status = not pbData.err_code and 0 or ProtoMsgDispatch:getErrCodeEnum(pbData.err_code) pbData.status = not pbData.err_code and 0 or ProtoMsgDispatch:getErrCodeEnum(pbData.err_code)
if pbData.status ~= 0 then if pbData.status ~= 0 then
self:closeAndClear() if msgName == "ReconnectRsp" then -- Reconnect失败就直接回登录界面
local accountInfo = LocalData:getAccountInfo() self:closeAll()
local loginType
local lastLoginType
if accountInfo.google_id and accountInfo.google_id ~= "" then
loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE
lastLoginType = NetManager.LOGIN_TYPE.GOOGLE
elseif accountInfo.apple_id and accountInfo.apple_id ~= "" then
loginType = SDKManager.BF_LOGIN_TYPE.APPLE
lastLoginType = NetManager.LOGIN_TYPE.APPLE
end
if loginType then
SDKManager:login(function(params)
if not params.token then
return
end
LocalData:setLastLoginInfo(lastLoginType, params.id, params.token)
ModuleManager.LoginManager:saveAuthArgs(true)
ModuleManager.LoginManager:initSocket()
end, loginType)
else else
LocalData:setLastLoginInfo() self:closeAndClear()
ModuleManager.LoginManager:saveAuthArgs(true) local accountInfo = LocalData:getAccountInfo()
local params = { local loginType
content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN), local lastLoginType
okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), if accountInfo.google_id and accountInfo.google_id ~= "" then
noShowClose = true, loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE
okFunc = function() lastLoginType = NetManager.LOGIN_TYPE.GOOGLE
elseif accountInfo.apple_id and accountInfo.apple_id ~= "" then
loginType = SDKManager.BF_LOGIN_TYPE.APPLE
lastLoginType = NetManager.LOGIN_TYPE.APPLE
end
if loginType then
SDKManager:login(function(params)
if not params.token then
return
end
LocalData:setLastLoginInfo(lastLoginType, params.id, params.token)
ModuleManager.LoginManager:saveAuthArgs(true)
ModuleManager.LoginManager:initSocket() ModuleManager.LoginManager:initSocket()
end, end, loginType)
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK, else
top = true, LocalData:setLastLoginInfo()
} ModuleManager.LoginManager:saveAuthArgs(true)
GFunc.showMessageBox(params) local params = {
content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN),
okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK),
noShowClose = true,
okFunc = function()
ModuleManager.LoginManager:initSocket()
end,
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK,
top = true,
}
GFunc.showMessageBox(params)
end
end end
else else
UIManager:hideWaitNet(true) UIManager:hideWaitNet(true)