ServerCommerceMiddle.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. local Util = require("common.Util")
  2. local WarZoneConf = require("excel.WarZone")
  3. local MiddleConnect = require("middle.MiddleConnect")
  4. local MiddleManager = require("middle.MiddleManager")
  5. local InnerMsg = require("core.InnerMsg")
  6. local Config = require("Config")
  7. local CommonDB = require("common.CommonDB")
  8. local Timer = require("core.Timer")
  9. local CommerceManger = require("serverCommerce.ServerCommerceManager")
  10. -- 缓存开服天数
  11. local tServerOpenDay = nil
  12. local SERVERCOMMERCEOPENDAY = 8 -- 活动开启要求天数
  13. -- 获取(中心服主动去获取)
  14. function CommerceMiddle_GetOpen()
  15. local tWarZoneConf = WarZoneConf.group
  16. local tMsgData = InnerMsg.wl.WL_COMMERCE_QUERYOPENDAY
  17. for _, v in ipairs(tWarZoneConf) do
  18. local nFirstServerID = MiddleConnect.MiddleConnect_ConfServerID2TrueServerID(v.nMinServerID)
  19. local fd = MiddleManager.getFDBySvrIndex(nFirstServerID)
  20. if fd then
  21. InnerMsg.sendMsg(fd, tMsgData)
  22. end
  23. end
  24. end
  25. -- 回复开服天数
  26. function CommerceMiddle_SendOpenDay(fd, msg)
  27. local nOpenDay = msg.nOpenDay
  28. local nServerConfID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
  29. if not tServerOpenDay then
  30. tServerOpenDay = {}
  31. end
  32. tServerOpenDay[nServerConfID] = nOpenDay
  33. end
  34. -- 请求开服天数
  35. function CommerceMiddle_QueryOpenDay(fd, msg)
  36. local tMsgData = InnerMsg.lw.LW_COMMERCE_SENDOPENDAY
  37. tMsgData.nOpenDay = CommonDB.getServerOpenDay()
  38. tMsgData.nSrcServerID = Config.SVR_INDEX
  39. InnerMsg.sendMsg(0, tMsgData)
  40. end
  41. function CommerceMiddle_QueryOpenAct(fd, msg)
  42. local nConfServerID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
  43. local nFirstServerID
  44. for _, v in ipairs(WarZoneConf.group) do
  45. if v.nMinServerID <= nConfServerID and v.nMaxServerID >= nConfServerID then
  46. nFirstServerID = v.nMinServerID
  47. break
  48. end
  49. end
  50. if nil == nFirstServerID or not tServerOpenDay or not tServerOpenDay[nFirstServerID] then
  51. print("[QueryOpenAct] 获取不到战区的第一个服务器\n")
  52. return
  53. end
  54. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  55. if not nSrcFD then
  56. return
  57. end
  58. local tMsgData = InnerMsg.wl.WL_COMMERCE_ACTOPEN
  59. tMsgData.nOpen = tServerOpenDay[nFirstServerID] >= SERVERCOMMERCEOPENDAY and 1 or 0
  60. tMsgData.nOperate = msg.nOperate
  61. InnerMsg.sendMsg(nSrcFD, tMsgData)
  62. end
  63. function CommerceMiddle_SendOpenAct(fd, msg)
  64. CommerceManger.CommerceAct_ActCheckOpen(msg.nOpen, msg.nOperate)
  65. end
  66. ------------------ 活动管理器操作 ------------------------
  67. -- 请求活动是否开启
  68. function CommerceMiddle_IsActOpen(nOperate)
  69. local tMsgData = InnerMsg.lw.LW_COMMERCE_ACTOPEN
  70. tMsgData.nSrcServerID = Config.SVR_INDEX
  71. tMsgData.nOperate = nOperate
  72. InnerMsg.sendMsg(0, tMsgData)
  73. end