changhong_newclient/lua_probject/base_project/Game/Controller/LoginController.lua

213 lines
6.8 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
LoginController = {}
local M = {}
--- Create a new LoginController
function LoginController.new()
setmetatable(M, { __index = IController })
local self = setmetatable({}, { __index = M })
self.baseType = LoginController
self.class = "Login"
return self
2025-05-24 14:29:14 +08:00
end
local _LocalConfigAllGame = {
10, 13, 14, 15, 16, 17, 22, 33, 65, 66, 67, 77, 88,
101, 102, 103, 104, 105, 106, 107,
108,
301, 201, 202, 203
2025-05-24 14:29:14 +08:00
}
local FilterGame = function(games)
local tempGames = {}
for k, v in pairs(games) do
if IsHasDictionary(v.game_id, _LocalConfigAllGame) then
table.insert(tempGames, v)
end
end
return tempGames
2025-05-24 14:29:14 +08:00
end
local function __Login(cmd, _data, callBack)
2025-08-30 20:29:56 +08:00
if not UnityEngine.SystemInfo.deviceUniqueIdentifier or #UnityEngine.SystemInfo.deviceUniqueIdentifier < 6 then
ViewUtil.CloseModalWait()
ViewUtil.ErrorMsg(nil, "", "找不到您的设备信息,若无法登录请联系客服人员解决")
return
end
2025-05-24 14:29:14 +08:00
local _client = ControllerManager.WebClient
_client:send(cmd, _data, function(res)
2025-05-24 14:29:14 +08:00
if (res.ReturnCode == 0) then
local data = res.Data
local account = data["account"]
local user = DataManager.SelfUser
user.acc = account.acc
2025-05-24 14:29:14 +08:00
user.account_id = account["id"]
user.diamo = account["diamo"]
user.nick_name = account["nick"]
user.sex = account["sex"]
user.head_url = account["portrait"]
user.room_id = account["roomid"]
user.group_id = account["groupId"]
user.type = account["type"]
user.agent = account["mng"]
2025-08-30 20:29:56 +08:00
user.bind_pwd = data["havePassword"]
2025-10-01 20:18:09 +08:00
user.retri_pwd = data["havegroup"]
user.isBangding = tonumber(data.isBangding)
user.real_info = account.real_info
user.phone = account.phone
user.address = account.address
user.games = FilterGame(data.games)
if Application.platform == RuntimePlatform.WindowsPlayer or Application.platform == RuntimePlatform.WindowsEditor then
2025-05-24 14:29:14 +08:00
--GameApplication.Instance.printLog = true
else
--GameApplication.Instance.printLog = user.type == 2
end
_client:setSession(data["session_id"] .. "," .. data["token"])
2025-06-29 22:06:20 +08:00
2025-05-24 14:29:14 +08:00
ControllerManager.GroupClient = NetClient.new(data.groupWeb, "web_group", ConnectionProtocol.Web)
ControllerManager.GroupClient:setSession((data["session_id"] .. "," .. data["token"]))
2025-05-24 14:29:14 +08:00
end
if (callBack ~= nil) then
2025-05-24 14:29:14 +08:00
callBack(res)
end
end)
end
local function __getCode(cmd, _data, callBack)
2025-08-25 19:23:57 +08:00
local _client = ControllerManager.WebClient
_client:send(Protocol.WEB_GET_CODE, { id = _data.id }, function(res)
if (res.ReturnCode == 0) then
_data["uuidCode"] = res.Data.code
__Login(cmd, _data, callBack)
2025-08-25 19:23:57 +08:00
end
end)
end
2025-09-12 23:04:24 +08:00
function __getCode_test(cmd, _data, callBack)
local _client = ControllerManager.WebClient
_client:send(Protocol.WEB_GET_CODE, { id = _data.id }, function(res)
if (res.ReturnCode == 0) then
_data["uuidCode"] = res.Data.code
__Login(cmd, _data, callBack)
end
end)
end
--得到app信息
2025-09-13 16:58:49 +08:00
function M:GetAppInfo()
2025-09-12 23:04:24 +08:00
local _client = ControllerManager.WebClient
2025-10-01 20:18:09 +08:00
_client:send(Protocol.WEB_GET_APP_INFO, { id = 1 }, function(res)
2025-09-12 23:04:24 +08:00
if (res.ReturnCode == 0) then
GameApplication.Instance:SetAppInfo(res.Data.appInfo)
end
2025-09-13 16:58:49 +08:00
return
2025-09-12 23:04:24 +08:00
end)
end
2025-05-24 14:29:14 +08:00
--手机登录
function M:PhoneLogin(phone, code, callback)
2025-05-24 14:29:14 +08:00
local _data = {}
_data["phone"] = phone
_data["code"] = code
__Login(Protocol.WEB_PHONE_LOGIN, _data, callback)
2025-05-24 14:29:14 +08:00
end
--手机密码登录
function M:PhonePasswordLogin(phone, password, callback)
2025-05-24 14:29:14 +08:00
local _data = {}
_data["phone"] = phone
_data["password"] = password
__Login(Protocol.WEB_PHONE_PASSWORD_LOGIN, _data, callback)
2025-05-24 14:29:14 +08:00
end
2025-08-30 20:29:56 +08:00
function M:IdPasswordLogin(uid, password, callback)
local _data = {}
2025-08-30 20:29:56 +08:00
local result, resultInfo = pcall(function(...)
_data.data = RSAHelper.Encrypt(json.encode({
id = tonumber(uid),
password = password,
deviceCode = UnityEngine.SystemInfo.deviceUniqueIdentifier
}))
end)
if result then
__getCode(Protocol.WEB_ID_PASSWORD_LOGIN_2, _data, callback)
else
ViewUtil.CloseModalWait()
ViewUtil.ErrorMsg(nil, "", "您的个人信息太长,若无法登录请联系客服人员解决")
end
end
2025-08-30 20:29:56 +08:00
function M:IdPasswordLogin2(uid, password, callback)
2025-05-24 14:29:14 +08:00
local _data = {}
_data["id"] = tonumber(uid)
_data["password"] = password
2025-08-25 19:23:57 +08:00
_data["deviceCode"] = UnityEngine.SystemInfo.deviceUniqueIdentifier
__getCode(Protocol.WEB_ID_PASSWORD_LOGIN, _data, callback)
2025-05-24 14:29:14 +08:00
end
function M:Login2(callback)
2025-05-24 14:29:14 +08:00
local user = DataManager.SelfUser
local _data = {}
_data["acc"] = user.acc
_data["nick"] = user.nick_name
_data["sex"] = user.sex
_data["portrait"] = user.head_url
2025-08-27 16:23:30 +08:00
_data["deviceCode"] = UnityEngine.SystemInfo.deviceUniqueIdentifier
__Login(Protocol.WEB_USER_LOGIN, _data, callback)
2025-05-24 14:29:14 +08:00
end
function M:Login(callback)
local user = DataManager.SelfUser
local _data = {}
2025-10-01 20:18:09 +08:00
printlog("lingmeng Login", UnityEngine.SystemInfo.deviceUniqueIdentifier)
2025-08-30 20:29:56 +08:00
local result = pcall(function(...)
_data.data = RSAHelper.Encrypt(json.encode({
2025-10-01 22:25:45 +08:00
-- acc = user.acc,
acc = "kjsaf65agf4d65g4sdf3216SD5D465SA",
2025-08-30 20:29:56 +08:00
nick = user.nick_name,
sex = user.sex,
2025-09-26 16:06:55 +08:00
portrait = user.head_url,
2025-08-30 20:29:56 +08:00
deviceCode = UnityEngine.SystemInfo.deviceUniqueIdentifier
}))
end)
if result then
__Login(Protocol.WEB_USER_LOGIN_2, _data, callback)
else
ViewUtil.CloseModalWait()
ViewUtil.ErrorMsg(nil, "", "您的个人信息太长,若无法登录请联系客服人员解决")
end
end
2025-08-30 20:29:56 +08:00
function M:QuickLogin(session_id, callback)
local _data = {}
_data.data = RSAHelper.Encrypt(json.encode({
2025-08-30 21:23:22 +08:00
quick = 1,
deviceCode = UnityEngine.SystemInfo.deviceUniqueIdentifier
}))
local _client = ControllerManager.WebClient
_client:setSession(session_id)
__Login(Protocol.WEB_QUICK_LOGIN_2, _data, callback)
end
2025-08-30 20:29:56 +08:00
--快速登入加密
function M:QuickLogin2(session_id, callback)
2025-05-24 14:29:14 +08:00
local _data = {}
2025-08-29 20:15:02 +08:00
_data["deviceCode"] = UnityEngine.SystemInfo.deviceUniqueIdentifier
2025-05-24 14:29:14 +08:00
local _client = ControllerManager.WebClient
_client:setSession(session_id)
-- ControllerManager.GroupClient:setSession(session_id)
__Login(Protocol.WEB_QUICK_LOGIN, _data, callback)
2025-05-24 14:29:14 +08:00
end
function M.OnEnter(self)
--print("login controller enter")
2025-05-24 14:29:14 +08:00
end
function M.OnExit(self)
--print("login controller exit")
2025-05-24 14:29:14 +08:00
end