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.

936 lines
25 KiB

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