|
|
@@ -10,11 +10,168 @@ local CommonDefine = require("common.CommonDefine")
|
|
|
local ServerCommerceManger = require("serverCommerce.ServerCommerceManager")
|
|
|
local ServerCommerceActDefine = require("serverCommerce.ServerCommerceActDefine")
|
|
|
local ServerCommerceRank = require("serverCommerce.ServerCommerceActRank")
|
|
|
+local Log = require("common.Log")
|
|
|
+
|
|
|
|
|
|
-- 缓存开服天数
|
|
|
local tServerOpenDay = nil
|
|
|
local SERVERCOMMERCEOPENDAY = 8 -- 活动开启要求天数
|
|
|
|
|
|
+-- 缓存已经回复的开服天数的服务器
|
|
|
+local tServerOKDay = nil
|
|
|
+
|
|
|
+local function CommerceMiddle_WriteLog(szLogText)
|
|
|
+ Log.write(Log.LOGID_OSS_COMMON_ACT, szLogText)
|
|
|
+end
|
|
|
+
|
|
|
+-- 检查是否进入下一轮
|
|
|
+local function CommerceMiddle_CheckGoNextBatch(nServerKey)
|
|
|
+ if _G.is_middle ~= true then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local tDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if not tDBData then
|
|
|
+ return true
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 已经是第三轮了
|
|
|
+ if tDBData.nBatchID >= 3 then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local nNowTime = os.time()
|
|
|
+ if nNowTime < tDBData.nEndTime then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local nDiffDay = Util.diffDay(tDBData.nEndTime)
|
|
|
+ if nDiffDay > ServerCommerceActDefine.COMMERCEACT_NEXTDAY then
|
|
|
+ print("[CommerceMiddle_CheckGoNextBatch] 间隔天数已经满足条件 nDiffDay = "..nDiffDay)
|
|
|
+ return true
|
|
|
+ end
|
|
|
+
|
|
|
+ return false
|
|
|
+end
|
|
|
+
|
|
|
+local function CommerceMiddle_CreateActTime()
|
|
|
+ local nNowTime = os.time()
|
|
|
+ local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
|
|
|
+ local tEndDate = os.date("*t",nEndTime)
|
|
|
+ tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
|
|
|
+ tEndDate.min = 0
|
|
|
+ tEndDate.sec = 0
|
|
|
+ nEndTime = os.time(tEndDate)
|
|
|
+
|
|
|
+ return nNowTime, nEndTime
|
|
|
+end
|
|
|
+
|
|
|
+-- 更新下一轮DB数据
|
|
|
+local function CommerceMiddle_CreateNextBatchDB(nServerKey)
|
|
|
+ local tOldDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if not tOldDBData then
|
|
|
+ CommerceMiddle_WriteLog("[CommerceMiddle_CreateNextBatchDB] 更新下一轮中心服活动时间数据, 但是不存在久的数据 nServerKey = "..nServerKey)
|
|
|
+ end
|
|
|
+
|
|
|
+ local nBeginTime, nEndTime = CommerceMiddle_CreateActTime()
|
|
|
+ local nBatchID = 1
|
|
|
+ if tOldDBData and tOldDBData.nBatchID then
|
|
|
+ nBatchID = tOldDBData.nBatchID + 1
|
|
|
+ end
|
|
|
+
|
|
|
+ local tDBData =
|
|
|
+ {
|
|
|
+ nBatchID = nBatchID,
|
|
|
+ nBeginTime = nBeginTime,
|
|
|
+ nEndTime = nEndTime
|
|
|
+ }
|
|
|
+
|
|
|
+ local szText = "[CommerceMiddle_CreateNewDB] 更新下一轮的DB数据 nServerKey = "..nServerKey.." nBatchID = "..tDBData.nBatchID
|
|
|
+ .." nBeginTime = "..tDBData.nBeginTime.." nEndTime = "..tDBData.nEndTime
|
|
|
+ CommerceMiddle_WriteLog(szText)
|
|
|
+
|
|
|
+ CommonDB.SetCommerceMiddleAct_ByKey(nServerKey, tDBData)
|
|
|
+end
|
|
|
+
|
|
|
+-- 创建新的DB数据
|
|
|
+local function CommerceMiddle_CreateNewDB(nServerKey)
|
|
|
+ local tOldData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if tOldData then
|
|
|
+ local bRet = CommerceMiddle_CheckGoNextBatch(nServerKey)
|
|
|
+ if false == bRet then
|
|
|
+ return
|
|
|
+ else
|
|
|
+ CommerceMiddle_WriteLog("[CommerceMiddle_CreateNewDB] 该服务器满足生成下一轮条件, 生成中心服时间数据 nServerKey = "..nServerKey)
|
|
|
+
|
|
|
+ CommerceMiddle_CreateNextBatchDB(nServerKey)
|
|
|
+
|
|
|
+ return
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local nBeginTime, nEndTime = CommerceMiddle_CreateActTime()
|
|
|
+ local tDBData =
|
|
|
+ {
|
|
|
+ nBatchID = 1,
|
|
|
+ nBeginTime = nBeginTime,
|
|
|
+ nEndTime = nEndTime
|
|
|
+ }
|
|
|
+
|
|
|
+ local szText = "[CommerceMiddle_CreateNewDB] 生成新的DB数据 nServerKey = "..nServerKey.." nBatchID = "..tDBData.nBatchID
|
|
|
+ .." nBeginTime = "..tDBData.nBeginTime.." nEndTime = "..tDBData.nEndTime
|
|
|
+ CommerceMiddle_WriteLog(szText)
|
|
|
+
|
|
|
+ CommonDB.SetCommerceMiddleAct_ByKey(nServerKey, tDBData)
|
|
|
+end
|
|
|
+
|
|
|
+local function CommerceMiddle_Refresh(nServerKey)
|
|
|
+ if _G.is_middle ~= true or not tServerOpenDay then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nOpenDay = tServerOpenDay[nServerKey]
|
|
|
+ if nOpenDay < 8 then
|
|
|
+ print("[CommerceMiddle_Refresh] 当前开服时间不足直接返回")
|
|
|
+ return
|
|
|
+ elseif nOpenDay == 8 then
|
|
|
+ CommerceMiddle_WriteLog("[CommerceMiddle_Refresh] 该服务器时间到达8天, 生成中心服时间数据 nServerKey = "..nServerKey)
|
|
|
+ CommerceMiddle_CreateNewDB(nServerKey)
|
|
|
+ else
|
|
|
+ if true == CommerceMiddle_CheckGoNextBatch(nServerKey) then
|
|
|
+ CommerceMiddle_WriteLog("[CommerceMiddle_Refresh] 该服务器满足生成下一轮条件, 生成中心服时间数据 nServerKey = "..nServerKey)
|
|
|
+
|
|
|
+ CommerceMiddle_CreateNextBatchDB(nServerKey)
|
|
|
+ else
|
|
|
+ print("[CommerceMiddle_Refresh] 当前不满足条件不生成下一轮")
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 发送活动开始时间
|
|
|
+local function CommerceMiddle_SendOpenTime(nServerID)
|
|
|
+ local fd = MiddleManager.getFDBySvrIndex(nServerID)
|
|
|
+ if not fd then
|
|
|
+ print("[CommerceMiddle_SendOpenTime] 获取不到对应的fd nServerID = "..nServerID)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nServerConfID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(nServerID)
|
|
|
+ local nServerKey = MiddleConnect.MiddleConnect_GetWarZoneServer(nServerConfID)
|
|
|
+
|
|
|
+ local tDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if not tDBData then
|
|
|
+ CommerceMiddle_WriteLog("[CommerceMiddle_SendOpenTime] 不存在对应的中心服DB数据 nServerKey = "..nServerKey)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local tMsgData = InnerMsg.wl.WL_COMMERCE_ACT_GET_OPENTIME
|
|
|
+ tMsgData.nBatchID = tDBData.nBatchID
|
|
|
+ tMsgData.nBeginTime = tDBData.nBeginTime
|
|
|
+ tMsgData.nEndTime = tDBData.nEndTime
|
|
|
+
|
|
|
+ InnerMsg.sendMsg(fd, tMsgData)
|
|
|
+end
|
|
|
+
|
|
|
-- 起服获取信息
|
|
|
function CommerceMiddle_InitServer()
|
|
|
if _G.is_middle ~= true then
|
|
|
@@ -40,14 +197,16 @@ function CommerceMiddle_GetOpen()
|
|
|
if _G.is_middle ~= true then
|
|
|
return
|
|
|
end
|
|
|
+ tServerOKDay = {}
|
|
|
+
|
|
|
print("[CommerceMiddle_GetOpen] 开始去获取服务器开启信息")
|
|
|
-
|
|
|
local tWarZoneConf = WarZoneConf.group
|
|
|
for _, v in ipairs(tWarZoneConf) do
|
|
|
local nFirstServerID = MiddleConnect.MiddleConnect_ConfServerID2TrueServerID(v.nMinServerID)
|
|
|
print("[CommerceMiddle_GetOpen] nMinServerID = "..v.nMinServerID.." nFirstServerID = "..nFirstServerID)
|
|
|
local fd = MiddleManager.getFDBySvrIndex(nFirstServerID)
|
|
|
if fd then
|
|
|
+ tServerOKDay[nFirstServerID] = 0
|
|
|
print("[CommerceMiddle_GetOpen] 中心服主动去获取数据 nFirstServerID = "..nFirstServerID)
|
|
|
local tMsgData = InnerMsg.wl.WL_COMMERCE_QUERYOPENDAY
|
|
|
InnerMsg.sendMsg(fd, tMsgData)
|
|
|
@@ -67,8 +226,26 @@ function CommerceMiddle_SendOpenDay(fd, msg)
|
|
|
tServerOpenDay = {}
|
|
|
end
|
|
|
|
|
|
+ if not tServerOKDay then
|
|
|
+ print("[CommerceMiddle_SendOpenDay] 没有正确的对 tServerOKDay 进行初始化")
|
|
|
+ tServerOKDay = {}
|
|
|
+ end
|
|
|
+
|
|
|
tServerOpenDay[nServerConfID] = nOpenDay
|
|
|
print("[CommerceMiddle_SendOpenDay] 回复开服天数 nServerConfID = "..nServerConfID.." nOpenDay = "..nOpenDay)
|
|
|
+
|
|
|
+ tServerOKDay[msg.nSrcServerID] = 1
|
|
|
+
|
|
|
+ local bOK = true
|
|
|
+ for _, v in pairs(tServerOKDay) do
|
|
|
+ if 0 == v then
|
|
|
+ bOK = false
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ if true == bOK then
|
|
|
+ CommerMiddle_CheckMiddleInfo()
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
-- 请求开服天数
|
|
|
@@ -169,6 +346,149 @@ function CommerveMiddle_GetRankInfo(tData)
|
|
|
ServerCommerceRank.CommercerActRank_GetRankInfo(tData)
|
|
|
end
|
|
|
|
|
|
+-- 检测是否存在中心服数据
|
|
|
+function CommerMiddle_CheckMiddleInfo()
|
|
|
+ if _G.is_middle ~= true then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ for nServerID, v in pairs(tServerOKDay) do
|
|
|
+ local nServerConfID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(nServerID)
|
|
|
+ local nServerKey = MiddleConnect.MiddleConnect_GetWarZoneServer(nServerConfID)
|
|
|
+ print("[CommerMiddle_CheckMiddleInfo] 进行判断中心服是否存在数据 nServerKey = "..nServerKey.." nServerID = "..nServerID)
|
|
|
+ local tDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ local nOpenDay = tServerOpenDay[nServerConfID]
|
|
|
+ -- 不存在去拿数据
|
|
|
+ if nil == tDBData then
|
|
|
+ --if nOpenDay >= 8 then
|
|
|
+ local fd = MiddleManager.getFDBySvrIndex(nServerID)
|
|
|
+ if fd then
|
|
|
+ local tMsgData = InnerMsg.wl.WL_COMMERCE_GET_ACT_INFO
|
|
|
+ tMsgData.nReqServerID = 0
|
|
|
+ InnerMsg.sendMsg(fd, tMsgData)
|
|
|
+ print("[CommerMiddle_CheckMiddleInfo] 发送数据完成")
|
|
|
+ else
|
|
|
+ print("[CommerMiddle_CheckMiddleInfo] 获取不到FD nServerID = "..nServerID)
|
|
|
+ end
|
|
|
+ --end
|
|
|
+ else
|
|
|
+ print("[CommerMiddle_CheckMiddleInfo] 存在数据, 判断是否刷新 nServerID = "..nServerID.." nServerKey = "..nServerKey
|
|
|
+ .." nBatchID = "..tDBData.nBatchID.." nBeginTime = "..tDBData.nBeginTime.." nEndTime = "..tDBData.nEndTime)
|
|
|
+ CommerceMiddle_Refresh(nServerKey)
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 中心服请求活动时间相关数据
|
|
|
+function CommerceMiddle_GetActInfo_WL(msg)
|
|
|
+ print("[CommerceMiddle_GetActInfo] 收到中心服请求")
|
|
|
+
|
|
|
+ local tDBData = CommonDB.GetCommerceActInfo()
|
|
|
+ local tMsgData = InnerMsg.lw.LW_COMMERCE_GET_ACT_INFO
|
|
|
+ table.print_lua_table(tDBData)
|
|
|
+
|
|
|
+ tMsgData.nReqServerID = msg.nReqServerID
|
|
|
+ tMsgData.nSrcServerID = Config.SVR_INDEX
|
|
|
+ tMsgData.nOperate = 0
|
|
|
+ tMsgData.nBatchID = 0
|
|
|
+ tMsgData.nBeginTime = 0
|
|
|
+ tMsgData.nEndTime = 0
|
|
|
+
|
|
|
+ if not tDBData or nil == _G.next(tDBData) then
|
|
|
+ tMsgData.nOperate = 2
|
|
|
+ else
|
|
|
+ tMsgData.nOperate = 1
|
|
|
+ tMsgData.nBatchID = tDBData.nBatchID
|
|
|
+ tMsgData.nBeginTime = tDBData.nBeginTime
|
|
|
+ tMsgData.nEndTime = tDBData.nEndTime
|
|
|
+ end
|
|
|
+
|
|
|
+ InnerMsg.sendMsg(0, tMsgData)
|
|
|
+end
|
|
|
+
|
|
|
+-- 中心服收到活动相关数据
|
|
|
+function CommerceMiddle_GetActInfo_LW(msg)
|
|
|
+ if msg.nOperate == 0 then
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 不存在对应的数据")
|
|
|
+ end
|
|
|
+
|
|
|
+ local nReqServerID = msg.nReqServerID
|
|
|
+ local nServerConfID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
|
|
|
+ local nServerKey = MiddleConnect.MiddleConnect_GetWarZoneServer(nServerConfID)
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 中心服收到回包 nReqServerID = "..nReqServerID.." nServerConfID = "..nServerConfID)
|
|
|
+ table.print_lua_table(msg)
|
|
|
+
|
|
|
+ local tDBData = {
|
|
|
+ nBatchID = 0,
|
|
|
+ nBeginTime = 0,
|
|
|
+ nEndTime = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ local tOldDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if tOldDBData then
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 存在db数据")
|
|
|
+ table.print_lua_table(tOldDBData)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 不存在对应的数据
|
|
|
+ if msg.nOperate == 2 then
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 当前上报的服务器没有对应的数据, 活动未开始")
|
|
|
+ CommerceMiddle_Refresh(nServerKey)
|
|
|
+ elseif msg.nOperate == 1 then
|
|
|
+ if nil == tOldDBData then
|
|
|
+ tDBData.nBatchID = msg.nBatchID
|
|
|
+ tDBData.nBeginTime = msg.nBeginTime
|
|
|
+ tDBData.nEndTime = msg.nEndTime
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 当前不存在数据, 进行了设置 nServerKey = "..nServerKey)
|
|
|
+ CommonDB.SetCommerceMiddleAct_ByKey(nServerKey, tDBData)
|
|
|
+ end
|
|
|
+
|
|
|
+ tOldDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if tOldDBData then
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 设置后的数据打印")
|
|
|
+ table.print_lua_table(tOldDBData)
|
|
|
+ end
|
|
|
+
|
|
|
+ CommerceMiddle_Refresh(nServerKey)
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 1111111")
|
|
|
+ table.print_lua_table(tDBData)
|
|
|
+
|
|
|
+ if 0 ~= nReqServerID then
|
|
|
+ print("[CommerceMiddle_GetActInfo_LW] 当前有服务器请求数据 nReqServerID = "..nReqServerID)
|
|
|
+ CommerceMiddle_SendOpenTime(nReqServerID)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 普通服请求活动时间
|
|
|
+function CommerceMiddle_GetActOpenTime_LW(msg)
|
|
|
+ if _G.is_middle ~= true then return end
|
|
|
+
|
|
|
+ local nServerConfID = MiddleConnect.MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
|
|
|
+ local nServerKey = MiddleConnect.MiddleConnect_GetWarZoneServer(nServerConfID)
|
|
|
+
|
|
|
+ local tDBData = CommonDB.GetCommerceMiddleAct_ByKey(nServerKey)
|
|
|
+ if nil == tDBData then
|
|
|
+ local nFirstServerID = MiddleConnect.MiddleConnect_ConfServerID2TrueServerID(nServerKey)
|
|
|
+ local fd = MiddleManager.getFDBySvrIndex(nFirstServerID)
|
|
|
+ if fd then
|
|
|
+ local tMsgData = InnerMsg.wl.WL_COMMERCE_GET_ACT_INFO
|
|
|
+ tMsgData.nReqServerID = msg.nSrcServerID
|
|
|
+ InnerMsg.sendMsg(fd, tMsgData)
|
|
|
+ else
|
|
|
+ print("[CommerceMiddle_GetActOpenTime_LW] 不存在对应的fd 数据 nFirstServerID = "..nFirstServerID)
|
|
|
+ end
|
|
|
+ else
|
|
|
+ CommerceMiddle_Refresh(nServerKey)
|
|
|
+ CommerceMiddle_SendOpenTime(msg.nSrcServerID)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function CommerceMiddle_GetActOpenTime_WL(msg)
|
|
|
+ ServerCommerceManger.CommerceAct_GetActTime(msg)
|
|
|
+end
|
|
|
+
|
|
|
------------------ 活动管理器操作 ------------------------
|
|
|
-- 请求活动是否开启
|
|
|
function CommerceMiddle_IsActOpen(nOperate)
|
|
|
@@ -221,4 +541,11 @@ function CommerceMiddle_GMClearMiddleMail()
|
|
|
local tMsgData = InnerMsg.lw.LW_COMMERCE_GM_CLEAR_MAIL
|
|
|
tMsgData.nSrcServerID = Config.SVR_INDEX
|
|
|
InnerMsg.sendMsg(0, tMsgData)
|
|
|
+end
|
|
|
+
|
|
|
+function CommerceMiddle_QueryActOpenTime()
|
|
|
+ local tMsgData = InnerMsg.lw.LW_COMMERCE_ACT_GET_OPENTIME
|
|
|
+ tMsgData.nSrcServerID = Config.SVR_INDEX
|
|
|
+ InnerMsg.sendMsg(0, tMsgData)
|
|
|
+ print("[CommerceMiddle_QueryActOpenTime] 请求中心服活动开启时间")
|
|
|
end
|