You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

941 lines
25 KiB

  1. --[[
  2. 说明:从服务器获取的所有配置信息
  3. 更新记录:
  4. ------------------------------------------------------------------
  5. 2018-03-01 重新优化获取子游戏列表的流程
  6. 获取服务器配置成功之后,开始初始化子游戏列表,同时请求登录。
  7. 也就是说,登录时可以子游戏列表的数据可能是空的。
  8. 初始化子游戏列表的流程
  9. 1、从本地读取子游戏列表数据
  10. 2、从服务器获取子游戏列表数据,成功后覆盖本地数据
  11. 3、将子游戏列表数据写入到本地文件
  12. 玩家登陆成功需要显示游戏列表时,肯定是又数据的。
  13. 如果此时网络状况良好,则数据是服务器下发的最新数据,
  14. 如果此时网络状况差,则使用的是本地文件的数据,即上一次从服务器获取的数据。
  15. 加入玩家是第一次打开游戏,就碰到网络状况差,则游戏列表是空的。此题无解。
  16. ------------------------------------------------------------------
  17. --]]
  18. require("luaScript.Protocol.ProtocolCommon")
  19. local ServerConfigs = class("ServerConfigs", require("luaScript.Protocol.Protocol"))
  20. local ConfigCmd =
  21. {
  22. --[[/**
  23. * 客户端请求获取配置信息
  24. * <pre>
  25. * 请求: {@code ServerConfigRequest}
  26. * </pre>
  27. */--]]
  28. GAME_COMMAND_GET_SERVER_CONF = 0x0301,
  29. --[[/**
  30. * server返回游戏的配置信息
  31. * <pre>
  32. * 推送: {@code ServerConfigResponse}
  33. * </pre>
  34. */--]]
  35. GAME_COMMAND_SEND_SERVER_CONF = 0x0302,
  36. --[[/**
  37. * server返回游戏的配置信息
  38. * <pre>
  39. * 推送: {@code ServerConfigsResponse}
  40. * </pre>
  41. */--]]
  42. GAME_COMMAND_SEND_GAME_CONF = 0x0303,
  43. --[[/**
  44. * 客户端和PHP之间交互使用的TCP通道
  45. * <pre>
  46. * 请求: {@code StringPacket}
  47. * </pre>
  48. */--]]
  49. GAME_COMMAND_PHP = 0x0401,
  50. }
  51. -- 登陆之前配置请求
  52. ServerConfigRequest = defClass("ServerConfigRequest"
  53. -- gameId
  54. ,defVar("appId", VT_String, "")
  55. )
  56. -- 服务器返回配置
  57. ServerConfigResponse= defClass("ServerConfigResponse"
  58. --json格式的信息
  59. , defVar("strContent", VT_String, "")
  60. )
  61. -- 多游戏配置数据
  62. ServerConfigsResponse = defClass("ServerConfigsResponse"
  63. -- 各个游戏的配置信息,json格式,
  64. , defVar("gameServerConfigList", VT_Vector(VT_String), {})
  65. )
  66. -- 登录之前需要做的初始化
  67. function ServerConfigs:initBeforeLogin()
  68. if not self._isInited then
  69. self:requestGetServerConfig()
  70. end
  71. end
  72. function ServerConfigs:initBeforLoginSuccessed(bInit)
  73. self._isInited = (bInit == true)
  74. if self._isInited then
  75. self:dispatchEvent({name = "initBeforLoginSuccessed"})
  76. end
  77. end
  78. function ServerConfigs:getInitStatus()
  79. return (self._isInited == true)
  80. end
  81. ------------------------- PHP 通道 -------------------------
  82. -- ttInfo : 传送给PHP的数据
  83. -- callback : 处理后的回调
  84. function ServerConfigs:sendPhpMsg(ttInfo, callback)
  85. if not ttInfo or type(ttInfo) ~= "table" then
  86. return
  87. end
  88. -- 索引++
  89. self.phpIndex = self.phpIndex + 1;
  90. -- 记录回调索引
  91. local callbackKey = self.phpIndex .. "_" .. (ttInfo.pSSq or "0")
  92. self.phpCallbackList[callbackKey] = callback
  93. -- 改变发往服务器的索引
  94. ttInfo.pSSq = callbackKey
  95. local strContent = json.encode(ttInfo)
  96. -- 发送消息到服务器
  97. local request = StringPacket:new()
  98. request.stringValue = strContent;
  99. logD("ServerConfigs:sendPhpMsg() request = " .. table.tostring(request))
  100. self:sendResponse{cmd = ConfigCmd.GAME_COMMAND_PHP , sender = request};
  101. end
  102. function ServerConfigs:onPhpMsgResponse(status, response)
  103. logD("ServerConfigs:onPhpMsgResponse()", tostring(status), table.tostring(response))
  104. if status ~= 0 then
  105. return
  106. end
  107. local ttResult = json.decode(response.stringValue)
  108. if not ttResult then
  109. return
  110. end
  111. local index = tostring(ttResult.pSSq)
  112. if not index then
  113. return
  114. end
  115. if not self.phpCallbackList[index] then
  116. return
  117. end
  118. self.phpCallbackList[index](0, ttResult);
  119. self.phpCallbackList[index] = nil;
  120. end
  121. ------------------------- 配置相关 -------------------------
  122. -- 获取配置信息
  123. function ServerConfigs:requestGetServerConfig()
  124. local request = ServerConfigRequest:new()
  125. request.appId = getAppId()
  126. log("ServerConfigs:requestGetServerConfig() request = ", table.tostring(request))
  127. self:sendResponse{cmd = ConfigCmd.GAME_COMMAND_GET_SERVER_CONF , sender = request};
  128. end
  129. function ServerConfigs:onServerConfigResponse(status, response)
  130. logD("ServerConfigs:onServerConfigResponse()", tostring(status), table.tostring(response))
  131. if status ~= 0 then
  132. return
  133. end
  134. local ttResult = json.decode(response.strContent)
  135. -- 公告信息
  136. self.notice = {}
  137. local notice = tostring(ttResult.notice) or ""
  138. if notice ~= "" then
  139. local arr = string.split(notice, "\n")
  140. for k,v in pairs(arr) do
  141. table.insert(self.notice, v)
  142. end
  143. end
  144. -- 滚动公告
  145. self.scroll = tostring(ttResult.scroll) or ""
  146. -- 游戏ID
  147. self.gameId = tonumber(ttResult.gameId) or 0
  148. -- 区域信息
  149. self.areano = tonumber(ttResult.areano) or 0
  150. -- 记录获取大厅配置成功
  151. self.isGetConfigSuccess = true
  152. self:onServerConfigSuccessed();
  153. end
  154. function ServerConfigs:onServerConfigsResponse(status, response)
  155. log("ServerConfigs:onServerConfigsResponse()", tostring(status), table.tostring(response))
  156. if status ~= 0 then
  157. return
  158. end
  159. self.configs = {}
  160. for _, value in pairs(response.gameServerConfigList) do
  161. local ttConfig = json.decode(value)
  162. if ttConfig and type(ttConfig) == "table" and ttConfig.gameid then
  163. self.configs[tonumber(ttConfig.gameid)] = ttConfig;
  164. if ttConfig.contiTimer then--连打房间解散时间,黄十八用
  165. app.user.contiTimer = ttConfig.contiTimer
  166. end
  167. end
  168. end
  169. self.isGetConfigsSuccess = true;
  170. self:onServerConfigSuccessed();
  171. end
  172. function ServerConfigs:onServerConfigSuccessed()
  173. if self.isGetConfigSuccess and self.isGetConfigsSuccess then
  174. -- 先请求一次全国数据,亲友圈、创建房间、修改玩法里面显示的必须是所有游戏
  175. self:requestGameList(0, true, function ()
  176. -- 再根据当前选择地区,再拉取对应地区的游戏列表
  177. local regionCode = cc.UserDefault:getInstance():getIntegerForKey("address_code_" .. app.config.RomSetting.Platform)
  178. self:requestGameList(regionCode)
  179. end)
  180. self:initBeforLoginSuccessed(true)
  181. end
  182. end
  183. ------------------------- 子游戏列表 -------------------------
  184. function ServerConfigs:saveSubGameListToFile()
  185. logD("ServerConfigs:saveSubGameListToFile()", table.tostring(self.subGameList))
  186. table.saveToLocFile(self.subGameList, "SubGameList.lua")
  187. end
  188. function ServerConfigs:loadSubGameListFromFile()
  189. self.subGameList = table.loadFromLocFile("SubGameList.lua") or {}
  190. logD("ServerConfigs:loadSubGameListFromFile()", table.tostring(self.subGameList))
  191. end
  192. -- 获取子游戏版本信息
  193. function ServerConfigs:requestGetSubGameVersions(endCallback)
  194. local params =
  195. {
  196. action = "system.games",
  197. app = getAppId(),
  198. uid = loadUserId(),
  199. apkver = "",-- 获取子游戏版本号时不再依赖APK的版本号 - zzb,20190715
  200. installGameVer = "",
  201. isNew=1,
  202. }
  203. for gameId,v in pairs(self.subGameList) do
  204. local ver=app.subGameManager:isInstaller(gameId) and app.subGameManager.GameVersions[gameId] or -1
  205. params.installGameVer=params.installGameVer..gameId..","..ver.."|"
  206. end
  207. --基础包
  208. local baseIds={1001,1002,1003}
  209. for k,gameId in pairs(baseIds) do
  210. local ver=app.subGameManager:isInstaller(gameId) and app.subGameManager.GameVersions[gameId] or -1
  211. params.installGameVer=params.installGameVer..gameId..","..ver.."|"
  212. end
  213. logD("ServerConfigs:requestGetSubGameVersions() ", table.tostring(params));
  214. self:sendPhpMsg(params, function(status, response)
  215. self:getSubGameVersionsResponse(status, response)
  216. if endCallback then
  217. endCallback()
  218. end
  219. end)
  220. end
  221. function ServerConfigs:getSubGameVersionsResponse(status, ttResult)
  222. logD("ServerConfigs:getSubGameVersionsResponse() " .. table.tostring(ttResult))
  223. self.getsubGameList = true
  224. if ttResult and tonumber(ttResult.code) == 200 and ttResult.result and type(ttResult.result) == "table" then
  225. for k,v in pairs(ttResult.result) do
  226. if k~="new" then
  227. local gameId = tonumber(k)
  228. local gameInfo = self.subGameList[gameId] or {}
  229. -- 下载提示
  230. gameInfo.desc = tostring(v.desc)
  231. -- 新版本
  232. gameInfo.version = tostring(v.ver)
  233. -- 资源下载地址
  234. if v.url and v.url ~= "" then
  235. gameInfo.versionUrls = toStringArray(",")(v.url)
  236. end
  237. self.subGameList[gameId] = gameInfo;
  238. end
  239. end
  240. --添加新更新数据
  241. if ttResult.result.new then
  242. for k,v in pairs(ttResult.result.new) do
  243. local gameId = tonumber(k)
  244. if self.subGameList[gameId] then
  245. self.subGameList[gameId].newUpdate=v
  246. else
  247. self.subGameList[gameId] = {}
  248. self.subGameList[gameId].newUpdate=v
  249. end
  250. end
  251. end
  252. end
  253. -- 添加更多游戏的显示
  254. -- local gameInfo =
  255. -- {
  256. -- gameId = 0;
  257. -- gameName = "更多游戏";
  258. -- sortIndex = 9999;
  259. -- show = true;
  260. -- }
  261. -- self.subGameList[gameInfo.gameId] = gameInfo
  262. if isIOSReviewVersion() then
  263. -- 苹果审核
  264. ---self:updateSubGameVisible({7,12})
  265. self:updateSubGameVisible()
  266. elseif isRuanZhu() then
  267. -- 软著
  268. if app.config.RomSetting.ruanZhuGames then
  269. self:updateSubGameVisible(app.config.RomSetting.ruanZhuGames or {})
  270. else
  271. -- 六胡抢
  272. self:updateSubGameVisible({5})
  273. end
  274. else
  275. --self:updateSubGameVisible()
  276. --logD("ServerConfigs requestGameList4 :", table.tostring(self.subGameList))
  277. if self.subGameList[3] then --欢乐拼五张
  278. self.subGameList[3].show = false
  279. end
  280. end
  281. -- 保存到本地
  282. self:saveSubGameListToFile();
  283. self:dispatchEvent({name = "getSubGameListSuccessed"})
  284. end
  285. -- 设置哪些子游戏是需要显示的
  286. -- ttShow = {gameid, gameid, gameid}
  287. function ServerConfigs:updateSubGameVisible(ttShow)
  288. if ttShow then
  289. -- 全部标记为不显示
  290. for k,v in pairs(self.subGameList) do
  291. v.show = false;
  292. end
  293. for _,v in pairs(ttShow) do
  294. if self.subGameList[v] then
  295. self.subGameList[v].show = true
  296. end
  297. end
  298. else
  299. -- 全部标记为显示
  300. for k,v in pairs(self.subGameList) do
  301. v.show = true;
  302. end
  303. end
  304. end
  305. -- 获取指定子游戏的配置信息
  306. -- 可能返回 nil
  307. function ServerConfigs:getSubGameConfig(gameId)
  308. if not gameId then
  309. return nil
  310. end
  311. return self.subGameList[gameId]
  312. end
  313. -- 获取指定web子游戏的配置信息
  314. -- 可能返回 nil
  315. function ServerConfigs:getWebGameConfig(gameId)
  316. for i,v in pairs(self.webGameList) do
  317. if v.gameId == gameId then
  318. return v
  319. end
  320. end
  321. return nil
  322. end
  323. function ServerConfigs:requestClientConfig(callback)
  324. logD("ServerConfigs:requestClientConfig()")
  325. local params =
  326. {
  327. action = "system.clicfg",
  328. app = getAppId(),
  329. uid = loadUserId(),
  330. }
  331. logD("ServerConfigs:requestClientConfig() ", table.tostring(params));
  332. app.waitDialogManager:showWaitNetworkDialog("请稍等...")
  333. self:sendPhpMsg(params, function(status,response)
  334. app.waitDialogManager:closeWaitNetworkDialog()
  335. logD("ServerConfigs:requestClientConfig() ", table.tostring(response));
  336. if tonumber(response.code)==200 then
  337. if response.result and table.nums(response.result)>0 then
  338. self.clientConfig = response.result
  339. table.saveToLocFile(self.clientConfig, "ClientConfig.lua")
  340. math.randomseed(tostring(os.time()):reverse():sub(1, 6));
  341. local wx = response.result.wx or {};
  342. if table.nums(wx) > 0 then
  343. local idx = math.random(table.nums(wx))
  344. if wx[idx] then
  345. app.plugin:initWxShare(wx[idx].appid, wx[idx].secret);
  346. else
  347. app.plugin:initWxShare(wx.appid, wx.secret);
  348. end
  349. else
  350. if app.plugin and wx.appid and wx.secret then
  351. app.plugin:initWxShare(wx.appid, wx.secret);
  352. end
  353. end
  354. end
  355. end
  356. if callback then callback() end
  357. app:dispatchEvent({name = "onRequestClientConfig"})
  358. end)
  359. end
  360. function ServerConfigs:requestWebGameUrl(gameId,callback)
  361. local function getOrientation (url)
  362. local orientation = 1;
  363. local index = string.find(url,"?")
  364. if index then
  365. local params=string.sub(url,index+1,string.len(url))
  366. local tmp = string.split(params,"&");
  367. local args = {};
  368. for k, v in pairs(tmp) do
  369. local arr = string.split(v, "=");
  370. if arr[1] == "orientation" then
  371. orientation = arr[2] or 1;
  372. break;
  373. end
  374. end
  375. end
  376. return orientation;
  377. end
  378. local params =
  379. {
  380. action = "platform.geturl",
  381. app = getAppId(),
  382. uid = loadUserId(),
  383. tinyid = gameId,
  384. }
  385. -- logD("ProtocolSubGame:requestWebGameList() ", table.tostring(params));
  386. self:sendPhpMsg(params,function (status,response)
  387. -- dump(response)
  388. if tonumber(response.code)==200 then
  389. local orientation = getOrientation(response.result);
  390. if callback then callback(response.result, tonumber(orientation)) end
  391. else
  392. if callback then callback() end
  393. end
  394. end)
  395. end
  396. function ServerConfigs:getGameGroupConfig(gameId, regionCode)
  397. regionCode = regionCode or 0
  398. local subGameList = self.regionGameList[regionCode] or self.subGameList
  399. if subGameList[gameId] then
  400. local strGameConfig = subGameList[gameId].gameRule
  401. if strGameConfig and strGameConfig~="" then
  402. local gameConfig = json.decode(strGameConfig)
  403. if gameConfig and gameConfig.group and gameConfig.group.games then
  404. return gameConfig.group
  405. end
  406. end
  407. end
  408. return nil
  409. end
  410. function ServerConfigs:getWebGameGroupConfig(gameId)
  411. for i,v in pairs(self.webGameList) do
  412. if v.gameId == gameId then
  413. local strGameConfig = v.gamecfg
  414. if strGameConfig and strGameConfig~="" then
  415. local gameConfig = json.decode(strGameConfig)
  416. if gameConfig and gameConfig.group then
  417. return gameConfig.group
  418. end
  419. end
  420. end
  421. end
  422. return nil
  423. end
  424. ---
  425. -- 子游戏是否在合集里面
  426. -- @return boolean
  427. --
  428. function ServerConfigs:isWebGameInGroup (gameId)
  429. local isExist = false
  430. for i,v in pairs(self.webGameList) do
  431. local groupConfig = self:getWebGameGroupConfig(v.gameId) or {}
  432. local games = groupConfig.games or {}
  433. for _, id in ipairs(games) do
  434. if tonumber(id) == tonumber(gameId) then
  435. isExist = true
  436. break
  437. end
  438. end
  439. if isExist then
  440. break
  441. end
  442. end
  443. return isExist
  444. end
  445. function ServerConfigs:isNewGame(gameId)
  446. if self.subGameList[gameId] then
  447. local strGameConfig = self.subGameList[gameId].gameRule
  448. if strGameConfig and strGameConfig~="" then
  449. local gameConfig = json.decode(strGameConfig)
  450. if gameConfig and gameConfig.isNew then
  451. return gameConfig.isNew
  452. end
  453. end
  454. end
  455. return false
  456. end
  457. ---
  458. -- 获取子游戏列表
  459. -- @return
  460. --
  461. function ServerConfigs:getSubGameList()
  462. return self.subGameList
  463. end
  464. ---
  465. -- 获取子游戏列表(没有子游戏具体信息)
  466. -- @return
  467. --
  468. function ServerConfigs:getGameList(regionCode)
  469. regionCode = regionCode or 0
  470. local gameList = {}
  471. local baseIds={
  472. [1001]=true,
  473. [1002]=true,
  474. [1003]=true
  475. }
  476. if isIOSReviewVersion() then
  477. -- 添加更多游戏的显示
  478. local gameInfo =
  479. {
  480. gameId = 0;
  481. gameName = "更多游戏";
  482. sortIndex = 9999;
  483. show = true;
  484. visible = true;
  485. }
  486. self.subGameList[gameInfo.gameId] = gameInfo
  487. end
  488. local subGameList = self.regionGameList[regionCode] or self.subGameList
  489. local tt = {}
  490. for k,v in pairs(subGameList) do
  491. if v.visible and v.showInHall == 1 then
  492. if v.other_name and v.other_name ~= "" then
  493. if not tt[v.other_name] then
  494. tt[v.other_name] = {}
  495. end
  496. table.insert(tt[v.other_name],{gameId = v.gameId, sort = v.sortIndex ,gameType = "sub"})
  497. elseif v.gameId and not baseIds[v.gameId] then
  498. table.insert(gameList,{gameId = v.gameId, sort = v.sortIndex ,gameType = "sub"})
  499. end
  500. end
  501. end
  502. for k,v in pairs(tt) do
  503. --求最小排序
  504. table.sort(v, function (a,b)
  505. return a.sort<b.sort
  506. end)
  507. table.insert(gameList,{data = v,sort = v[1].sort,gameType = "sub",gameId = v[1].gameId})
  508. end
  509. --如果是苹果审核版则不需要小游戏
  510. if not isIOSReviewVersion() then
  511. local ttWebGame = {}
  512. for k,v in pairs(self.webGameList) do
  513. if v.other_name and v.other_name ~= "" then
  514. if not tt[v.other_name] then
  515. tt[v.other_name] = {}
  516. end
  517. table.insert(tt[v.other_name],{gameId = v.gameId, sort = v.sortIndex ,gameType = "web"})
  518. else
  519. table.insert(gameList,{gameId = v.gameId, icon = v.icon, sort = v.sort ,gameType = "web"})
  520. end
  521. end
  522. for k,v in pairs(ttWebGame) do
  523. table.insert(gameList,{data = v,sort = v[1].sort,gameType = "web",gameId = v[1].gameId})
  524. end
  525. end
  526. table.sort(gameList, function (a,b)
  527. return a.sort<b.sort
  528. end)
  529. dump(gameList,"--hall gamelist--")
  530. return gameList
  531. end
  532. --是否对当前用户打开webGame
  533. function ServerConfigs:isOpenWebGame(gameId)
  534. local isOpen = false
  535. local gamecfg = nil
  536. for k,v in pairs(self.webGameList) do
  537. if v.gameId==gameId then
  538. gamecfg = v.gamecfg
  539. break
  540. end
  541. end
  542. -- local gamecfg = webGame.gamecfg --添加userid 字段判断白名单测试
  543. if gamecfg and gamecfg~="" then
  544. local cfg = json.decode(gamecfg)
  545. if cfg and cfg.userId then
  546. local users = string.split(cfg.userId,",")
  547. for k,v in pairs(users) do
  548. if tonumber(v) == tonumber(app.user.loginInfo.uid) then
  549. isOpen = true
  550. end
  551. end
  552. else
  553. isOpen = true
  554. end
  555. else
  556. isOpen = true
  557. end
  558. return isOpen
  559. end
  560. function ServerConfigs:isNewWebGame(gameId)
  561. local isNew = false
  562. local gamecfg = nil
  563. for k,v in pairs(self.webGameList) do
  564. if v.gameId==gameId then
  565. gamecfg = v.gamecfg
  566. break
  567. end
  568. end
  569. -- local gamecfg = webGame.gamecfg --添加userid 字段判断白名单测试
  570. if gamecfg and gamecfg~="" then
  571. local cfg = json.decode(gamecfg)
  572. if cfg and cfg.isNew then
  573. isNew = cfg.isNew
  574. end
  575. end
  576. return isNew
  577. end
  578. --获取活动数据列表(新接口)
  579. function ServerConfigs:requestMissionList()
  580. local params =
  581. {
  582. action= "missions.lists",
  583. uid = app.user.loginInfo.uid,
  584. app = getAppId(),
  585. }
  586. logD("ServerConfigs:requestMissionList()", table.tostring(params))
  587. self:sendPhpMsg(params, function(status,response)
  588. -- if status ~= "successed" then
  589. -- logE("活动数据拉取失败")
  590. -- return
  591. -- end
  592. -- local data = json.decode(response)
  593. -- logD("ServerConfigs:requestMissionList()", table.tostring(response))
  594. if tonumber(response.code)~=200 then
  595. logE("活动数据错误")
  596. return
  597. end
  598. -- "code":200,
  599. -- "error":"",
  600. -- "result":{
  601. -- {
  602. -- "id" : 1, //任务ID
  603. -- "type": 1, //任务类型 4展示任务
  604. -- "name":"活动名称", //任务名称
  605. -- "desc":"" //任务描述
  606. -- "ishot": 1, //是否最热
  607. -- "sort":1, //排序
  608. -- "ext":'', //扩展信息
  609. -- "pic":'', //图片
  610. -- "catalog":1, //活动分类 1 游戏公告 2 精彩活动
  611. -- }
  612. -- }
  613. self.missions = response.result or {}
  614. -- for k,v in pairs(data.result) do
  615. -- end
  616. app:dispatchEvent({name = "onGetActivityInfoResponse"})
  617. end)
  618. end
  619. function ServerConfigs:getMissionListByType(catalog)
  620. local missions = {}
  621. local stickyIndex = 1 --置顶的index
  622. for k,v in pairs(self.missions) do
  623. if v.catalog == catalog then
  624. table.insert(missions,v)
  625. end
  626. --if v.sticky==1 then --置顶
  627. -- stickyIndex = #missions
  628. --end
  629. end
  630. table.sort(missions,function(a,b)
  631. return a.sort<b.sort
  632. end)
  633. for k,v in pairs(missions) do
  634. if v.sticky==1 then --置顶
  635. stickyIndex = k
  636. end
  637. end
  638. return missions,stickyIndex
  639. end
  640. --获取置顶类型
  641. function ServerConfigs:getStickyType()
  642. local catalog = 1 --置顶的类型
  643. for k,v in pairs(self.missions) do
  644. if v.sticky==1 then --置顶
  645. catalog = v.catalog
  646. end
  647. end
  648. return catalog
  649. end
  650. function ServerConfigs:popConfig()
  651. self:initPopConfig()
  652. if self.popConfigs and #self.popConfigs>0 then
  653. local config = self.popConfigs[1]
  654. table.remove(self.popConfigs,1)
  655. return config
  656. end
  657. return nil
  658. end
  659. function ServerConfigs:initPopConfig()
  660. if self.popConfigs then
  661. return
  662. end
  663. --弹出配置
  664. if cc.Application:getInstance():getTargetPlatform() == 0 then
  665. -- self.popConfigs = {"luaScript.Views.Main.HongBaoKa.HongBaoKaView", "luaScript.Views.Activity.ActivityMainView"}
  666. self.popConfigs = {}
  667. else
  668. local popWindows = PhpSetting["pop_window"] or {}
  669. table.sort(popWindows, function (a, b)
  670. return a.index < b.index
  671. end)
  672. local configs = {}
  673. for _, v in ipairs(popWindows or {}) do
  674. if v then
  675. table.insert(configs, v.view)
  676. end
  677. end
  678. self.popConfigs = configs;
  679. end
  680. end
  681. function ServerConfigs:ctor(net)
  682. ServerConfigs.super.ctor(self , net, ModuleId);
  683. -- php 通道相关
  684. self.phpIndex = 0
  685. self.phpCallbackList = {};
  686. self.isGetGameVerList = false
  687. -- 大厅的配置信息
  688. self.notice = {}; --{"",""}
  689. self.scroll = ""; --
  690. self.areano = ""; --
  691. -- 从gameServer获取的游戏列表
  692. self.configs = {}
  693. --活动配置
  694. self.missions = {}
  695. -- 从php获取的游戏列表
  696. --[[ self.subGameList =
  697. {
  698. [gameid] =
  699. {
  700. show = true;
  701. gameId = 5;
  702. gameName = "六胡抢";
  703. gameIcon = "http://img.dingdingqipai.com/images/games/lhq.png?v=1515639314";
  704. sortIndex = 4;
  705. version = "1000";
  706. versionUrls = {url, url}
  707. },
  708. }
  709. --]]
  710. self.subGameList = {}
  711. self.webGameList = table.loadFromLocFile("WebGameList.lua") or {}
  712. self.clientConfig = table.loadFromLocFile("ClientConfig.lua") or {
  713. myHead = "http://cnplayer.ddpenghu.com/client/user/loginpost?wechatid=8&wechatmpid=8", -- 我的装扮
  714. webgamb = RomSetting.ZhanJiUrl, -- 网页战绩
  715. }
  716. -- 是否已经初始化完成
  717. self._isInited = false
  718. -- 默认读取本地信息
  719. self:loadSubGameListFromFile()
  720. self:updateSubGameVisible()
  721. -- 请求配置信息
  722. self:defPushMsg{cmd = ConfigCmd.GAME_COMMAND_SEND_SERVER_CONF, reader = ServerConfigResponse, func = handler(self , self.onServerConfigResponse)};
  723. self:defPushMsg{cmd = ConfigCmd.GAME_COMMAND_SEND_GAME_CONF, reader = ServerConfigsResponse, func = handler(self , self.onServerConfigsResponse)};
  724. -- PHP 通道
  725. self:defPushMsg{cmd = ConfigCmd.GAME_COMMAND_PHP, reader = StringPacket, func = handler(self , self.onPhpMsgResponse)};
  726. end
  727. --------------------------------------------------------------------------------------------------------------------------------
  728. --------------------------------------------------------------------------------------------------------------------------------
  729. --------------------------------------------------------------------------------------------------------------------------------
  730. --------------------------------------------------------------------------------------------------------------------------------
  731. function ServerConfigs:requestGameList(regionCode, isFirstRequest, callback)
  732. -- 保存所有地区的游戏列表数据
  733. self.regionGameList = self.regionGameList or {}
  734. regionCode = regionCode or 0
  735. if self.regionGameList[regionCode] then
  736. -- 如果已经请求过该地区的数据,则不再请求游戏列表
  737. self:dispatchEvent({name = "getSubGameListSuccessed"})
  738. app.waitDialogManager:closeWaitNetworkDialog()
  739. return
  740. end
  741. local params =
  742. {
  743. action = "system.uniongameinfo",
  744. app = getAppId(),
  745. uid = loadUserId(),
  746. region = regionCode,
  747. }
  748. logD("ServerConfigs requestGameList :", table.tostring(params))
  749. self:sendPhpMsg(params, function(status, response)
  750. logD("ServerConfigs requestGameList :", table.tostring(response))
  751. app.waitDialogManager:closeWaitNetworkDialog()
  752. if tonumber(response.code) == 200 then
  753. -- self.subGameList = {}
  754. local subGameList = {}
  755. if response.result.game then
  756. for k,v in pairs(response.result.game) do
  757. local gameId = tonumber(k)
  758. local gamecfg = v.gamecfg
  759. local gamecfgData = json.decode(gamecfg)
  760. local gameInfo = {}
  761. -- gameId = gameId == 43 and 22 or gameId
  762. gameInfo.gameId = gameId
  763. gameInfo.gameName = tostring(v.name)
  764. gameInfo.gameIcon = tostring(v.icon)
  765. gameInfo.gameRule = tostring(v.gamecfg)
  766. gameInfo.sortIndex = tonumber(v.sort)
  767. gameInfo.other_name = tostring(v.other_name)
  768. gameInfo.show = true
  769. --游戏列表的显示逻辑用visible,创建房间的逻辑用show
  770. if gamecfgData then
  771. if gamecfgData.group and gamecfgData.group.show == "0" then
  772. gameInfo.visible = false
  773. else
  774. gameInfo.visible = true
  775. end
  776. if not gamecfgData.showInHall then
  777. gameInfo.showInHall = 1
  778. else
  779. gameInfo.showInHall = tonumber(gamecfgData.showInHall)
  780. end
  781. else
  782. gameInfo.visible = true
  783. gameInfo.showInHall = 1
  784. end
  785. -- self.subGameList[gameId] = gameInfo
  786. subGameList[gameId] = gameInfo
  787. end
  788. end
  789. -- 记录已经拉取过的地区游戏列表
  790. self.regionGameList[regionCode] = subGameList
  791. if isFirstRequest then
  792. -- self.subGameList为所有的游戏列表,检测游戏是否存在、热更等使用这个self.subGameList
  793. -- 大厅主界面显示游戏列表,使用self.regionGameList[regionCode]
  794. self.subGameList = self.regionGameList[regionCode]
  795. end
  796. self.webGameList = {}
  797. if response.result.tiny then
  798. for gameId,v in pairs(response.result.tiny) do
  799. v.gameId = tonumber(gameId)
  800. local gamecfgData = json.decode(v.gamecfg)
  801. if gamecfgData then
  802. local uids = gamecfgData.uids
  803. local uid = app.user.loginInfo.uid
  804. if uids then
  805. for _, vv in pairs(uids) do
  806. if tonumber(vv) == uid then
  807. table.insert(self.webGameList, v)
  808. break
  809. end
  810. end
  811. else
  812. table.insert(self.webGameList, v)
  813. end
  814. else
  815. table.insert(self.webGameList, v)
  816. end
  817. end
  818. table.saveToLocFile(self.webGameList, "WebGameList.lua")
  819. end
  820. if isFirstRequest then
  821. -- 只有第一次拉取所有全国游戏列表的时候,才会拉取版本信息
  822. self:requestGetSubGameVersions(callback)
  823. else
  824. self:dispatchEvent({name = "getSubGameListSuccessed"})
  825. end
  826. end
  827. end)
  828. end
  829. return ServerConfigs