您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

322 行
10 KiB

  1. local isLoginData = false
  2. local isUpdateData = false
  3. local function gotoRoom()
  4. local loginInfo = app.user.loginInfo
  5. if loginInfo.gameId > 0 and loginInfo.tid > 0 then
  6. if not isLoginData or not isUpdateData then
  7. app.waitDialogManager:closeWaitNetworkDialog()
  8. return
  9. end
  10. app.waitDialogManager:closeWaitNetworkDialog()
  11. -- 进入房间
  12. local function enterRoom()
  13. app.hall:requestEnterRoom(loginInfo.gameId, loginInfo.tid, app.protocolType)
  14. end
  15. -- 尝试进入房间
  16. local function tryEnterRoom()
  17. local result, subGameId, missingFiles = app.subGameManager:checkGameFiles(loginInfo.gameId)
  18. if not result then
  19. logD("GlobalEvent::gotoRoom() 发现子游戏文件缺失,gameId = "..subGameId)
  20. for k,v in pairs(missingFiles) do
  21. logD(v);
  22. end
  23. local function onOk()
  24. app.subGameManager:clearGame(subGameId, function()
  25. downloadSubGame(subGameId, tryEnterRoom);
  26. end);
  27. end
  28. showConfirmDialog("发现文件缺失,点击确定开始修复", onOk);
  29. else
  30. enterRoom();
  31. end
  32. end
  33. local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
  34. local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
  35. if not isInstall or isNeedUpdate then
  36. downloadSubGame(loginInfo.gameId, tryEnterRoom)
  37. return
  38. end
  39. tryEnterRoom()
  40. end
  41. end
  42. -- 侦听全局的socket重连成功消息
  43. function netConnectSucceed()
  44. -- 清空之前通过Protocol:sendResponse所有的消息注册函数
  45. local function clearAllRegMsg()
  46. for i, v in pairs(g_regMsgCallBackFuncs) do
  47. v()
  48. end
  49. print("连接成功,清空所有之前通过Protocol:sendResponse注册的网络回调函数, 回到函数个数:" .. table.nums(g_regMsgCallBackFuncs))
  50. g_regMsgCallBackFuncs = { }
  51. end
  52. app:addEventListener("socketConnectSucceed", clearAllRegMsg)
  53. end
  54. -- 绑定角色登陆成功的全局事件
  55. local function actorLoginSucceed()
  56. -- 角色登陆成功后拉取消息全部返回完毕后拉取战斗
  57. local function onLoginSuccessed()
  58. local LoginConfig = require("luaScript.Views.Login.LoginConfig")
  59. if LoginConfig.EapSDK and (not isWin32Platform()) and G_EapSdkMgr then
  60. local userInfo = json.decode(app.user.userInfo);
  61. G_EapSdkMgr:login(tostring(app.user.loginInfo.uid), userInfo.nickname, userInfo.headimgurl, app.user.phonenum or "", app.user.sex)
  62. end
  63. app.waitDialogManager:closeTransparencyMask();
  64. local loginInfo = app.user.loginInfo
  65. print("GlobalEvent onLoginSuccessed :"..table.tostring(loginInfo))
  66. local currentView = app:getCurrentView();
  67. -- 参数不正确的情况下直接进入到大厅界面,省事
  68. if not loginInfo or not currentView then
  69. --app:gotoView(import("luaScript.Views.Main.MainView"):new());
  70. gotoMainView()
  71. app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
  72. return
  73. end
  74. --在比赛中
  75. if loginInfo and loginInfo.matchFlag == 1 then
  76. local function gotoMatch()
  77. local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents")
  78. local ProtocolMatchMessage = require("luaScript.Protocol.Match.ProtocolMatchMessage")
  79. local request=ProtocolMatchMessage.MatchEnter:new()
  80. request.uid = loginInfo.uid
  81. request.userInfo = app.user.userInfo
  82. dump(request)
  83. app.waitDialogManager:showWaitNetworkDialog("获取比赛信息...");
  84. app.mainScene:sendMsg(app.match, MatchEvents.ENTER_MATCH, request, function(status, response)
  85. -- print(table.tostring(response))
  86. end)
  87. end
  88. local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
  89. local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
  90. if not isInstall or isNeedUpdate then
  91. downloadSubGame(loginInfo.gameId, gotoMatch)
  92. return
  93. end
  94. gotoMatch()
  95. return
  96. end
  97. -- 看玩家数据是不是在房间中
  98. if loginInfo.gameId > 0 and loginInfo.tid > 0 then
  99. -- 如果没有配置信息,只能进大厅
  100. local gameConfig = getSubGameConfig(loginInfo.gameId)
  101. if not gameConfig then
  102. --app:gotoView(import("luaScript.Views.Main.MainView"):new());
  103. gotoMainView()
  104. app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
  105. return
  106. end
  107. if loginInfo.serverLevel >= COIN_LEVEL.INIT and loginInfo.serverLevel <= COIN_LEVEL.HIGH + 10 then --金币场区间为10~40
  108. app.protocolType = PROTOCOL_TYPE.COIN
  109. end
  110. isLoginData=true
  111. app.waitDialogManager:showWaitNetworkDialog()
  112. gotoRoom()
  113. -- -- 请求进入房间
  114. -- local function enterRoom()
  115. -- app.hall:requestEnterRoom(loginInfo.gameId, loginInfo.tid)
  116. -- end
  117. -- local isInstall = app.subGameManager:isInstaller(loginInfo.gameId)
  118. -- local isNeedUpdate = app.subGameManager:isNeedUpdate(loginInfo.gameId)
  119. -- if not isInstall or isNeedUpdate then
  120. -- downloadSubGame(loginInfo.gameId, enterRoom)
  121. -- return;
  122. -- end
  123. -- enterRoom()
  124. else
  125. -- 若果正在显示总结算,则不理
  126. if isShowCountAll() then
  127. return
  128. end
  129. -- 如果玩家不在房间中,分两种情况
  130. -- 一种是现在的界面就是在大厅中。则什么都不用做,保持当前状态
  131. -- 另一种是现在的界面不在大厅中,则需要重新进入大厅界面
  132. if "MainView" ~= currentView.__cname then
  133. --app:gotoView(import("luaScript.Views.Main.MainView"):new());
  134. gotoMainView()
  135. end
  136. app.user:dispatchEvent({name = "onMainViewLoginSuccessed"})
  137. end
  138. end
  139. app.user:addEventListener("onLoginSuccessed", onLoginSuccessed)
  140. end
  141. local function actorLoginFailed()
  142. local function OnActorLoginFailed(event)
  143. local errCode = event.errCode
  144. if errCode then
  145. -- 1: 电话号码未绑定微信 2: 密码错误
  146. local errString =
  147. {
  148. [1] = "您的账号还没有绑定,请先使用【微信登陆】并在玩家信息中绑定【手机】账号",
  149. [2] = "密码错误",
  150. [3] = "账号已经禁止使用",
  151. [4] = "验证码错误",
  152. [7] = "该手机号已绑定过其他游戏账号",
  153. [8] = "该手机号还未注册",
  154. [9] = "没有此用户",
  155. }
  156. local message = errString[errCode] or "手机号登录失败 "..tostring(errCode);
  157. if tonumber(errCode) == 1 then
  158. showConfirmDialog(message,nil,nil,25);
  159. else
  160. showConfirmDialog(message);
  161. end
  162. end
  163. end
  164. app.user:addEventListener("onPhoneLoginErrResponse", OnActorLoginFailed)
  165. end
  166. function registerEnterRoomEvent()
  167. local function onEnterRoomSuccess(event)
  168. --EAPSDK 进入房间自动隐藏
  169. if G_LayerMain then
  170. G_LayerMain:setVisible(false);
  171. end
  172. local gameId = event.gameId or 0;
  173. local gameType = event.gameType or 0;
  174. --目前只有金币场用到,用于区分是进入房间成功还是断线重连(金币场的gameStatus无法使用)
  175. local param = event.param;
  176. runInNextFrame(function()
  177. local roomViewName = getSubGameRoomView(gameId, gameType, app.protocolType)
  178. logD("onEnterRoomSuccess() roomViewName = " .. roomViewName)
  179. if roomViewName then
  180. local arr = string.split(roomViewName, ".")
  181. local len = table.nums(arr)
  182. local currentView = app:getCurrentView();
  183. if currentView then
  184. logD("onEnterRoomSuccess() currentName = " .. currentView.__cname)
  185. else
  186. logD("onEnterRoomSuccess() currentView is nil")
  187. end
  188. if currentView and currentView.__cname == arr[len] then
  189. -- 当前正是在我想去的房间里面
  190. logD("onEnterRoomSuccess() do nothing")
  191. else
  192. logD("onEnterRoomSuccess() goto view " .. roomViewName)
  193. app:gotoView(import(roomViewName):new(param));
  194. end
  195. end
  196. end)
  197. end
  198. app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
  199. end
  200. function registerKickoutEvent()
  201. local function onServerKickout()
  202. local function onClickOk()
  203. app.plugin:logout();
  204. end
  205. app.net.isNeedReconnect = false
  206. app.net:close();
  207. showConfirmDialog("数据异常,请重新登录", onClickOk)--"您的账号在其他地方登陆,您被强制下线"
  208. end
  209. app.user:addEventListener("onServerKickOutResponse", onServerKickout)
  210. end
  211. --子游戏更新获取完成事件
  212. function registerSubGameListEvent()
  213. local function getSubGameListSuccessed()
  214. if not isUpdateData then
  215. isUpdateData=true
  216. gotoRoom()
  217. end
  218. end
  219. app.serverConfigs:addEventListener("getSubGameListSuccessed", getSubGameListSuccessed)
  220. end
  221. --绑定手机结果/绑定微信/二次授权
  222. function registerBindAppEvent()
  223. local function onBindResponse(event)
  224. if not event or not event.response then
  225. return
  226. end
  227. local ret = tonumber(event.response.ret);
  228. if ret == 7 then
  229. uploadLogs("WEIXIN_TWICE_BIND")
  230. end
  231. local tips =
  232. {
  233. [0] = "绑定成功",
  234. [1] = "验证码错误",
  235. [2] = "已绑定过手机号,无需再次绑定",
  236. [5] = "该手机号已经被其他游戏ID绑定,请更换手机号再次绑定",
  237. [6] = "绑定成功",
  238. [7] = "该微信号已绑定过其他游戏账号",
  239. [8] = "绑定成功",
  240. [9] = "设置成功",
  241. }
  242. local msg = tips[ret] or "未知错误:"..tostring(ret)
  243. showConfirmDialog(msg, function() end)
  244. end
  245. app.user:addEventListener("onBindResponse", onBindResponse)
  246. end
  247. --修改手机号/修改密码
  248. function registerChangeAppEvent()
  249. local function onChangePlayerInfo(event)
  250. if not event or not event.response then
  251. return
  252. end
  253. local ret = tonumber(event.response.ret);
  254. local tips =
  255. {
  256. [0] = "修改成功",
  257. [1] = "您的账号还没有绑定,请先使用【微信登陆】并在玩家信息中绑定【手机】账号",
  258. [2] = "密码错误",
  259. [3] = "账号已经禁止使用",
  260. [4] = "验证码错误",
  261. [7] = "该手机号已绑定过其他游戏账号",
  262. [8] = "该手机号还未注册",
  263. }
  264. local msg = tips[ret] or "未知错误:"..tostring(ret)
  265. showConfirmDialog(msg, function() end)
  266. end
  267. app.user:addEventListener("onChangePlayerInfo", onChangePlayerInfo)
  268. end
  269. -- 开始侦听所有全局事件
  270. function startGlobalEvent()
  271. if isReviewWithMiniGame() then
  272. return
  273. end
  274. netConnectSucceed()
  275. actorLoginSucceed()
  276. actorLoginFailed()
  277. registerEnterRoomEvent()
  278. registerKickoutEvent()
  279. registerSubGameListEvent()
  280. registerBindAppEvent()
  281. registerChangeAppEvent()
  282. end