2023-07-14 19:35:33 +00:00
|
|
|
|
XUserManager = XUserManager or {}
|
|
|
|
|
|
|
|
|
|
local Application = CS.UnityEngine.Application
|
|
|
|
|
local Platform = Application.platform
|
|
|
|
|
local RuntimePlatform = CS.UnityEngine.RuntimePlatform
|
|
|
|
|
|
|
|
|
|
XUserManager.CHANNEL = {
|
|
|
|
|
HARU = 1,
|
|
|
|
|
HERO = 2,
|
|
|
|
|
Android = 3,
|
|
|
|
|
IOS = 4,
|
2024-09-01 20:49:41 +00:00
|
|
|
|
KURO_SDK = 15,
|
2023-07-14 19:35:33 +00:00
|
|
|
|
KuroPC = 15
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XUserManager.PLATFORM = {
|
|
|
|
|
Win = 0,
|
|
|
|
|
Android = 1,
|
|
|
|
|
IOS = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XUserManager.UserId = nil
|
|
|
|
|
XUserManager.UserName = nil
|
|
|
|
|
XUserManager.Token = nil
|
|
|
|
|
XUserManager.ReconnectedToken = nil
|
|
|
|
|
XUserManager.Channel = nil
|
|
|
|
|
XUserManager.Platform = nil
|
2024-09-01 20:49:41 +00:00
|
|
|
|
-- 登录渠道,PC端用
|
|
|
|
|
XUserManager.LoginChannel = nil
|
2023-07-14 19:35:33 +00:00
|
|
|
|
|
|
|
|
|
local UserType = XHgSdkManager.UserType
|
|
|
|
|
|
|
|
|
|
local InitPlatform = function()
|
|
|
|
|
if Platform == RuntimePlatform.Android then
|
|
|
|
|
XUserManager.Platform = XUserManager.PLATFORM.Android
|
|
|
|
|
XHgSdkManager.SetCallBackUrl(CS.XRemoteConfig.AndroidPayCallbackUrl)
|
|
|
|
|
elseif Platform == RuntimePlatform.IPhonePlayer then
|
|
|
|
|
XUserManager.Platform = XUserManager.PLATFORM.IOS
|
|
|
|
|
XHgSdkManager.SetCallBackUrl(CS.XRemoteConfig.IosPayCallbackUrl)
|
|
|
|
|
else
|
|
|
|
|
XUserManager.Platform = XUserManager.PLATFORM.Win
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XHgSdkManager.SetCallBackUrl(CS.XRemoteConfig.PcPayCallbackUrl)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.IsUseSdk()
|
|
|
|
|
return XUserManager.Channel == XUserManager.CHANNEL.HERO or XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.IsKuroSdk()
|
|
|
|
|
return XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XUserManager.IsHeroSdk()
|
|
|
|
|
return XUserManager.Channel == XUserManager.CHANNEL.HERO
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
function XUserManager.Init()
|
|
|
|
|
XUserManager.Channel = CS.XHgSdkAgent.LoginType or XUserManager.CHANNEL.HARU
|
|
|
|
|
XUserManager.UserId = XLoginManager.GetUserId()
|
|
|
|
|
XUserManager.UserType = XLoginManager.GetUserType() or UserType.Vistor
|
|
|
|
|
XUserManager.PasswordStatus = tonumber(XLoginManager.GetPasswordStatus() or "0") or 0
|
|
|
|
|
if XUserManager.Channel ~= XUserManager.CHANNEL.Android and XUserManager.Channel ~= XUserManager.CHANNEL.IOS then
|
|
|
|
|
XUserManager.Token = XLoginManager.GetToken()
|
|
|
|
|
XUserManager.SetPasswordStatus(0)
|
|
|
|
|
end
|
|
|
|
|
InitPlatform()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.IsNeedLogin()
|
|
|
|
|
if (XUserManager.Channel == XUserManager.CHANNEL.Android) or (XUserManager.Channel == XUserManager.CHANNEL.IOS) or
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK or XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
2023-07-14 19:35:33 +00:00
|
|
|
|
return XHgSdkManager.IsNeedLogin()
|
|
|
|
|
else
|
|
|
|
|
return XHaruUserManager.IsNeedLogin()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.HasLoginError()
|
|
|
|
|
if XUserManager.IsUseSdk() then
|
|
|
|
|
return XHeroSdkManager.HasLoginError()
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.ShowLogin()
|
|
|
|
|
if XUserManager.Channel == XUserManager.CHANNEL.Android or XUserManager.Channel == XUserManager.CHANNEL.IOS or
|
|
|
|
|
XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
|
|
|
|
XHgSdkManager.Login(XHgSdkManager.UserType.Quickly) -- 默认快速登录逻辑
|
|
|
|
|
else
|
|
|
|
|
XHaruUserManager.Login()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.ShowLogout()
|
|
|
|
|
if XUserManager.Channel == XUserManager.CHANNEL.Android or XUserManager.Channel == XUserManager.CHANNEL.IOS then
|
|
|
|
|
XHgSdkManager.BackToLogin()
|
|
|
|
|
elseif XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
|
|
|
|
-- #105485 PC端使用的登出逻辑和移动端保持一致,都使用切换账号逻辑来登出
|
|
|
|
|
XHgSdkManager.BackToLogin()
|
|
|
|
|
else
|
|
|
|
|
XHaruUserManager.Logout()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.Logout(cb)
|
|
|
|
|
if XUserManager.Channel == XUserManager.CHANNEL.Android or XUserManager.Channel == XUserManager.CHANNEL.IOS or
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK or XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
2023-07-14 19:35:33 +00:00
|
|
|
|
XHgSdkManager.Logout(cb)
|
|
|
|
|
else
|
|
|
|
|
XHaruUserManager.Logout(cb)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.ClearLoginData()
|
|
|
|
|
if XUserManager.Channel == XUserManager.CHANNEL.Android or XUserManager.Channel == XUserManager.CHANNEL.IOS or
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK or XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
2023-07-14 19:35:33 +00:00
|
|
|
|
XHgSdkManager.Logout()
|
|
|
|
|
else
|
|
|
|
|
XUserManager.SignOut()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SetUserId(userId)
|
|
|
|
|
XLog.Debug("userId:" .. tostring(userId))
|
|
|
|
|
XUserManager.UserId = userId
|
|
|
|
|
CS.XHeroBdcAgent.UserId = "HeroEn#" .. (userId or "")
|
|
|
|
|
XLoginManager.SetUserId(userId)
|
|
|
|
|
CsXGameEventManager.Instance:Notify(XEventId.EVENT_USERID_CHANGE, userId)
|
|
|
|
|
XEventManager.DispatchEvent(XEventId.EVENT_USERID_CHANGE, userId)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.CleanUserId()
|
|
|
|
|
XUserManager.UserId = nil
|
|
|
|
|
XLoginManager.CleanUserId()
|
|
|
|
|
XEventManager.DispatchEvent(XEventId.EVENT_USERID_CHANGE, nil)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SetUserType(userType)
|
|
|
|
|
XUserManager.UserType = userType
|
|
|
|
|
XLoginManager.SetUserType(userType)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.CleanUserType()
|
|
|
|
|
XUserManager.UserType = nil
|
|
|
|
|
XLoginManager.CleanUserType()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SetPasswordStatus(status)
|
|
|
|
|
XUserManager.PasswordStatus = status
|
|
|
|
|
XLoginManager.SetPasswordStatus(status)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SetUserName(userName)
|
|
|
|
|
XUserManager.UserName = userName
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if not XUserManager.IsUseSdk() then
|
|
|
|
|
CS.UnityEngine.PlayerPrefs.SetString(XPrefs.UserName, XUserManager.UserName)
|
|
|
|
|
CS.UnityEngine.PlayerPrefs.Save()
|
|
|
|
|
end
|
|
|
|
|
CsXGameEventManager.Instance:Notify(XEventId.EVENT_USERNAME_CHANGE, userName)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SetToken(token)
|
|
|
|
|
XUserManager.Token = token
|
|
|
|
|
if XUserManager.Channel ~= XUserManager.CHANNEL.Android and XUserManager.Channel ~= XUserManager.CHANNEL.IOS or
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XUserManager.Channel == XUserManager.CHANNEL.KURO_SDK or XUserManager.Channel == XUserManager.CHANNEL.KuroPC then
|
2023-07-14 19:35:33 +00:00
|
|
|
|
XLoginManager.SetToken(token)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XUserManager.SetLoginChannel(channel)
|
|
|
|
|
XUserManager.LoginChannel = channel
|
|
|
|
|
if XUserManager.LoginChannel then
|
|
|
|
|
CS.XLog.Debug(string.format("XUserManager.SetLoginChannel: type: %s , value: %s", type(XUserManager.LoginChannel), tostring(XUserManager.LoginChannel)))
|
|
|
|
|
--pc版的要在获取到登录渠道后才设置选择服务器
|
|
|
|
|
XServerManager.SelectChannelServer()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
function XUserManager.CleanToken()
|
|
|
|
|
XUserManager.Token = nil
|
|
|
|
|
XLoginManager.CleanToken()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local DoRunLogin = function()
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XEventManager.DispatchEvent(XEventId.EVENT_LOGIN_UI_OPEN)
|
|
|
|
|
XFightUtil.ClearFight()
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if XDataCenter.MovieManager then
|
|
|
|
|
XDataCenter.MovieManager.StopMovie()
|
|
|
|
|
end
|
|
|
|
|
CS.Movie.XMovieManager.Instance:Clear()
|
|
|
|
|
CsXUiManager.Instance:Clear()
|
|
|
|
|
XHomeSceneManager.LeaveScene()
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
|
|
|
|
XDataCenter.Init()
|
|
|
|
|
XMVCA:Init()
|
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
XLuaUiManager.Open("UiLogin")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.SignOut()
|
|
|
|
|
XLoginManager.Disconnect()
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
if XUserManager.Channel ~= XUserManager.CHANNEL.Android and XUserManager.Channel ~= XUserManager.CHANNEL.IOS and
|
2023-07-14 19:35:33 +00:00
|
|
|
|
XUserManager.Channel ~= XUserManager.CHANNEL.KuroPC then
|
|
|
|
|
XUserManager.SetUserId(nil)
|
|
|
|
|
XUserManager.SetUserName(nil)
|
|
|
|
|
XUserManager.SetToken(nil)
|
|
|
|
|
XUserManager.SetPasswordStatus(0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
XEventManager.DispatchEvent(XEventId.EVENT_USER_LOGOUT)
|
|
|
|
|
CsXGameEventManager.Instance:Notify(XEventId.EVENT_USER_LOGOUT)
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
DoRunLogin()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XUserManager.OnSwitchAccountSuccess(uid, token, userType)
|
|
|
|
|
XLoginManager.Disconnect()
|
|
|
|
|
|
|
|
|
|
XUserManager.SetUserId(uid)
|
|
|
|
|
XUserManager.SetUserType(userType)
|
|
|
|
|
XUserManager.SetToken(token)
|
|
|
|
|
|
|
|
|
|
XEventManager.DispatchEvent(XEventId.EVENT_USER_LOGOUT)
|
|
|
|
|
CsXGameEventManager.Instance:Notify(XEventId.EVENT_USER_LOGOUT)
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
DoRunLogin()
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XUserManager.GetLoginType()
|
|
|
|
|
return XUserManager.LoginType[XUserManager.Channel]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 对应服务端Server文件Define.cs中Channel规则
|
2023-07-14 19:35:33 +00:00
|
|
|
|
function XUserManager.GetUniqueUserId()
|
|
|
|
|
local prefix = ""
|
|
|
|
|
if XUserManager.Channel == XUserManager.CHANNEL.HARU then --dev(母包和win包)、
|
|
|
|
|
prefix = "dev"
|
|
|
|
|
elseif XUserManager.Channel == XUserManager.CHANNEL.HERO then
|
|
|
|
|
local channelId = CS.XHeroSdkAgent.GetChannelId()
|
|
|
|
|
if channelId == 18 or channelId == 56 then --Hero(国服官服渠道18、56)
|
|
|
|
|
prefix = "Hero"
|
|
|
|
|
else --国内其他安卓渠道使用英雄提供的渠道Id
|
|
|
|
|
prefix = tostring(channelId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return string.format("%s#%s", prefix, XUserManager.UserId)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
XRpc.LoginResponse = function(response)
|
|
|
|
|
if response.Token then
|
|
|
|
|
XUserManager.ReconnectedToken = response.Token
|
|
|
|
|
--BDC
|
|
|
|
|
CS.XHeroBdcAgent.UserId = "HeroEn#" .. XUserManager.UserId
|
|
|
|
|
if XUserManager.Channel ~= XUserManager.CHANNEL.Android and XUserManager.Channel ~= XUserManager.CHANNEL.IOS then
|
|
|
|
|
XLoginManager.SetUserId(XUserManager.UserId)
|
|
|
|
|
XLoginManager.SetToken(XUserManager.Token)
|
|
|
|
|
XLoginManager.SetUserType(XUserManager.UserType)
|
|
|
|
|
XLoginManager.SetPasswordStatus(XUserManager.PasswordStatus)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|