require("Base/BasePanel")
LoginPanel = Inherit(BasePanel)
local this = LoginPanel
this.LoginWay = { Account = 0, WeChat = 1 }
SERVER_VERSION = tonumber(ServerConfigManager.GetSettingValue(ServerConfigManager.SettingConfig.ServerVersion) or 0)
local IsShowNotice = false
local IsSDKLogin = AppConst.isSDK and AppConst.isSDKLogin
local IsDevelopLogin = true
local openIdkey = "openIdkey"
local openIdPw = "openIdPw"
local defaultOpenIdkey = Language[11711]
local defaultOpenIdPw = ""
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 ""
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))
local UrlList = {}
local HaveConfirm = false
--初始化组件(用于子类重写)
function this:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
this.loginPart = this.gameObject
this.tip = Util.GetGameObject(this.loginPart, "tip/Text")
this.loginAnim = this.gameObject:GetComponent("Animator")
this.loginAnim.enabled = false
this.btnLoginPart = Util.GetGameObject(this.loginPart, "jinruyouxi")
this.btnLogin = Util.GetGameObject(this.loginPart, "jinruyouxi _wenzi")
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")
this.btnAgeTip = Util.GetGameObject(this.loginPart, "btnAgeTip")
this.btnAgeTip:SetActive(IsUserProtoActive)
this.btnAgeTipPosition = this.btnAgeTip:GetComponent("RectTransform").localPosition
this.btnNotice:SetActive(IsShowNotice)
--反馈邮箱
this.fankui = Util.GetGameObject(this.loginPart, "fankui")
if this.fankui then
local fankuiText = this.fankui:GetComponent("Text")
fankuiText.text = ServerConfigManager.GetSettingValue(ServerConfigManager.SettingConfig.SHOW_EMAIL_LOGIN) or ""
end
---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)
this.loginMask = Util.GetGameObject(this.loginPart, "loginMask")
this.versionText = Util.GetGameObject(this.loginPart, "version"):GetComponent("Text")
this.versionText.text = Language[11712] .. 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
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)
else
this.logo.gameObject:SetActive(false)
end
--this.logo.gameObject:SetActive(false)
-- BindLightFlash(Util.GetGameObject(this.logo, "saoguang"), this.logo)
this.healthTip = Util.GetGameObject(this.gameObject, "healthTip")
this.healthTip:SetActive(IS_SHOW_HEALTH_TIP)
this.bh = Util.GetGameObject(this.gameObject, "healthTip/bh"):GetComponent("Text")
local bhContent = PackageManager.GetBHContent()
-- LogError(tostring(bhContent))
if bhContent then
this.bh.text = bhContent
else
this.bh.text = ""
end
this.video = Util.GetGameObject(this.gameObject, "VideoPlayer")
--用户隐私协议
this.protos = Util.GetGameObject(this.gameObject, "protos")
this.newproto = Util.GetGameObject(this.gameObject, "newProto")
this.instructionsBtn = Util.GetGameObject(this.gameObject, "protos/instructionsBtn")
this.privacyBtn = Util.GetGameObject(this.gameObject, "protos/privacyBtn")
this.boyBtn = Util.GetGameObject(this.gameObject, "newProto/boyBtn")
this.thirdBtn = Util.GetGameObject(this.gameObject, "newProto/thirdBtn")
this.ConfirmBtn = Util.GetGameObject(this.gameObject, "protos/Confirm")
this.ConfirmImg = Util.GetGameObject(this.ConfirmBtn, "gou")
this.protos:SetActive(IsUserProtoActive)
this.newproto:SetActive(false)
this.beianBtn = Util.GetGameObject(this.gameObject, "healthTip/beianTxt")
Util.GetGameObject(this.gameObject, "healthTip/beianTxt"):GetComponent("Text").text = "beian.miit.gov.cn"
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()
end)
Util.AddClick(this.btnAgeTip, function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.AgeTip, this.btnAgeTipPosition.x, this.btnAgeTipPosition.y)
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
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)
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"complete_change_server",
roleCreateTime = "server_name_after|" ..
tostring(this.serverList[index].server_id ..
"|server_name_before|" .. tostring(PlayerManager.serverInfo.server_id))
})
LogError("server_name_before:" .. PlayerManager.serverInfo.name)
LogError("server_name_after:" .. tostring(this.serverList[index].name))
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" .. severArea .. "" .. Language[11713]
end
})
SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "show_server_list" })
end)
end
end
-- 判断获取服务器的id
if IsSDKLogin then
this.RequestServerList(AppConst.OpenId, reServerCallback)
else
local userId = PlayerPrefs.GetString(openIdkey, defaultOpenIdkey)
this.RequestServerList(userId, reServerCallback)
end
SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "click_change_server" })
end)
--SDK 登录
Util.AddClick(this.sdkLoginBtn, function()
-- 喜扑IOS包sdk无法屏蔽点击事件,不允许主动触发
if LoginRoot_Channel == "XP2" then
return
end
this.SDKLogin()
end)
--用户隐私协议
Util.AddClick(this.instructionsBtn, function()
OpenWeb(UrlList[1])
end)
Util.AddClick(this.privacyBtn, function()
OpenWeb(UrlList[2])
end)
Util.AddClick(this.boyBtn, function()
OpenWeb("http://smi.648sy.com/about/child")
end)
Util.AddClick(this.thirdBtn, function()
OpenWeb("http://smi.648sy.com/about/share")
end)
Util.AddClick(this.beianBtn, function()
OpenWeb("https://beian.miit.gov.cn/#/Integrated/index")
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
end)
end
-- sdk 初始化完成回调
function this.OnInitSuccess()
this.SDKLogin()
end
--添加事件监听(用于子类重写)
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)
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
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)
--LogError("userid=="..userId)
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
RequestPanel.Show(Language[11714])
this.SetLoginPart(true)
-- 获取服务器列表
this.RequestServerList(userId, this.OnReceiveServerList)
end
end
function this:OnSortingOrderChange()
Util.AddParticleSortLayer(self.gameObject, self.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
end
--界面打开时调用(用于子类重写)
function this:OnOpen(...)
-- local url="http://82.157.34.193:9991/delivery/ohayooGetExternal"
-- local data="body;高级基金;notify_url;http://82.157.34.193:9991/delivery/OhayooCallback;open_id;32AtGSX36PYLuNbx;custom_callback_info;20001190_78_4001_IOS;order_no;200011901931657796390;product_id;78;sign_type;MD5;subject;高级基金;total_amount;12800;trade_time;1657796390;valid_time;2592000"
-- HttpManager:SendPostHttp(url,data, this.OnReceiveLogin, nil, nil, nil)
--设置背景
SubmitExtraData({ type = SDKSubMitType.TYPE_RESOURCE_DOWNLOAD_SUCCESS })
PackageManager.SetVideo(this.video, this.bg)
if AppConst.Code ~= "" then
MsgPanel.ShowOne(GetLanguageStrById(AppConst.Code))
AppConst.Code = ""
end
if IsSDKLogin then
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
RequestPanel.Show(Language[11714])
this.SetLoginPart(true)
-- 获取服务器列表
this.RequestServerList(userId, this.OnReceiveServerList)
end
local tran = this.tip:GetComponent("RectTransform")
--LayoutUtility.GetPreferredWidth(tran)
local offsetX = (GetPreferredWidth(tran) + Screen.width) / 2
tran.anchoredPosition = Vector2.New(offsetX, 0)
tran:DOAnchorPosX(-offsetX, 30, false):SetEase(Ease.Linear):SetLoops(-1)
-- 初始化一些数据
LoginManager.InitPackInfo()
SoundManager.PlayMusic(SoundConfig.BGM_Login)
SoundManager.PlayAmbient(SoundConfig.Ambient_Login)
-- local data = {}
-- local godData = this.GetGodSoulDataByLv(10023,5)
-- local godSingleDatas = {}
-- for i = 1,#godData do
-- godSingleDatas[i] = 0
-- end
-- local curHeroData = {}
-- --用条件进行匹配,使得满足条件
-- GodSoulManager.PutQueen(godData, godDatas, 1,godSingleDatas,curHeroData,5)
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()
RequestPanel.Show(Language[11715])
--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
noticeChannel = noticeChannel .. packID
end
end
]]
local url = LoginRoot_Url ..
"jl_loginserver/getNotice?timestamp=" .. timeStamp .. "&sign=" .. timeSign .. "&packageName=" .. noticeChannel
HttpManager:SendGetHttp(url, function(str)
UIManager.OpenPanel(UIName.NoticePopup, str)
end, nil, nil, nil)
end
-- 请求获取
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
HttpManager:SendGetHttp(url, function(str)
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
-- 请求获取服务器列表
function this.RequestServerList(userId, callback)
this.RequestServerVersion(function()
this.CheckNoticeShow()
--userId=100
RequestPanel.Show(Language[11714])
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)
LogError("获取服务器列表url:" .. url)
SubmitExtraData({ type = SDKSubMitType.TYPE_GETSERVERLIST })
HttpManager:SendGetHttp(url, callback, nil, nil, function(msg)
SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "get_server_list_error" })
end)
end)
--用户协议,隐私政策
this.RequestProtos(userId)
end
--获取用户隐私协议
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 chanel = AppConst.SdkChannel
local ChannelID = LoginRoot_UserChannel == "" and LoginRoot_Channel or LoginRoot_UserChannel
local PackageID = PackageManager.GetPackageID()
if PackageID then
ChannelID = ChannelID .. PackageID
end
local url = LoginRoot_Url .. "jl_loginserver/getAgreement?gamePack=" .. ChannelID
LogError("协议地址为==" .. url)
HttpManager: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)
this.newproto:SetActive(false)
Log("用户和隐私协议地址为空")
HaveConfirm = false
return
end
if UrlList[1] ~= "" and UrlList[2] ~= "" then
this.protos:SetActive(true)
if chanel and (chanel == "ZZXX" or chanel == "ZZXXXQ") then
this.newproto:SetActive(true)
else
this.newproto:SetActive(false)
end
HaveConfirm = true
else
this.protos:SetActive(false)
this.newproto:SetActive(false)
HaveConfirm = false
end
end, nil, nil, nil)
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
this.spLoader:Destroy()
PackageManager.UnloadVideo()
end
this.isWaiting = false
function this.SDKLogin()
if not this.isWaiting then
this.isWaiting = true
Timer.New(function()
SDKMgr:Login()
this.isWaiting = false
end, 1, 1):Start()
end
end
function this.RefreshLoginStatus(result)
if result == SDK_RESULT.SUCCESS then
RequestPanel.Show(Language[11714])
this.SetLoginPart(true)
this.sdkLoginBtn:SetActive(false)
-- 获取服务器列表
this.RequestServerList(AppConst.OpenId, this.OnReceiveServerList)
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
end
if str ~= nil and str ~= "" then
MyPCall(function()
local json = require 'cjson'
local data = json.decode(str)
SubmitExtraData({ type = SDKSubMitType.TYPE_GETSERVERLISTSUCCESS })
---selectServerPart
this.SetServerList(data)
if not IsSDKLogin and not IsDevelopLogin then
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
if IsShowNotice then
this.loginMask:SetActive(true)
Timer.New(function()
this.ShowNotice()
this.loginMask:SetActive(false)
end, 2.5, 1):Start()
end
end
end)
end
else
if IsShowNotice then
this.loginMask:SetActive(true)
Timer.New(function()
this.ShowNotice()
this.loginMask:SetActive(false)
end, 2.5, 1):Start()
end
end
end)
end
end
function this.SetServerList(data)
this.CacheLoginData(data)
-- 默认选择第一个服务器
local lastIndex = 1
-- 判断要显示的服务器
local showServer
if this.lastServer then --有最近登录显示最近登录,没有显示推荐,否则显示第一个服
showServer = this.lastServer.serverid
else
if this.recommend then
showServer = this.recommend
end
end
-- 如果有要显示的服务器判断位置
if showServer then
for i = 1, #this.serverList do
if this.serverList[i].server_id == showServer then
lastIndex = i
break
end
end
end
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
--local severArea = tonumber(string.sub(this.serverList[lastIndex].server_id, 0, -5))
this.serverMes.text = PlayerManager.serverInfo
.name -- .. "\t" .. severArea .. "" .. Language[11713]
RequestPanel.Hide()
end
function this.CacheLoginData(data)
this.serverList = {}
for i = 1, #data.serverList do
this.serverList[i] = data.serverList[i]
end
--取消serverId排序,改用后端原数据,手动把isnew的数据插入到第一个
local tempList = {}
for i = 1, #this.serverList do
if this.serverList[i].isnew > 0 then
local tempData = this.serverList[i]
for j = i, 2, -1 do
this.serverList[j] = this.serverList[j - 1]
end
this.serverList[1] = tempData
break
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()
local requestList = {
--[[[1] = ]] function() NetManager.PlayerInfoRequest(LoadingPanel.OnStep) end, -- 基础信息
--[[[2] = ]] function() NetManager.GetComparenumInfoRequest(LoadingPanel.OnStep) end, -- 数字游戏信息
--[[[2] = ]] function() NetManager.RequestMission(LoadingPanel.OnStep) end, -- 任务信息
--[[[3] = ]] function() NetManager.ItemInfoRequest(0, LoadingPanel.OnStep) end, -- 物品信息
--[[[4]=]] function() NetManager.CrossServerStatusRequest(LoadingPanel.OnStep) end, -- 装备(走背包了)
--[[[5] = ]] function() NetManager.AllEquipTreasureRequest(0, LoadingPanel.OnStep) end, -- 宝物
-- [[[6] = ]]function() NetManager.GetSoulPrintDataRequest(0, LoadingPanel.OnStep) end, -- 魂印(走背包了)
--[[[5] = ]] function() NetManager.GetAllFaXiangRequest(1, LoadingPanel.OnStep) end, -- 法相
--[[[6] =]] function() NetManager.AllBookEnableResponse(LoadingPanel.OnStep) end, --天枢密卷
--[[[7] = ]] function() NetManager.DiffMonsterRequest(0, LoadingPanel.OnStep) end, -- 异妖
--[[[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, -- 商店
--function() NetManager.GetWorkShopInfoRequest(LoadingPanel.OnStep) end, -- 工坊?
--[[[15] =]] function() ChatManager.InitData(LoadingPanel.OnStep) end, -- 聊天
--[[[16] =]] function() NetManager.GetAllFunState(LoadingPanel.OnStep) end, -- 功能开启信息
--[[[17] =]] function() NetManager.RequestGetFriendInfo(1, LoadingPanel.OnStep) end, -- 好友
--[[[18] =]] function() NetManager.RequestGetFriendInfo(2, LoadingPanel.OnStep) end, -- 好友申请
--[[[19] =]] function() NetManager.RequestGetFriendInfo(3, LoadingPanel.OnStep) end, -- 好友搜索
--[[[20] =]] function() NetManager.RequestGetFriendInfo(4, LoadingPanel.OnStep) end, -- 黑名单
--[[[21] =]] function() FriendChatManager.InitData(LoadingPanel.OnStep) end, -- 好友消息
--[[[22] =]] function() MyGuildManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会信息
--function() GuildFightManager.InitBaseData(LoadingPanel.OnStep) end, -- 公会战
--[[[23] =]] function() NetManager.GetAllGuildSkillData(LoadingPanel.OnStep) end, -- 公会技能
--[[[24] =]] function() NetManager.InitFightPointLevelInfo(LoadingPanel.OnStep) end, -- 关卡
--[[[25] =]] function() NetManager.GetExpeditionRequest(ExpeditionManager.expeditionLeve, LoadingPanel.OnStep) end, -- 大闹天宫
--[[[26] =]] function() NetManager.GuildHelpGetAllRequest(LoadingPanel.OnStep) end, -- 公会援助
--[[[27] =]] function() DeathPosManager.InitData(LoadingPanel.OnStep) end, -- 十绝阵
--[[[28] =]] function() NetManager.TreasureOfHeavenScoreRequest(LoadingPanel.OnStep) end, -- 天宫秘宝积分
--[[[29] =]] function()
NetManager.RankFirstRequest({ 3, 22, 20, 4, 21 }, { 0, 0, 0, 0, 20 }, LoadingPanel
.OnStep)
end, -- 排行榜数据
--[[[30] =]] function() NetManager.GetSituationInfoRequest(LoadingPanel.OnStep) end, --轩辕宝镜
--[[[31] =]] function() NetManager.RefreshTimeSLRequest(LoadingPanel.OnStep) end, --青龙秘宝倒计时
--[[[32] =]] function() HeroManager.CheckRepeatTreasure(LoadingPanel.OnStep) end, --检测所有重复穿戴的宝器并卸下
--[[[33] =]] function() XiaoYaoManager.GetOpenMapData(LoadingPanel.OnStep) end, --逍遥游
--[[[34] =]] function() NetManager.GetHeroSkinData(LoadingPanel.OnStep) end, --皮肤
--[[[35] =]] function() NetManager.GetFourElementGetInfo(LoadingPanel.OnStep) end, --四灵试炼
--[[[35] =]] function() NetManager.GetChallengeCopyInfo(LoadingPanel.OnStep) end, --挑战副本
--[[[36] =]] function() MonsterCampManager.SetMyHelpHeroData(nil, nil, LoadingPanel.OnStep) end, --助战神将
--[[[37] =]] function() NetManager.HongMengInfoResponse(LoadingPanel.OnStep) end, --鸿蒙阵
--[--[[38] =]]function() NetManager.AllBookEnableResponse(LoadingPanel.OnStep) end, --天枢密卷
--[[[39] =]] function() NetManager.AllEndLessHeroDataResponse(0, LoadingPanel.OnStep) end, --无尽英雄数据
--[[[40] =]] function() NetManager.GetEndlessTreasureInfoResponse(LoadingPanel.OnStep) end, --无尽密保
--[[[41] =]] function() MyGuildManager.ReuqsetRedPackage(LoadingPanel.OnStep) end, --请求红包
--[[[42] =]] function() NetManager.HardStageRequest(LoadingPanel.OnStep) end, --山河社稷图
--[[[43] =]] function() NetManager.VipLevelStateRequset(LoadingPanel.OnStep) end, --vip
--[[[44] =]] function() NetManager.RequestRedPacketData(LoadingPanel.OnStep) end, --福利红包
--[[[45] =]] function() NetManager.BeautyBagWishEquipRequest(nil, LoadingPanel.OnStep) end, --心愿魂印
--[[[46] =]] function() LingLongBaoJingManager.InitData(LoadingPanel.OnStep) end, --玲珑宝镜
--[[[47] =]] function() NetManager.IsCrossRequert(LoadingPanel.OnStep) end, --跨服
--[[[48] =]] function()
NetManager.TaiChuSecretvolumeRequest(LoadingPanel.OnStep)
--SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "complete_loading2_50%" })
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"complete_loading2_50%",
roleCreateTime = "server_name|" ..
tostring(PlayerManager.serverInfo.name) ..
"|server_id|" .. tostring(PlayerManager.serverInfo
.server_id)
})
LogError("**************************server_name|" ..
tostring(PlayerManager.serverInfo.name) .. "|server_id|" .. tostring(PlayerManager.serverInfo.server_id))
end, --太初密卷
--[[[49] =]] function() NetManager.CrossYuXuLunDaoGetInfoRequest(2, LoadingPanel.OnStep) end, --玉虚论道红点
--[[[50] =]] function() NetManager.GetLikeableDataRequest(LoadingPanel.OnStep) end, --好感度
--[[[51] =]] function() NetManager.GetTransformationRequest(LoadingPanel.OnStep) end, --身外化身
--[[[52] =]] function() NetManager.GetLingMaiInfoRequest(0, LoadingPanel.OnStep) end, --灵脉秘境
--[[[53] =]] function() NetManager.SendGetTailsmanSoulData(LoadingPanel.OnStep) end, --法宝之灵
--[[[54] =]] --function() NetManager.RequestArenaRankData(1,LoadingPanel.OnStep) end, --获取竞技场数据
--[[[55] =]] function() HomeLandManager.GetData(LoadingPanel.OnStep) end, --家园获取数据
--[[[56] =]] function() NetManager.ExplorerMapInfoRequest(LoadingPanel.OnStep) end, --灵脉秘境
--[[[57] =]] function() CommonActPageManager.GetPowerRicePower(LoadingPanel.OnStep) end, --战力冲刺
--[[[58] =]] function() NetManager.RequestMagicSoldierInfo(LoadingPanel.OnStep) end, --神兵
--[[[59] =]] function() NetManager.GemNewInfoRequest(LoadingPanel.OnStep) end, --新命石
--[[[60] =]] function() NetManager.BaublesAllInfoRequest(LoadingPanel.OnStep) end, --新法宝
--[[[61] =]] function() NetManager.TrainingArchitectureInfoRequest(LoadingPanel.OnStep) end, --特训信息
--[[[62] =]] function() NetManager.NewArenaResetRequest(LoadingPanel.OnStep) end, -- 竞技场
--[[[63] =]] function() NetManager.GetNewArenaInfoRequest(LoadingPanel.OnStep) end, -- 竞技场
--[[[64] =]] function() NetManager.GetSoldiersInfoRequest(LoadingPanel.OnStep) end, --小兵
--[[[65] =]] function() NetManager.BaublesAllInfoRequest(LoadingPanel.OnStep) end, --新法宝
--[[[66] =]] function() NetManager.TrainingArchitectureInfoRequest(LoadingPanel.OnStep) end,
--[[[67] =]] function() NetManager.QueryBookImageRequest(6, LoadingPanel.OnStep) end,
--[[[68] =]] function() NetManager.QueryBookImageRequest(7, LoadingPanel.OnStep) end,
--[[[69] =]] function() NetManager.QueryBookImageRequest(8, LoadingPanel.OnStep) end,
--[[[70] =]] function() NetManager.QueryLuofuRegisterInfoRequest(LoadingPanel.OnStep) end,
--[[[71] =]] function() JumpServerManager.LoginGetWorldArenaInfoRequest(LoadingPanel.OnStep) end, --跨服天梯
--[[[72] =]] function() NetManager.AssistInfoRequest(LoadingPanel.OnStep) end,
----[[[73] =]]function() NetManager.AnewRechargeOrderRequest(LoadingPanel.OnStep) end,
function() -- 登录请求最终接口,所有请求放在此接口之前
-- 登录成功确认
NetManager.LoginConfimRequest()
NetManager.AnewRechargeOrderRequest()
-- 登录时初始化主界面竖条显示为打开状态
PlayerPrefs.SetInt(PlayerManager.uid .. "MainRightBarSetting", 1)
if AppConst.isGuide then
if GuideManager.GetCurId(GuideType.Force) == 1 and PlayerManager.nickName == tostring(PlayerManager.uid) and PlayerManager.level == 1 then
-- 新的引导
-- StoryManager.EventTrigger(300001)
--创号阶段先进入剧情对话,进入假战斗,然后对话起名,最后进入主界面
StoryManager.EventTrigger(300007)
-- 新的引导
-- StoryManager.EventTrigger(100001)
else
PatFaceManager.isLogin = true
UIManager.OpenPanel(UIName.FightPointPassMainPanel)
LoadingPanel.End()
--SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "complete_loading_2" })
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"complete_loading_2",
roleCreateTime = "server_name|" ..
tostring(PlayerManager.serverInfo.name) ..
"|server_id|" .. tostring(PlayerManager.serverInfo
.server_id)
})
end
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)
-- PopupTipPanel.ShowTip("您已经在请求匹配血战游戏了,请耐心等待匹配成功")
-- else
-- if RoomManager.CurRoomType == 1 then
-- Log("在房间里,需要重新获取房间游戏数据~~~~~~~~~~")
-- RoomManager.RoomReGetGameRequest(RoomManager.RoomAddress)
-- end
-- end
LoadingPanel.End()
--SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "complete_loading_2" })
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"complete_loading_2",
roleCreateTime = "server_name|" ..
tostring(PlayerManager.serverInfo.name) ..
"|server_id|" .. tostring(PlayerManager.serverInfo
.server_id)
})
end)
end
LogError("开始调用日志上报--------------------------------------------------------")
LogBlue("调用日志上报")
this.SubmitGameData()
if OperatingManager.IsBuyGift(78) == false then
PlayerPrefs.SetInt(PlayerManager.uid .. "chaozhijijin128", 0)
end
if OperatingManager.IsBuyGift(79) == false then
PlayerPrefs.SetInt(PlayerManager.uid .. "chaozhijijin328", 0)
end
PlayerPrefs.SetInt(PlayerManager.uid .. "XunBaoMiZong_zqbg", 0)
local dailyActInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.yunmenghaoli)
if dailyActInfo and #dailyActInfo.mission > 0 then
-- 每天检测
PlayerPrefs.SetInt(PlayerManager.uid .. "_YunMeng_Check" .. dailyActInfo.activityId, 0)
end
-- 登录成功刷新红点数据
RedpotManager.CheckAllRedPointStatus()
-- 检查新字状态
FunctionOpenMananger.InitCheck()
DataCenterManager.CommitBootStatus()
end,
}
--
for _, func in ipairs(requestList) do
LoadingPanel.AddStep(func)
end
LoadingPanel.Start()
this:ClosePanel()
--SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "start_loading_2" })
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"start_loading_2",
roleCreateTime = "server_name|" ..
tostring(PlayerManager.serverInfo.name) ..
"|server_id|" .. tostring(PlayerManager.serverInfo
.server_id)
})
end
this.isLoginClick = false
function this.OnLoginClick()
if IsUserProtoActive and HaveConfirm and PlayerPrefs.GetInt("IHaveConfirmProtos") == 0 then
PopupTipPanel.ShowTip(Language[11716])
return
end
-- 只要不是流畅,拥挤,爆满状态就不让登录
if not LoginManager.IsServerStateEnterable(LoginManager.state) then
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(Language[11717])
RequestPanel.Hide()
else
-- 开始登录
this.RequestHttpLogin()
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
-- 开始登录
this.RequestHttpLogin()
--SubmitExtraData({ type = SDKSubMitType.TYPE_CUSTOM, roleLevelUpTime = "click_play_game" })
SubmitExtraData({
type = SDKSubMitType.TYPE_CUSTOM_PARAMS,
roleLevelUpTime =
"click_play_game",
roleCreateTime = "server_name|" ..
tostring(PlayerManager.serverInfo.name) ..
"|server_id|" .. tostring(PlayerManager.serverInfo
.server_id)
})
end
-----------++++++++++++++++++++++++++++++++++++++++ http +++++++++++++++++++++++++++++
-- 登录服请求登录
function this.RequestHttpLogin()
RequestPanel.Show(Language[11718])
local url = ""
local user_channel = LoginRoot_UserChannel == "" and LoginRoot_Channel or LoginRoot_UserChannel
local tokenStr = AppConst.TokenStr
local Platform = 1
-- if user_channel~="pc" then
-- local chanel= SDKMgr:GetChannel()
-- if chanel and chanel=="Ohayoo" then
-- tokenStr =encodeURI(AppConst.TokenStr)
-- LogError("AppConst.TokenStr============"..tokenStr)
-- Platform=3
-- end
-- end
if IsSDKLogin then
url = LoginRoot_Url
.. "jl_loginserver/getUserInfo?openId=" .. AppConst.OpenId
.. "&serverId=" .. LoginManager.ServerId
.. "&token=" .. tokenStr
.. "&platform=" .. Platform
.. "&channel=" .. user_channel
.. "&sub_channel=" .. LoginRoot_SubChannel
.. "&pid=" .. AppConst.SdkChannel --LoginManager.pt_pId
.. "&gid=" .. AppConst.SdkPackageName --LoginManager.pt_gId
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp=" .. LoginManager.SdkLoginTimeStamp
.. "&ext=" .. encodeURI(LoginManager.extData)
.. "&platform_appid=" .. LoginManager.p_appId
-- .. "&userId="..LoginManager.qyUserId
-- .. "&platformId="..LoginManager.qyPlatformId
-- .. "×tamp="..LoginManager.qyTimestamp
-- .. "&sign="..LoginManager.qySign
else
if IsDevelopLogin then
-- 开发用
local str = this.inputField.text
if str == Language[11711] then
RequestPanel.Hide()
PopupTipPanel.ShowTip(Language[11711])
return
end
PlayerPrefs.SetString(openIdkey, str)
url = LoginRoot_Url
.. "jl_loginserver/getUserInfo?openId=" .. str
.. "&serverId=" .. LoginManager.ServerId
.. "&token=111"
.. "&platform=1"
.. "&channel=" .. user_channel
.. "&sub_channel=" .. LoginRoot_SubChannel
.. "&admin=d53b3e8ef74bf72d8aafce3a1c8671a0"
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp=0"
else
url = LoginRoot_Url
.. "jl_loginserver/getUserInfo?openId=" .. LoginManager.openId
.. "&serverId=" .. LoginManager.ServerId
.. "&token=" .. LoginManager.token
.. "&platform=4"
.. "&channel=" .. user_channel
.. "&sub_channel=" .. LoginRoot_SubChannel
.. "&admin=d53b3e8ef74bf72d8aafce3a1c8671a0"
.. "&version=" .. LoginRoot_PackageVersion
.. "&timeStamp=0",
this.OnReceiveLogin, nil, nil, nil
end
end
HttpManager:SendGetHttp(url, this.OnReceiveLogin, nil, nil, nil)
end
--用户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
MsgPanel.ShowOne(data.reason or Language[11719])
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
end
-----------++++++++++++++++++++++++++++++++++++++++ http +++++++++++++++++++++++++++++
-----------++++++++++++++++++++++++++++++++++++++++ socket +++++++++++++++++++++++++++++
-- 请求连接socket
function this.RequestSocketLogin()
Log("请求连接Socket")
RequestPanel.Show(Language[11720])
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
function this.OnDisconnect(network)
RequestPanel.Hide()
PopupTipPanel.ShowTip(Language[11719])
end
-----------++++++++++++++++++++++++++++++++++++++++ socket +++++++++++++++++++++++++++++
function this.SetLoginPart(flag)
this.loginAnim.enabled = flag
this.btnLoginPart:SetActive(flag and tostring(this.bgStr) == "dl_ui_effect_bg")
this.btnLogin:SetActive(flag)
this.serverSelectPart:SetActive(flag)
end
function this.SubmitGameData()
local isNewRole = PlayerPrefs.GetString(tostring(PlayerManager.uid), "")
if isNewRole == "" and PlayerManager.level == 1 then
PlayerPrefs.SetString(tostring(PlayerManager.uid), tostring(PlayerManager.uid))
SubmitExtraData({ type = SDKSubMitType.TYPE_CREATE_ROLE })
end
LogError("开始调用日志上报--------------------------------------------------------11111111111")
SubmitExtraData({ type = SDKSubMitType.TYPE_ENTER_GAME })
end
return LoginPanel