2025-04-01 10:48:36 +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
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local _LocalConfigAllGame = {
|
2025-05-14 15:56:27 +08:00
|
|
|
|
-- 10, 33,
|
|
|
|
|
|
-- 90,
|
2025-04-01 10:48:36 +08:00
|
|
|
|
66, 86, 87, 88, 89
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local FilterGame = function(games)
|
2025-04-09 15:33:02 +08:00
|
|
|
|
pt(games)
|
2025-04-01 10:48:36 +08:00
|
|
|
|
local tempGames = {}
|
|
|
|
|
|
for k, v in pairs(games) do
|
|
|
|
|
|
v.bundle = v.bundle:gsub("\r\n", "")
|
|
|
|
|
|
if IsHasDictionary(v.game_id, _LocalConfigAllGame) then
|
|
|
|
|
|
table.insert(tempGames, v)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
return tempGames
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function __Login(cmd, _data, callBack)
|
|
|
|
|
|
local _client = ControllerManager.WebClient
|
|
|
|
|
|
_client:send(cmd, _data, function(res)
|
|
|
|
|
|
printlog("1111111111111111222222222222")
|
|
|
|
|
|
-- pt(cmd)
|
|
|
|
|
|
-- pt(res)
|
|
|
|
|
|
if (res.ReturnCode == 0) then
|
|
|
|
|
|
local data = res.Data
|
|
|
|
|
|
local account = data["account"]
|
|
|
|
|
|
local user = DataManager.SelfUser
|
|
|
|
|
|
user.acc = account.acc
|
|
|
|
|
|
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"]
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
--GameApplication.Instance.printLog = true
|
|
|
|
|
|
else
|
|
|
|
|
|
--GameApplication.Instance.printLog = user.type == 2
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
_client:setSession(data["session_id"] .. "," .. data["token"])
|
2025-04-11 12:49:08 +08:00
|
|
|
|
-- print("11111111111111111111111111111111")
|
2025-04-01 10:48:36 +08:00
|
|
|
|
pt(data)
|
|
|
|
|
|
ControllerManager.GroupClient = NetClient.new(data.groupWeb, "web_group", ConnectionProtocol.Web)
|
|
|
|
|
|
ControllerManager.GroupClient:setSession((data["session_id"] .. "," .. data["token"]))
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if (callBack ~= nil) then
|
|
|
|
|
|
callBack(res)
|
|
|
|
|
|
end
|
|
|
|
|
|
end)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--手机登录
|
|
|
|
|
|
function M:GetPhoneCode(phone, callback)
|
|
|
|
|
|
--不走登录逻辑
|
|
|
|
|
|
local _client = ControllerManager.WebClient
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
_data["phone"] = phone
|
|
|
|
|
|
_client:send(Protocol.WEB_GET_VERIFCATION_CODE, _data, function(res)
|
|
|
|
|
|
if (callback ~= nil) then
|
|
|
|
|
|
callback(res)
|
|
|
|
|
|
end
|
|
|
|
|
|
end)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M:PhoneLogin(phone, code, callback)
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
_data["phone"] = phone
|
|
|
|
|
|
_data["code"] = code
|
2025-04-09 15:33:02 +08:00
|
|
|
|
__Login(Protocol.WEB_PHONE_LOGIN, _data, callback)
|
2025-04-01 10:48:36 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--手机密码登录
|
|
|
|
|
|
function M:PhonePasswordLogin(phone, password, callback)
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
_data["phone"] = phone
|
|
|
|
|
|
_data["password"] = password
|
|
|
|
|
|
__Login(Protocol.WEB_PHONE_PASSWORD_LOGIN, _data, callback)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M:IdPasswordLogin(uid, password, callback)
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
_data["id"] = tonumber(uid)
|
|
|
|
|
|
_data["password"] = password
|
|
|
|
|
|
__Login(Protocol.WEB_ID_PASSWORD_LOGIN, _data, callback)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M:Login(callback)
|
|
|
|
|
|
local user = DataManager.SelfUser
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
_data["acc"] = user.acc
|
|
|
|
|
|
_data["nick"] = user.nick_name
|
|
|
|
|
|
_data["sex"] = user.sex
|
|
|
|
|
|
_data["portrait"] = user.head_url
|
|
|
|
|
|
__Login(Protocol.WEB_USER_LOGIN, _data, callback)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M:QuickLogin(session_id, callback)
|
|
|
|
|
|
local _data = {}
|
|
|
|
|
|
local _client = ControllerManager.WebClient
|
|
|
|
|
|
_client:setSession(session_id)
|
|
|
|
|
|
-- ControllerManager.GroupClient:setSession(session_id)
|
|
|
|
|
|
__Login(Protocol.WEB_QUICK_LOGIN, _data, callback)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M.OnEnter(self)
|
2025-04-11 12:49:08 +08:00
|
|
|
|
---- print("login controller enter")
|
2025-04-01 10:48:36 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M.OnExit(self)
|
2025-04-11 12:49:08 +08:00
|
|
|
|
---- print("login controller exit")
|
2025-04-01 10:48:36 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--字符串类json格式转化为表
|
|
|
|
|
|
function stringToTAble(data)
|
|
|
|
|
|
local returnTable = {}
|
|
|
|
|
|
for key, value in string.gmatch(data, "(%w+)=([^,]*)") do
|
|
|
|
|
|
value = value:gsub("^%s*(.-)%s*$", "%1") -- 去除前后空格
|
|
|
|
|
|
if value == "" then
|
|
|
|
|
|
returnTable[key] = nil -- 空值转换为 nil
|
|
|
|
|
|
elseif tonumber(value) then
|
|
|
|
|
|
returnTable[key] = tonumber(value) -- 数值转换
|
|
|
|
|
|
elseif value:match("^https?://") then
|
|
|
|
|
|
returnTable[key] = value -- URL 直接保留
|
|
|
|
|
|
else
|
|
|
|
|
|
returnTable[key] = value:gsub("\\u(%x%x%x%x)", function(hex)
|
|
|
|
|
|
return utf8.char(tonumber(hex, 16)) -- 处理 Unicode(\u8dc3 -> 跃)
|
|
|
|
|
|
end)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
return returnTable
|
|
|
|
|
|
end
|