|
-
- local isLoginData = false
- local isUpdateData = false
-
- local function gotoRoom()
- local loginInfo = app.user.loginInfo
- if loginInfo.gameId > 0 and loginInfo.tid > 0 then
-
- if not isLoginData or not isUpdateData then
- app.waitDialogManager:closeWaitNetworkDialog()
- return
- end
-
- app.waitDialogManager:closeWaitNetworkDialog()
-
- -- 进入房间
- local function enterRoom()
- app.hall:requestEnterRoom(loginInfo.gameId, loginInfo.tid, app.protocolType)
- end
-
- -- 尝试进入房间
- local function tryEnterRoom()
- local result, subGameId, missingFiles = app.subGameManager:checkGameFiles(loginInfo.gameId)
- if not result then
- logD("GlobalEvent::gotoRoom() 发现子游戏文件缺失,gameId = "..subGameId)
- for k,v in pairs(missingFiles) do
- logD(v);
- end
- local function onOk()
- app.subGameManager:clearGame(subGameId, function()
- downloadSubGame(subGameId, tryEnterRoom);
- end);
- end
- showConfirmDialog("发现文件缺失,点击确定开始修复", onOk);
- else
- enterRoom();
- end
- end
-
- local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
- local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
- if not isInstall or isNeedUpdate then
- downloadSubGame(loginInfo.gameId, tryEnterRoom)
- return
- end
- tryEnterRoom()
- end
-
- end
-
- -- 侦听全局的socket重连成功消息
- function netConnectSucceed()
- -- 清空之前通过Protocol:sendResponse所有的消息注册函数
- local function clearAllRegMsg()
- for i, v in pairs(g_regMsgCallBackFuncs) do
- v()
- end
- print("连接成功,清空所有之前通过Protocol:sendResponse注册的网络回调函数, 回到函数个数:" .. table.nums(g_regMsgCallBackFuncs))
- g_regMsgCallBackFuncs = { }
- end
-
- app:addEventListener("socketConnectSucceed", clearAllRegMsg)
- end
-
- -- 绑定角色登陆成功的全局事件
- local function actorLoginSucceed()
-
- -- 角色登陆成功后拉取消息全部返回完毕后拉取战斗
- local function onLoginSuccessed()
-
- local LoginConfig = require("luaScript.Views.Login.LoginConfig")
- if LoginConfig.EapSDK and (not isWin32Platform()) and G_EapSdkMgr then
- local userInfo = json.decode(app.user.userInfo);
- G_EapSdkMgr:login(tostring(app.user.loginInfo.uid), userInfo.nickname, userInfo.headimgurl, app.user.phonenum or "", app.user.sex)
- end
-
- app.waitDialogManager:closeTransparencyMask();
-
- local loginInfo = app.user.loginInfo
- print("GlobalEvent onLoginSuccessed :"..table.tostring(loginInfo))
-
- local currentView = app:getCurrentView();
-
- -- 参数不正确的情况下直接进入到大厅界面,省事
- if not loginInfo or not currentView then
- --app:gotoView(import("luaScript.Views.Main.MainView"):new());
- gotoMainView()
- app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
- return
- end
-
- --在比赛中
- if loginInfo and loginInfo.matchFlag == 1 then
- local function gotoMatch()
- local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents")
- local ProtocolMatchMessage = require("luaScript.Protocol.Match.ProtocolMatchMessage")
- local request=ProtocolMatchMessage.MatchEnter:new()
- request.uid = loginInfo.uid
- request.userInfo = app.user.userInfo
- dump(request)
- app.waitDialogManager:showWaitNetworkDialog("获取比赛信息...");
- app.mainScene:sendMsg(app.match, MatchEvents.ENTER_MATCH, request, function(status, response)
- -- print(table.tostring(response))
- end)
- end
-
- local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
- local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
- if not isInstall or isNeedUpdate then
- downloadSubGame(loginInfo.gameId, gotoMatch)
- return
- end
- gotoMatch()
- return
- end
-
- -- 看玩家数据是不是在房间中
- if loginInfo.gameId > 0 and loginInfo.tid > 0 then
- -- 如果没有配置信息,只能进大厅
- local gameConfig = getSubGameConfig(loginInfo.gameId)
- if not gameConfig then
- --app:gotoView(import("luaScript.Views.Main.MainView"):new());
- gotoMainView()
- app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
- return
- end
-
- if loginInfo.serverLevel >= COIN_LEVEL.INIT and loginInfo.serverLevel <= COIN_LEVEL.HIGH + 10 then --金币场区间为10~40
- app.protocolType = PROTOCOL_TYPE.COIN
- end
-
- isLoginData=true
- app.waitDialogManager:showWaitNetworkDialog()
- gotoRoom()
- -- -- 请求进入房间
- -- local function enterRoom()
- -- app.hall:requestEnterRoom(loginInfo.gameId, loginInfo.tid)
- -- end
-
- -- local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
- -- local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
- -- if not isInstall or isNeedUpdate then
- -- downloadSubGame(loginInfo.gameId, enterRoom)
- -- return;
- -- end
-
- -- enterRoom()
- else
- -- 若果正在显示总结算,则不理
- if isShowCountAll() then
- return
- end
-
- -- 如果玩家不在房间中,分两种情况
- -- 一种是现在的界面就是在大厅中。则什么都不用做,保持当前状态
- -- 另一种是现在的界面不在大厅中,则需要重新进入大厅界面
- if "MainView" ~= currentView.__cname then
- --app:gotoView(import("luaScript.Views.Main.MainView"):new());
- gotoMainView()
- end
- app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
- end
- end
-
- app.user:addEventListener("onLoginSuccessed", onLoginSuccessed)
- end
-
- local function actorLoginFailed()
- local function OnActorLoginFailed(event)
- local errCode = event.errCode
- if errCode then
- -- 1: 电话号码未绑定微信 2: 密码错误
- local errString =
- {
- [1] = "您的账号还没有绑定,请先使用【微信登陆】并在玩家信息中绑定【手机】账号",
- [2] = "密码错误",
- [3] = "账号已经禁止使用",
- [4] = "验证码错误",
- [7] = "该手机号已绑定过其他游戏账号",
- [8] = "该手机号还未注册",
- [9] = "没有此用户",
- }
- local message = errString[errCode] or "手机号登录失败 "..tostring(errCode);
- if tonumber(errCode) == 1 then
- showConfirmDialog(message,nil,nil,25);
- else
- showConfirmDialog(message);
- end
- end
- end
- app.user:addEventListener("onPhoneLoginErrResponse", OnActorLoginFailed)
- end
-
- function registerEnterRoomEvent()
- local function onEnterRoomSuccess(event)
- --EAPSDK 进入房间自动隐藏
- if G_LayerMain then
- G_LayerMain:setVisible(false);
- end
- local gameId = event.gameId or 0;
- local gameType = event.gameType or 0;
- --目前只有金币场用到,用于区分是进入房间成功还是断线重连(金币场的gameStatus无法使用)
- local param = event.param;
- runInNextFrame(function()
- local roomViewName = getSubGameRoomView(gameId, gameType, app.protocolType)
- logD("onEnterRoomSuccess() roomViewName = " .. roomViewName)
-
- if roomViewName then
-
- local arr = string.split(roomViewName, ".")
- local len = table.nums(arr)
-
- local currentView = app:getCurrentView();
- if currentView then
- logD("onEnterRoomSuccess() currentName = " .. currentView.__cname)
- else
- logD("onEnterRoomSuccess() currentView is nil")
- end
-
- if currentView and currentView.__cname == arr[len] then
- -- 当前正是在我想去的房间里面
- logD("onEnterRoomSuccess() do nothing")
- else
- logD("onEnterRoomSuccess() goto view " .. roomViewName)
- app:gotoView(import(roomViewName):new(param));
- end
- end
- end)
- end
-
- app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
- end
-
- function registerKickoutEvent()
- local function onServerKickout()
- local function onClickOk()
- app.plugin:logout();
- end
- app.net.isNeedReconnect = false
- app.net:close();
- showConfirmDialog("数据异常,请重新登录", onClickOk)--"您的账号在其他地方登陆,您被强制下线"
- end
- app.user:addEventListener("onServerKickOutResponse", onServerKickout)
- end
-
- --子游戏更新获取完成事件
- function registerSubGameListEvent()
- local function getSubGameListSuccessed()
- if not isUpdateData then
- isUpdateData=true
- gotoRoom()
- end
- end
- app.serverConfigs:addEventListener("getSubGameListSuccessed", getSubGameListSuccessed)
- end
-
- --绑定手机结果/绑定微信/二次授权
- function registerBindAppEvent()
- local function onBindResponse(event)
- if not event or not event.response then
- return
- end
- local ret = tonumber(event.response.ret);
- if ret == 7 then
- uploadLogs("WEIXIN_TWICE_BIND")
- end
-
- local tips =
- {
- [0] = "绑定成功",
- [1] = "验证码错误",
- [2] = "已绑定过手机号,无需再次绑定",
- [5] = "该手机号已经被其他游戏ID绑定,请更换手机号再次绑定",
- [6] = "绑定成功",
- [7] = "该微信号已绑定过其他游戏账号",
- [8] = "绑定成功",
- [9] = "设置成功",
- }
- local msg = tips[ret] or "未知错误:"..tostring(ret)
- showConfirmDialog(msg, function() end)
- end
- app.user:addEventListener("onBindResponse", onBindResponse)
- end
-
- --修改手机号/修改密码
- function registerChangeAppEvent()
- local function onChangePlayerInfo(event)
- if not event or not event.response then
- return
- end
- local ret = tonumber(event.response.ret);
- local tips =
- {
- [0] = "修改成功",
- [1] = "您的账号还没有绑定,请先使用【微信登陆】并在玩家信息中绑定【手机】账号",
- [2] = "密码错误",
- [3] = "账号已经禁止使用",
- [4] = "验证码错误",
- [7] = "该手机号已绑定过其他游戏账号",
- [8] = "该手机号还未注册",
- }
- local msg = tips[ret] or "未知错误:"..tostring(ret)
- showConfirmDialog(msg, function() end)
- end
- app.user:addEventListener("onChangePlayerInfo", onChangePlayerInfo)
- end
-
- -- 开始侦听所有全局事件
- function startGlobalEvent()
- if isReviewWithMiniGame() then
- return
- end
-
- netConnectSucceed()
- actorLoginSucceed()
- actorLoginFailed()
- registerEnterRoomEvent()
- registerKickoutEvent()
- registerSubGameListEvent()
- registerBindAppEvent()
- registerChangeAppEvent()
- end
|