miduo_client/Assets/ManagedResources/~Lua/Modules/Login/LoginPanel.lua

880 lines
36 KiB
Lua
Raw Normal View History

2020-08-25 15:51:35 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
LoginPanel = Inherit(BasePanel)
local this = LoginPanel
this.LoginWay = { Account = 0, WeChat = 1 }
2021-03-02 15:18:06 +08:00
SERVER_VERSION = tonumber(ServerConfigManager.GetSettingValue(ServerConfigManager.SettingConfig.ServerVersion) or 0)
local IsShowNotice = false
2020-06-30 18:59:44 +08:00
local IsSDKLogin = AppConst.isSDK and AppConst.isSDKLogin
2020-09-04 10:25:40 +08:00
local IsDevelopLogin = true
2020-06-30 18:59:44 +08:00
2020-05-09 13:31:21 +08:00
local openIdkey = "openIdkey"
local openIdPw = "openIdPw"
2021-04-09 12:26:35 +08:00
local defaultOpenIdkey = Language[11135]
2020-05-09 13:31:21 +08:00
local defaultOpenIdPw = ""
2021-03-02 15:18:06 +08:00
local LoginRoot_Url = ServerConfigManager.GetVersionInfo("serverUrl")
local LoginRoot_SubChannel = ServerConfigManager.GetVersionInfo("subChannel")
local LoginRoot_Channel = ServerConfigManager.GetVersionInfo("channel")
local LoginRoot_Version = ServerConfigManager.GetVersionInfo("version")
local LoginRoot_PackageVersion = ServerConfigManager.GetVersionInfo("packageVersion")
local LoginRoot_NoticeChannel = ServerConfigManager.GetSettingValue(ServerConfigManager.SettingConfig.NOTICE_CHANNEL) or ""
local LoginRoot_UserChannel = ServerConfigManager.GetSettingValue(ServerConfigManager.SettingConfig.USER_CHANNEL) or ""
2020-05-09 13:31:21 +08:00
local orginLayer
local IsUserProtoActive = ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.USER_PROTO)
local timeStamp = Time.realtimeSinceStartup
local timeSign = Util.MD5Encrypt(string.format("%s%s", timeStamp, LoginManager.sign))
2021-06-24 11:38:43 +08:00
local UrlList = {}
local HaveConfirm = false
2021-06-23 19:39:46 +08:00
2020-05-09 13:31:21 +08:00
--初始化组件(用于子类重写)
function this:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-09 13:31:21 +08:00
orginLayer = 0
2020-08-25 17:56:55 +08:00
this.loginPart = this.gameObject
2021-05-31 17:31:31 +08:00
2020-05-09 13:31:21 +08:00
this.tip = Util.GetGameObject(this.loginPart, "tip/Text")
this.loginAnim = this.gameObject:GetComponent("Animator")
this.loginAnim.enabled = false
2020-08-25 17:56:55 +08:00
this.btnLoginPart = Util.GetGameObject(this.loginPart, "jinruyouxi")
this.btnLogin = Util.GetGameObject(this.loginPart, "jinruyouxi _wenzi")
2020-05-09 13:31:21 +08:00
this.inputField = Util.GetGameObject(this.loginPart, "InputField"):GetComponent("InputField")
this.UserBtn = Util.GetGameObject(this.loginPart, "userBtn")
this.UserBtnText = Util.GetGameObject(this.loginPart, "userBtn/Text"):GetComponent("Text")
this.btnUser = Util.GetGameObject(this.loginPart, "btnUser")
this.btnNotice = Util.GetGameObject(this.loginPart, "btnNotice")
2020-09-25 21:19:01 +08:00
this.btnNotice:SetActive(IsShowNotice)
2020-05-09 13:31:21 +08:00
---selectServerPart
this.serverSelectPart = Util.GetGameObject(this.loginPart, "serverSelect")
this.serverMes = Util.GetGameObject(this.serverSelectPart, "serverMes"):GetComponent("Text")
this.changeServerBtn = Util.GetGameObject(this.serverSelectPart, "changeServer")
this.sdkLoginBtn = Util.GetGameObject(this.loginPart, "loginBtn")
this.SetLoginPart(false)
2020-08-25 17:56:55 +08:00
this.loginMask = Util.GetGameObject(this.loginPart, "loginMask")
2020-05-09 13:31:21 +08:00
this.versionText = Util.GetGameObject(this.loginPart, "version"):GetComponent("Text")
2021-04-09 12:26:35 +08:00
this.versionText.text = Language[11136]..LoginRoot_Version
-- this.bg1 = Util.GetGameObject(this.gameObject, "bg11"):GetComponent("RawImage")
-- resMgr:SetStreamingTexture(this.bg1, "login_caohua.png")
-- 背景
this.bg = Util.GetGameObject(this.gameObject, "bg"):GetComponent("Image")
this.bgStr = PackageManager.GetLoginPanelBg()
this.bg.color = Color.New(1, 1, 1, 0)
LoadStreamingTexture(this.spLoader, this.bgStr, function(sp)
this.bg.sprite = sp
this.bg.color = Color.New(1, 1, 1, 1)
end)
-- logo
2021-06-03 13:52:55 +08:00
this.logo = Util.GetGameObject(this.gameObject, "logo"):GetComponent("Image")
this.logoStr = PackageManager.GetLoginPanelLogo()
if this.logoStr and this.logoStr ~= "" then
LoadStreamingTexture(this.spLoader, this.logoStr, function(sp)
this.logo.gameObject:SetActive(true)
this.logo.sprite = sp
this.logo:SetNativeSize()
end)
2021-06-03 13:52:55 +08:00
else
this.logo.gameObject:SetActive(false)
end
-- BindLightFlash(Util.GetGameObject(this.logo, "saoguang"), this.logo)
this.healthTip = Util.GetGameObject(this.gameObject, "healthTip")
this.healthTip:SetActive(IS_SHOW_HEALTH_TIP)
2021-06-11 01:45:09 +08:00
this.bh = Util.GetGameObject(this.gameObject, "healthTip/bh"):GetComponent("Text")
local bhContent = PackageManager.GetBHContent()
2021-06-24 11:38:43 +08:00
-- LogError(tostring(bhContent))
2021-06-11 01:45:09 +08:00
if bhContent then
this.bh.text = bhContent
else
this.bh.text = ""
end
2021-06-02 17:52:26 +08:00
this.video = Util.GetGameObject(this.gameObject, "VideoPlayer")
2021-06-23 19:39:46 +08:00
--用户隐私协议
2021-06-24 11:38:43 +08:00
this.protos = Util.GetGameObject(this.gameObject, "protos")
2021-06-24 09:50:55 +08:00
this.instructionsBtn = Util.GetGameObject(this.gameObject, "protos/instructionsBtn")
this.privacyBtn = Util.GetGameObject(this.gameObject, "protos/privacyBtn")
2021-06-24 11:38:43 +08:00
this.ConfirmBtn = Util.GetGameObject(this.gameObject, "protos/Confirm")
this.ConfirmImg = Util.GetGameObject(this.ConfirmBtn, "gou")
this.protos:SetActive(IsUserProtoActive)
2020-05-09 13:31:21 +08:00
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.btnLogin, this.OnLoginClick)
--this.dropDown:ClearOptions()
Util.AddInputField_OnEndEdit(this.inputField.gameObject, function(str)
PlayerPrefs.SetString(openIdkey, str)
end)
Util.AddClick(this.btnUser, function()
local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw)
UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw)
this.UserBtnText.text = str
PlayerPrefs.SetString(openIdkey, str)
PlayerPrefs.SetString(openIdPw, pw)
end)
end)
Util.AddClick(this.btnNotice, function()
this.ShowNotice()
2020-05-09 13:31:21 +08:00
end)
Util.AddClick(this.UserBtn, function()
local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw)
UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw)
this.UserBtnText.text = str
PlayerPrefs.SetString(openIdkey, str)
PlayerPrefs.SetString(openIdPw, pw)
end)
end)
---SelectServer
Util.AddClick(this.changeServerBtn, function()
local function reServerCallback(str)
if str == nil then
return
2020-05-09 13:31:21 +08:00
end
if str ~= nil and str ~= "" then
MyPCall(function()
local json = require 'cjson'
local data = json.decode(str)
-- selectServerPart
this.SetServerList(data)
-- 打开服务器选择界面
UIManager.OpenPanel(UIName.ServerListSelectPanel, {
serverList = this.serverList,
myServerList = this.myServerList,
lastServer = this.lastServer,
recommend = this.recommend,
callback = function(index)
local list = this.serverList[index]
PlayerManager.serverInfo = list
LoginManager.SocketAddress = list.ip
LoginManager.SocketPort = list.port
LoginManager.ServerId = list.server_id
LoginManager.state = list.state
--local severArea = tonumber(string.sub(list.server_id, 0, -5))
this.serverMes.text = PlayerManager.serverInfo.name-- .. "\t<color=#56F384FF>" .. severArea .. "</color>" .. Language[11138]
end
})
end)
end
end
-- 判断获取服务器的id
if IsSDKLogin then
this.RequestServerList(AppConst.OpenId, reServerCallback)
else
local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
this.RequestServerList(userId, reServerCallback)
end
2020-05-09 13:31:21 +08:00
end)
--SDK 登录
Util.AddClick(this.sdkLoginBtn, function()
this.SDKLogin()
end)
2021-06-23 19:39:46 +08:00
--用户隐私协议
2021-06-24 09:50:55 +08:00
Util.AddClick(this.instructionsBtn, function()
2021-06-24 11:38:43 +08:00
SDKMgr:OpenWeb(UrlList[1])
2021-06-24 09:50:55 +08:00
end)
Util.AddClick(this.privacyBtn, function()
2021-06-24 11:38:43 +08:00
SDKMgr:OpenWeb(UrlList[2])
end)
Util.AddClick(this.ConfirmBtn, function()
local confirm = PlayerPrefs.GetInt("IHaveConfirmProtos")
if confirm == 0 then
this.ConfirmImg:SetActive(true)
PlayerPrefs.SetInt("IHaveConfirmProtos",1)
elseif confirm == 1 then
this.ConfirmImg:SetActive(false)
PlayerPrefs.SetInt("IHaveConfirmProtos",0)
end
2021-06-24 09:50:55 +08:00
end)
2021-06-23 19:39:46 +08:00
2020-05-09 13:31:21 +08:00
end
-- sdk 初始化完成回调
function this.OnInitSuccess()
this.SDKLogin()
end
2020-05-09 13:31:21 +08:00
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(Protocal.Connect, this.OnConnect)
Game.GlobalEvent:AddEvent(Protocal.Disconnect, this.OnDisconnect)
Game.GlobalEvent:AddEvent(GameEvent.LoginSuccess.OnLoginSuccess, this.RefreshLoginStatus)
Game.GlobalEvent:AddEvent(GameEvent.LoginSuccess.OnLogout, this.OnLogout)
Game.GlobalEvent:AddEvent(GameEvent.SDK.InitSuccess, this.OnInitSuccess)
2020-05-09 13:31:21 +08:00
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(Protocal.Connect, this.OnConnect)
Game.GlobalEvent:RemoveEvent(Protocal.Disconnect, this.OnDisconnect)
Game.GlobalEvent:RemoveEvent(GameEvent.LoginSuccess.OnLoginSuccess, this.RefreshLoginStatus)
Game.GlobalEvent:RemoveEvent(GameEvent.LoginSuccess.OnLogout, this.OnLogout)
Game.GlobalEvent:RemoveEvent(GameEvent.SDK.InitSuccess, this.OnInitSuccess)
end
function this:OnLogout()
if IsSDKLogin then
2020-07-22 22:12:20 +08:00
this.SetLoginPart(false)
this.sdkLoginBtn:SetActive(true)
this.inputField.gameObject:SetActive(false)
this.UserBtn:SetActive(false)
this.btnUser:SetActive(false)
this.btnNotice.transform.position = this.btnUser.transform.position
this.SDKLogin()
else
this.sdkLoginBtn:SetActive(false)
local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
if IsDevelopLogin then
this.UserBtn:SetActive(false)
this.btnUser:SetActive(false)
this.inputField.gameObject:SetActive(true)
this.inputField.text = userId
else
this.UserBtn:SetActive(true)
this.btnUser:SetActive(true)
this.inputField.gameObject:SetActive(false)
this.UserBtnText.text = userId
end
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11139])
this.SetLoginPart(true)
2020-08-22 15:31:14 +08:00
-- 获取服务器列表
this.RequestServerList(userId, this.OnReceiveServerList)
end
2020-05-09 13:31:21 +08:00
end
function this:OnSortingOrderChange()
Util.AddParticleSortLayer(self.gameObject, self.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
end
--界面打开时调用(用于子类重写)
function this:OnOpen(...)
2021-06-02 18:08:03 +08:00
--设置背景
PackageManager.SetVideo(this.video, this.bg)
2020-05-09 13:31:21 +08:00
if AppConst.Code ~= "" then
2021-01-26 17:08:39 +08:00
MsgPanel.ShowOne(GetLanguageStrById(AppConst.Code))
2020-05-09 13:31:21 +08:00
AppConst.Code = ""
end
2020-06-30 18:59:44 +08:00
if IsSDKLogin then
2020-07-22 22:12:20 +08:00
this.SetLoginPart(false)
this.sdkLoginBtn:SetActive(true)
2020-06-30 18:59:44 +08:00
this.inputField.gameObject:SetActive(false)
this.UserBtn:SetActive(false)
this.btnUser:SetActive(false)
this.btnNotice.transform.position = this.btnUser.transform.position
this.SDKLogin()
2020-05-09 13:31:21 +08:00
else
2020-06-30 18:59:44 +08:00
this.sdkLoginBtn:SetActive(false)
2020-05-09 13:31:21 +08:00
2020-06-30 18:59:44 +08:00
local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
if IsDevelopLogin then
this.UserBtn:SetActive(false)
this.btnUser:SetActive(false)
this.inputField.gameObject:SetActive(true)
this.inputField.text = userId
else
this.UserBtn:SetActive(true)
this.btnUser:SetActive(true)
this.inputField.gameObject:SetActive(false)
this.UserBtnText.text = userId
end
2020-05-09 13:31:21 +08:00
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11139])
2020-05-09 13:31:21 +08:00
this.SetLoginPart(true)
2020-08-22 15:31:14 +08:00
-- 获取服务器列表
this.RequestServerList(userId, this.OnReceiveServerList)
2020-05-09 13:31:21 +08:00
end
2021-06-24 11:38:43 +08:00
2020-06-30 18:59:44 +08:00
local tran = this.tip:GetComponent("RectTransform")
--LayoutUtility.GetPreferredWidth(tran)
local offsetX = (GetPreferredWidth(tran) + Screen.width) / 2
2020-06-30 18:59:44 +08:00
tran.anchoredPosition = Vector2.New(offsetX, 0)
tran:DOAnchorPosX(-offsetX, 30, false):SetEase(Ease.Linear):SetLoops(-1)
2020-05-09 13:31:21 +08:00
SoundManager.PlayMusic(SoundConfig.BGM_Login)
SoundManager.PlayAmbient(SoundConfig.Ambient_Login)
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
this.SetLoginPart(false)
SoundManager.PauseAmbient()
end
function this.CheckNoticeShow()
-- 判断公告显示
IsShowNotice = not ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_NO_NOTICE)
this.btnNotice:SetActive(IsShowNotice)
end
-- 打开公告界面
function this.ShowNotice()
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11137])
--LogError("LoginRoot_NoticeChannel=="..LoginRoot_NoticeChannel)
-- 如果有渠道包配置的id则加上
local noticeChannel = LoginRoot_NoticeChannel
local subNoticeID = PackageManager.GetSubNoticeID()
if subNoticeID then
noticeChannel = noticeChannel.. subNoticeID
else
local packID = PackageManager.GetPackageID()
if packID then
2021-08-05 16:34:05 +08:00
noticeChannel = noticeChannel .. packID
end
end
local url = LoginRoot_Url .. "jl_loginserver/getNotice?timestamp="..timeStamp.."&sign=".. timeSign.."&packageName="..noticeChannel
Log(url)
2021-07-13 18:55:21 +08:00
LoginManager:SendGetHttp(url,function (str)
UIManager.OpenPanel(UIName.NoticePopup,str)
end, nil, nil, nil)
end
2020-08-22 15:31:14 +08:00
-- 请求获取
function this.RequestServerVersion(func)
local ChannelID = LoginRoot_UserChannel == "" and LoginRoot_Channel or LoginRoot_UserChannel
local packId = PackageManager.GetPackageID()
if packId then
ChannelID = ChannelID.. packId
end
local url = LoginRoot_Url .. "jl_loginserver/getServerVersion?serverVersion="..ChannelID
LogPink(url)
2021-07-13 18:55:21 +08:00
LoginManager:SendGetHttp(url, function (str)
LogPink(str)
2021-07-13 18:55:21 +08:00
if str == "" or str == "null" or string.find(str, "html") then
LogWarn("获取到的ServerVersion数据是空值请检查")
else
local json = require 'cjson'
local context = json.decode(str)
if IsSDKLogin then
-- 当前包的版本号小于GM配置的版本号则包连接正式服否则连接提审服
local vcode = ServerConfigManager.GetSDKVersionCode()
if vcode <= context.serverInfo then
SERVER_VERSION = 0 -- 正式服
else
SERVER_VERSION = 1 -- 提审服
end
end
end
--
if func then
func()
end
end, nil, nil, function(errCode, errMsg)
LogError("GetServerVersion Error: "..tostring(errCode) .. ", "..tostring(errMsg))
if func then
func()
end
end)
end
2020-08-22 15:31:14 +08:00
-- 请求获取服务器列表
function this.RequestServerList(userId, callback)
this.RequestServerVersion(function()
this.CheckNoticeShow()
RequestPanel.Show(Language[11139])
local url = string.format(
"%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s&server_version=%s",
LoginRoot_Url, userId, LoginRoot_Channel, LoginRoot_SubChannel, SERVER_VERSION)
Log(url)
2021-07-13 18:55:21 +08:00
LoginManager:SendGetHttp(url, callback, nil, nil, nil)
end)
2021-06-24 11:38:43 +08:00
--用户协议,隐私政策
this.RequestProtos(userId)
2020-08-22 15:31:14 +08:00
end
2021-06-24 11:38:43 +08:00
--获取用户隐私协议
function this.RequestProtos(userId)
this.protos:SetActive(false)
this.ConfirmImg:SetActive(PlayerPrefs.GetInt("IHaveConfirmProtos") == 1)
UrlList[1] = ""
UrlList[2] = ""
if not IsUserProtoActive then
Log("用户和隐私协议功能未开启")
return
end
local ChannelID = LoginRoot_UserChannel == "" and LoginRoot_Channel or LoginRoot_UserChannel
2021-06-24 11:56:09 +08:00
local PackageID = PackageManager.GetPackageID()
if PackageID then
ChannelID = ChannelID .. PackageID
2021-06-24 11:56:09 +08:00
end
local url = LoginRoot_Url.."jl_loginserver/getAgreement?gamePack="..ChannelID
Log(url)
2021-07-13 18:55:21 +08:00
LoginManager:SendGetHttp(url, function (str)
local json = require 'cjson'
local data = json.decode(str)
if data.parms then
UrlList[1] = data.parms.instructions
UrlList[2] = data.parms.privacy
Log("instructionsUrl:"..tostring(UrlList[1]).." privacyUrl:"..tostring(UrlList[2]))
HaveConfirm = true
else
this.protos:SetActive(false)
Log("用户和隐私协议地址为空")
HaveConfirm = false
return
end
if UrlList[1] ~= "" and UrlList[2] ~="" then
this.protos:SetActive(true)
HaveConfirm = true
else
this.protos:SetActive(false)
HaveConfirm = false
end
end, nil, nil, nil)
2021-06-24 11:38:43 +08:00
end
2020-08-22 15:31:14 +08:00
2020-05-09 13:31:21 +08:00
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2021-06-02 18:08:03 +08:00
PackageManager.UnloadVideo()
2020-05-09 13:31:21 +08:00
end
2020-08-22 15:31:14 +08:00
this.isWaiting = false
2020-05-09 13:31:21 +08:00
function this.SDKLogin()
2020-08-22 15:31:14 +08:00
if not this.isWaiting then
this.isWaiting = true
Timer.New(function()
SDKMgr:Login()
this.isWaiting = false
end, 1, 1):Start()
end
2020-05-09 13:31:21 +08:00
end
function this.RefreshLoginStatus(result)
if result == SDK_RESULT.SUCCESS then
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11139])
2020-05-09 13:31:21 +08:00
this.SetLoginPart(true)
this.sdkLoginBtn:SetActive(false)
2020-08-22 15:31:14 +08:00
-- 获取服务器列表
this.RequestServerList(AppConst.OpenId, this.OnReceiveServerList)
2020-05-09 13:31:21 +08:00
else
this.sdkLoginBtn:SetActive(true)
end
end
function this.SetSDKExtensionParams(params)
if not params or params == "" then
return
end
local json = require 'cjson'
local context = json.decode(params)
BindPhoneNumberManager.SetPtToken(context.token)
LoginManager.pt_pId = context.pid
LoginManager.pt_gId = context.gid
end
--收到公告
function this.OnReceiveAnnouncement(str)
if str == nil then
return
end ;
pcall(function()
local json = require 'cqueryAllies'
local data = json.decode(str);
if data.content ~= nil and data.content ~= "" then
UIManager.OpenPanel(UIName.GongGaoPanel, data.content)
end
end);
end
--获取服务器列表地址
function this.OnReceiveServerList(str)
if str == nil then
return
2020-06-30 18:59:44 +08:00
end
2020-05-09 13:31:21 +08:00
if str ~= nil and str ~= "" then
MyPCall(function()
local json = require 'cjson'
local data = json.decode(str)
---selectServerPart
this.SetServerList(data)
2020-06-30 18:59:44 +08:00
if not IsSDKLogin and not IsDevelopLogin then
2020-05-09 13:31:21 +08:00
local user = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
local userPw = PlayerPrefs.GetString(openIdPw, defaultOpenIdPw)
if user == defaultOpenIdkey or userPw == defaultOpenIdPw then
UIManager.OpenPanel(UIName.RegistPopup, function(str, pw)
this.UserBtnText.text = str
PlayerPrefs.SetString(openIdkey, str)
PlayerPrefs.SetString(openIdPw, pw)
end)
else
LoginManager.RequestUser(user, userPw, function(code)
if code ~= 0 then
UIManager.OpenPanel(UIName.LoginPopup, user, userPw, function(str, pw)
this.UserBtnText.text = str
PlayerPrefs.SetString(openIdkey, str)
PlayerPrefs.SetString(openIdPw, pw)
end)
else
2020-09-25 21:19:01 +08:00
if IsShowNotice then
this.loginMask:SetActive(true)
Timer.New(function()
this.ShowNotice()
2020-09-25 21:19:01 +08:00
this.loginMask:SetActive(false)
end, 2.5, 1):Start()
end
2020-05-09 13:31:21 +08:00
end
end)
end
else
2020-09-25 21:19:01 +08:00
if IsShowNotice then
this.loginMask:SetActive(true)
Timer.New(function()
this.ShowNotice()
2020-09-25 21:19:01 +08:00
this.loginMask:SetActive(false)
end, 2.5, 1):Start()
end
2020-05-09 13:31:21 +08:00
end
end)
end
end
function this.SetServerList(data)
this.CacheLoginData(data)
-- 默认选择第一个服务器
local lastIndex = 1
-- 判断要显示的服务器
local showServer
2020-05-09 13:31:21 +08:00
if this.lastServer then --有最近登录显示最近登录,没有显示推荐,否则显示第一个服
showServer = this.lastServer.serverid
2020-05-09 13:31:21 +08:00
else
if this.recommend then
showServer = this.recommend
end
2020-05-09 13:31:21 +08:00
end
-- 如果有要显示的服务器判断位置
if showServer then
for i = 1, #this.serverList do
if this.serverList[i].server_id == showServer then
lastIndex = i
break
end
end
2020-09-25 21:19:01 +08:00
end
2020-05-09 13:31:21 +08:00
PlayerManager.serverInfo = this.serverList[lastIndex]
LoginManager.SocketAddress = this.serverList[lastIndex].ip
LoginManager.SocketPort = tonumber(this.serverList[lastIndex].port)
LoginManager.ServerId = this.serverList[lastIndex].server_id
LoginManager.state = this.serverList[lastIndex].state
2020-05-09 13:31:21 +08:00
2021-03-19 11:37:22 +08:00
--local severArea = tonumber(string.sub(this.serverList[lastIndex].server_id, 0, -5))
2021-04-09 12:26:35 +08:00
this.serverMes.text = PlayerManager.serverInfo.name-- .. "\t<color=#56F384FF>" .. severArea .. "</color>" .. Language[11138]
2020-05-09 13:31:21 +08:00
RequestPanel.Hide()
end
function this.CacheLoginData(data)
this.serverList = {}
for i = 1, #data.serverList do
this.serverList[i] = data.serverList[i]
end
table.sort(this.serverList, function(a, b)
if a.isnew == b.isnew then
return a.server_id < b.server_id
else
return a.isnew > b.isnew
end
end)
this.myServerList = {}
for i = 1, #data.myServerList do
this.myServerList[i] = data.myServerList[i]
end
this.lastServer = data.lastServer
this.recommend = data.recommend
end
--登录进主界面之前需要依次请求玩家数据,物品数据,装备数据,英雄数据,编队数据,任务数据, 异妖数据,工坊数据, 冒险数据
function this.ExecuteLoading()
2020-06-03 19:09:01 +08:00
local requestList = {
2020-09-25 21:19:01 +08:00
--[[[1] = ]]function() NetManager.PlayerInfoRequest(LoadingPanel.OnStep) end, -- 基础信息
--[[[2] = ]]function() NetManager.RequestMission(LoadingPanel.OnStep) end, -- 任务信息
--[[[3] = ]]function() NetManager.ItemInfoRequest(0, LoadingPanel.OnStep) end, -- 物品信息
--[[[4] = ]]function() NetManager.AllEquipRequest(0, LoadingPanel.OnStep) end, -- 装备
--[[[5] = ]]function() NetManager.AllEquipTreasureRequest(0, LoadingPanel.OnStep) end, --
--[[[6] = ]]function() NetManager.GetSoulPrintDataRequest(0, LoadingPanel.OnStep) end, -- 魂印
2020-11-27 10:57:50 +08:00
--[[[7] = ]]function() NetManager.DiffMonsterRequest(0,LoadingPanel.OnStep) end, -- 异妖
2020-09-25 21:19:01 +08:00
--[[[8] = ]]function() NetManager.HeroInfoRequest(0, LoadingPanel.OnStep) end, --
--[[[9] = ]]function() NetManager.TeamInfoRequest(LoadingPanel.OnStep) end, -- 编队
--[[[10] =]] function() NetManager.GetAllMailData(LoadingPanel.OnStep) end, -- 邮件
--[[[11] =]] function() NetManager.GetAllFightDataRequest(LoadingPanel.OnStep) end, --
--[[[12] =]] function() NetManager.GetActivityAllRewardRequest(LoadingPanel.OnStep) end, -- 活动奖励
--[[[13] =]] function() NetManager.RequestBaseArenaData(LoadingPanel.OnStep) end, -- 竞技场
--[[[14] =]] function() ShopManager.InitData(LoadingPanel.OnStep) end, -- 商店
2020-11-04 14:24:08 +08:00
--[[[15] =]] --function() NetManager.GetWorkShopInfoRequest(LoadingPanel.OnStep) end, -- 工坊?
2020-09-25 21:19:01 +08:00
--[[[16] =]] function() ChatManager.InitData(LoadingPanel.OnStep) end, -- 聊天
--[[[17] =]] function() NetManager.GetAllFunState(LoadingPanel.OnStep) end, -- 功能开启信息
--[[[18] =]] function() NetManager.RequestGetFriendInfo(1, LoadingPanel.OnStep) end, -- 好友
--[[[19] =]] function() NetManager.RequestGetFriendInfo(2, LoadingPanel.OnStep) end, -- 好友申请
--[[[20] =]] function() NetManager.RequestGetFriendInfo(3, LoadingPanel.OnStep) end, -- 好友搜索
--[[[21] =]] function() NetManager.RequestGetFriendInfo(4, LoadingPanel.OnStep) end, -- 黑名单
--[[[22] =]] function() FriendChatManager.InitData(LoadingPanel.OnStep) end, -- 好友消息
--[[[23] =]] function() MyGuildManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会信息
--[[[24] =]] function() GuildFightManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会战
--[[[25] =]] function() NetManager.GetAllGuildSkillData(LoadingPanel.OnStep) end, -- 公会技能
--[[[26] =]] function() NetManager.InitFightPointLevelInfo(LoadingPanel.OnStep) end, -- 关卡
--[[[27] =]] function() NetManager.GetExpeditionRequest(ExpeditionManager.expeditionLeve,LoadingPanel.OnStep) end, -- 大闹天宫
--[[[28] =]] function() NetManager.GuildHelpGetAllRequest(LoadingPanel.OnStep) end, -- 公会援助
--[[[29] =]] function() DeathPosManager.InitData(LoadingPanel.OnStep) end, -- 十绝阵
--[[[30] =]] function() NetManager.TreasureOfHeavenScoreRequest(LoadingPanel.OnStep) end, -- 天宫秘宝积分
--[[[31] =]] function() NetManager.RankFirstRequest({3,22,20,4,21},{0,0,0,0,20},LoadingPanel.OnStep) end, -- 排行榜数据
--[[[32] =]] function() NetManager.GetSituationInfoRequest(LoadingPanel.OnStep) end,
--[[[33] =]] function() NetManager.RefreshTimeSLRequest(LoadingPanel.OnStep) end,
--[[[34] =]] function() HeroManager.CheckRepeatTreasure(LoadingPanel.OnStep) end,
2020-10-19 21:30:31 +08:00
--[[[34] =]] function() XiaoYaoManager.GetOpenMapData(LoadingPanel.OnStep) end,
2020-11-04 16:51:45 +08:00
function() NetManager.GetHeroSkinData(LoadingPanel.OnStep) end,
function() NetManager.HongMengInfoResponse(LoadingPanel.OnStep) end,
2021-03-19 16:53:00 +08:00
function() NetManager.AllBookEnableResponse(LoadingPanel.OnStep) end,
2021-05-14 19:11:40 +08:00
function() NetManager.AllEndLessHeroDataResponse(0, LoadingPanel.OnStep) end,
2021-05-21 16:39:08 +08:00
function() NetManager.GetEndlessTreasureInfoResponse(LoadingPanel.OnStep) end,
2021-05-21 14:47:04 +08:00
function() MyGuildManager.ReuqsetRedPackage(LoadingPanel.OnStep) end,
2021-05-17 20:08:33 +08:00
function() NetManager.HardStageRequest(LoadingPanel.OnStep) end,
2021-05-20 15:47:15 +08:00
function() NetManager.VipLevelStateRequset(LoadingPanel.OnStep) end,
2021-06-15 20:08:14 +08:00
function() JumpServerManager.LoginGetWorldArenaInfoRequest(LoadingPanel.OnStep) end,
2021-05-28 12:36:39 +08:00
function() NetManager.RequestRedPacketData(LoadingPanel.OnStep) end,
function() NetManager.BeautyBagWishEquipRequest(nil,LoadingPanel.OnStep) end,
function() LingLongBaoJingManager.InitData(LoadingPanel.OnStep) end,
2021-07-29 16:35:58 +08:00
function() NetManager.IsCrossRequert(LoadingPanel.OnStep) end,
--[[[35] =]] function() -- 登录请求最终接口,所有请求放在此接口之前
-- 登录成功确认
NetManager.LoginConfimRequest()
2020-06-03 19:09:01 +08:00
if AppConst.isGuide then
if GuideManager.GetCurId(GuideType.Force) == 1 and PlayerManager.nickName == tostring(PlayerManager.uid) and PlayerManager.level == 1 then
2021-03-15 20:16:03 +08:00
-- 新的引导
-- StoryManager.EventTrigger(300001)
2020-06-03 19:09:01 +08:00
--创号阶段先进入剧情对话,进入假战斗,然后对话起名,最后进入主界面
StoryManager.EventTrigger(300007)
2021-03-19 11:10:48 +08:00
-- 新的引导
2021-04-12 18:11:37 +08:00
-- StoryManager.EventTrigger(100001)
2020-09-25 14:11:05 +08:00
else
PatFaceManager.isLogin = true
UIManager.OpenPanel(UIName.FightPointPassMainPanel)
LoadingPanel.End()
2020-05-09 13:31:21 +08:00
end
2020-06-03 19:09:01 +08:00
else
UIManager.OpenPanelAsync(UIName.MainPanel, function()
if RoomManager.RoomAddress == nil or RoomManager.RoomAddress == "" then
RoomManager.IsMatch = 0
elseif RoomManager.RoomAddress == "1" then
RoomManager.IsMatch = 1
UIManager.OpenPanel(UIName.GMPanel)
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[11141])
2020-06-03 19:09:01 +08:00
else
if RoomManager.CurRoomType == 1 then
Log("在房间里,需要重新获取房间游戏数据~~~~~~~~~~")
2020-06-03 19:09:01 +08:00
RoomManager.RoomReGetGameRequest(RoomManager.RoomAddress)
end
2020-05-09 13:31:21 +08:00
end
2020-06-03 19:09:01 +08:00
LoadingPanel.End()
end)
end
-- 登录成功刷新红点数据
RedpotManager.CheckAllRedPointStatus()
-- 检查新字状态
FunctionOpenMananger.InitCheck()
this.SubmitGameData()
DataCenterManager.CommitBootStatus()
end,
}
--
for _, func in ipairs(requestList) do
LoadingPanel.AddStep(func)
end
2020-05-09 13:31:21 +08:00
LoadingPanel.Start()
this:ClosePanel()
end
2020-08-22 15:31:14 +08:00
this.isLoginClick = false
2020-05-09 13:31:21 +08:00
function this.OnLoginClick()
if IsUserProtoActive and HaveConfirm and PlayerPrefs.GetInt("IHaveConfirmProtos") == 0 then
2021-06-24 11:38:43 +08:00
PopupTipPanel.ShowTip("为了保证您的个人隐私和隐私安全,请详细阅读并同意用户协议及隐私政策")
return
end
-- 只要不是流畅,拥挤,爆满状态就不让登录
if not LoginManager.IsServerStateEnterable(LoginManager.state) then
2020-08-22 15:31:14 +08:00
local function reServerCallback(str)
if str == nil then
return
end
if str ~= nil and str ~= "" then
MyPCall(function()
local json = require 'cjson'
local data = json.decode(str)
---selectServerPart
this.SetServerList(data)
-- 还是不可进状态则提示服务器维护中
if not LoginManager.IsServerStateEnterable(LoginManager.state) then
PopupTipPanel.ShowTip("服务器还未开启哦,请道友稍后片刻,具体开服时间可见公告~")
2020-08-22 15:31:14 +08:00
RequestPanel.Hide()
else
-- 开始登录
this.RequestHttpLogin()
2020-08-22 15:31:14 +08:00
end
end)
end
end
-- 判断获取服务器的id
if IsSDKLogin then
this.RequestServerList(AppConst.OpenId, reServerCallback)
else
local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
this.RequestServerList(userId, reServerCallback)
end
return
end
2020-08-22 15:31:14 +08:00
-- 开始登录
this.RequestHttpLogin()
2020-08-22 15:31:14 +08:00
end
-----------++++++++++++++++++++++++++++++++++++++++ http +++++++++++++++++++++++++++++
-- 登录服请求登录
function this.RequestHttpLogin()
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11144])
local url = ""
local user_channel = LoginRoot_UserChannel == "" and LoginRoot_Channel or LoginRoot_UserChannel
2020-06-30 18:59:44 +08:00
if IsSDKLogin then
url = LoginRoot_Url
.. "jl_loginserver/getUserInfo?openId=" .. AppConst.OpenId
2020-07-16 19:51:38 +08:00
.. "&serverId=" .. LoginManager.ServerId
.. "&token=" .. AppConst.TokenStr
.. "&platform=" .. 1
.. "&channel=" .. user_channel
2020-07-16 19:51:38 +08:00
.. "&sub_channel=" .. LoginRoot_SubChannel
.. "&pid=" .. AppConst.SdkChannel --LoginManager.pt_pId
2020-07-24 10:22:20 +08:00
.. "&gid=" .. AppConst.SdkPackageName --LoginManager.pt_gId
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp="..LoginManager.SdkLoginTimeStamp
.. "&ext="..encodeURI(LoginManager.extData)
.. "&platform_appid="..LoginManager.p_appId
2020-05-09 13:31:21 +08:00
else
2020-06-30 18:59:44 +08:00
if IsDevelopLogin then
-- 开发用
local str = this.inputField.text
PlayerPrefs.SetString(openIdkey, str)
url = LoginRoot_Url
2020-06-30 18:59:44 +08:00
.. "jl_loginserver/getUserInfo?openId=" .. str
2020-05-09 13:31:21 +08:00
.. "&serverId=" .. LoginManager.ServerId
2020-06-30 18:59:44 +08:00
.. "&token=111"
2020-08-22 15:31:14 +08:00
.. "&platform=1"
.. "&channel=" .. user_channel
2020-06-30 18:59:44 +08:00
.. "&sub_channel=" .. LoginRoot_SubChannel
.. "&admin=d53b3e8ef74bf72d8aafce3a1c8671a0"
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp=0"
2020-05-09 13:31:21 +08:00
else
url = LoginRoot_Url
2020-06-30 18:59:44 +08:00
.. "jl_loginserver/getUserInfo?openId=" ..LoginManager.openId
2020-05-09 13:31:21 +08:00
.. "&serverId=" .. LoginManager.ServerId
2020-06-30 18:59:44 +08:00
.. "&token=" .. LoginManager.token
.. "&platform=4"
.. "&channel=" .. user_channel
2020-06-30 18:59:44 +08:00
.. "&sub_channel=" .. LoginRoot_SubChannel
2020-08-25 15:51:35 +08:00
.. "&admin=d53b3e8ef74bf72d8aafce3a1c8671a0"
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp=0",
this.OnReceiveLogin, nil, nil, nil
2020-06-30 18:59:44 +08:00
end
2020-05-09 13:31:21 +08:00
end
Log(url)
2021-07-13 18:24:33 +08:00
LoginManager:SendGetHttp(url, this.OnReceiveLogin, nil, nil, nil)
end
2020-05-09 13:31:21 +08:00
--用户id登录
function this.OnReceiveLogin(str)
RequestPanel.Hide()
if str == nil then
return
end
if str ~= nil and str ~= "" then
MyPCall(function()
Log(str)
local json = require 'cjson'
local data = json.decode(str)
if data.errorCode and data.errorCode == -1 then
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(data.reason or Language[11145])
return
end
if data.uid and data.token and not LoginManager.IsLogin then
AppConst.UserId = data.uid
AppConst.Token = data.token
this.RequestSocketLogin()
end
end)
end
2020-05-09 13:31:21 +08:00
end
-----------++++++++++++++++++++++++++++++++++++++++ http +++++++++++++++++++++++++++++
2020-05-09 13:31:21 +08:00
-----------++++++++++++++++++++++++++++++++++++++++ socket +++++++++++++++++++++++++++++
-- 请求连接socket
function this.RequestSocketLogin()
Log("请求连接Socket")
2021-04-09 12:26:35 +08:00
RequestPanel.Show(Language[11143])
SocketManager.Disconnect(SocketType.LOGIN)
SocketManager.AddNetwork(SocketType.LOGIN, LoginManager.SocketAddress, LoginManager.SocketPort)
SocketManager.TryConnect(SocketType.LOGIN)
end
function this.OnConnect(network)
local openId = AppConst.isSDKLogin and AppConst.OpenId or PlayerPrefs.GetString(openIdkey)
NetManager.LoginRequest(openId, function()
if not LoginManager.IsLogin then
LoginManager.IsLogin = true
this.ExecuteLoading()
end
RequestPanel.Hide()
end)
end
2020-05-09 13:31:21 +08:00
function this.OnDisconnect(network)
RequestPanel.Hide()
2021-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[11145])
2020-05-09 13:31:21 +08:00
end
-----------++++++++++++++++++++++++++++++++++++++++ socket +++++++++++++++++++++++++++++
2020-05-09 13:31:21 +08:00
function this.SetLoginPart(flag)
this.loginAnim.enabled = flag
this.btnLoginPart:SetActive(flag and tostring(this.bgStr) == "dl_ui_effect_bg")
2020-08-25 17:56:55 +08:00
this.btnLogin:SetActive(flag)
2020-05-09 13:31:21 +08:00
this.serverSelectPart:SetActive(flag)
end
function this.SubmitGameData()
local isNewRole = PlayerPrefs.GetString(tostring(PlayerManager.uid), "")
if isNewRole == "" and PlayerManager.level == 1 then
2020-05-09 13:31:21 +08:00
PlayerPrefs.SetString(tostring(PlayerManager.uid), tostring(PlayerManager.uid))
SubmitExtraData({ type = SDKSubMitType.TYPE_CREATE_ROLE })
end
SubmitExtraData({ type = SDKSubMitType.TYPE_ENTER_GAME })
end
2020-06-23 18:36:24 +08:00
return LoginPanel