jjcNewLadderMiddle.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. --------------------------------
  2. -- 文件名 : jjcNewLadderMiddle.lua
  3. -- 文件说明 : 天梯赛-跨服相关
  4. -- 创建时间 : 2025/05/21
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local WarZoneConf = require("excel.WarZone")
  9. local MiddleConnect = require("middle.MiddleConnect")
  10. local MiddleManager = require("middle.MiddleManager")
  11. local InnerMsg = require("core.InnerMsg")
  12. local Config = require("Config")
  13. local CommonDB = require("common.CommonDB")
  14. local Timer = require("core.Timer")
  15. local Log = require("common.Log")
  16. local JjcNewLogic = require("jjcnewladder.jjcNewLadderLogic")
  17. -- local JjcNewLadderDB = require("jjcnewladder.jjcNewLadderDB")
  18. local CommonDefine = require("common.CommonDefine")
  19. ----------------------------------- 内部操作 ---------------------------
  20. -- 判断是否是战区第一个服
  21. local function JjcNewLadderMiddle_CheckIsFirstWarServer(nServerID)
  22. local nConfServerID = nServerID - CommonDefine.COMMON_SERVER_OFFSET
  23. local tWarZoneConf = WarZoneConf.group
  24. for _, v in pairs(tWarZoneConf) do
  25. if v.nMinServerID == nConfServerID then
  26. return true
  27. end
  28. end
  29. return false
  30. end
  31. --------------------------- 跨服请求 ------------------------------
  32. -- 普通服请求报名参加
  33. function JjcNewLadderMiddle_JoinLadder(human)
  34. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_JOINLADDER_O2C
  35. tMsgData.uuid = human.db._id
  36. tMsgData.name = human.db.name
  37. tMsgData.nSrcServerID = Config.SVR_INDEX
  38. tMsgData.head = human.db.head
  39. tMsgData.headFrame = human.db.headFrame
  40. tMsgData.szServerName = Config.NEW_SVR_INDEX.."区"
  41. tMsgData.zhandouli = human.db.zhandouli
  42. InnerMsg.sendMsg(0, tMsgData)
  43. end
  44. -- 数据服回复中心服报名数据
  45. function JjcNewLadderMiddle_JoinLadder_D2C(uuid, nSrcServerID, nRank, tRivalData, nPoint)
  46. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_JOINLADDER_D2C
  47. tMsgData.uuid = uuid
  48. tMsgData.nSrcServerID = nSrcServerID
  49. tMsgData.nRank = nRank
  50. tMsgData.tEnemy = tRivalData
  51. tMsgData.nPoint = nPoint
  52. InnerMsg.sendMsg(0, tMsgData)
  53. print("[JjcNewLadderMiddle_JoinLadder_D2C] 数据服回复中心服报名数据")
  54. end
  55. -- 普通服请求刷新对手
  56. function JjcNewLadderMiddle_RefreshEnemy(human)
  57. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_REFRESH_O2C
  58. tMsgData.uuid = human.db._id
  59. tMsgData.nSrcServerID = Config.SVR_INDEX
  60. InnerMsg.sendMsg(0, tMsgData)
  61. print("[JjcNewLadderMiddle_RefreshEnemy] 普通服请求刷新对手发送协议完成")
  62. end
  63. -- 数据服回复中心服刷新对战列表
  64. function JjcNewLadderMiddle_RefreshEnemy_D2C(uuid, nSrcServerID, tRivalData)
  65. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_REFRESH_D2C
  66. tMsgData.uuid = uuid
  67. tMsgData.nSrcServerID = nSrcServerID
  68. tMsgData.tEnemy = tRivalData
  69. InnerMsg.sendMsg(0, tMsgData)
  70. end
  71. -- 请求上一轮前3名玩家信息
  72. function JjcNewLadderMiddle_QueryLastRank()
  73. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_LAST3RANK_O2C
  74. tMsgData.nSrcServerID = Config.SVR_INDEX
  75. InnerMsg.sendMsg(0, tMsgData)
  76. end
  77. -- 点赞对应玩家(发起人, 被点赞人, 被点赞人服务器ID)
  78. function JjcNewLadderMiddle_SendWorShip(uuidSrc, uuidDes, nDesServerID)
  79. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_WORSHIP_O2C
  80. tMsgData.uuidSrc = uuidSrc
  81. tMsgData.uuidDes = uuidDes
  82. tMsgData.nSrcServerID = Config.SVR_INDEX
  83. tMsgData.nDesServerID = nDesServerID
  84. InnerMsg.sendMsg(0, tMsgData)
  85. end
  86. -- 回复点赞数据
  87. function JjcNewLadderMiddle_AddWorShip_D2C(tData, nWorShipNum)
  88. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_WORSHIP_D2C
  89. tMsgData.uuidSrc = tData.uuidSrc
  90. tMsgData.nSrcServerID = tData.nSrcServerID
  91. tMsgData.uuidDes = tData.uuidDes
  92. tMsgData.nNowWorShip = nWorShipNum
  93. InnerMsg.sendMsg(0, tMsgData)
  94. end
  95. -- 请求排行榜数据
  96. function JjcNewLadderMiddle_QueryRankInfo()
  97. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_RANK_O2C
  98. tMsgData.nSrcServerID = Config.SVR_INDEX
  99. InnerMsg.sendMsg(0, tMsgData)
  100. end
  101. -- 回复排行榜数据给中心服
  102. function JjcNewLadderMiddle_QueryRankInfo_D2C(tRankData, nFinish, nServerID, nFirst)
  103. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_RANK_D2C
  104. tMsgData.nSrcServerID = nServerID
  105. tMsgData.nIsEnd = nFinish
  106. tMsgData.nFirst = nFirst
  107. tMsgData.tRankInfo = tRankData
  108. InnerMsg.sendMsg(0, tMsgData)
  109. end
  110. -- 请求检测能否进入战斗
  111. function JjcNewLadderMiddle_CheckCanFightBegin(human, uuidEnemy)
  112. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C
  113. tMsgData.uuid = human.db._id
  114. tMsgData.uuidDes = uuidEnemy
  115. tMsgData.nSrcServerID = Config.SVR_INDEX
  116. InnerMsg.sendMsg(0, tMsgData)
  117. print("[JjcNewLadderMiddle_CheckCanFightBegin] 去请求检测能否进入战斗 ")
  118. end
  119. -- 数据服回复检测战斗完成
  120. function JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  121. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C
  122. tMsgData.uuid = tData.uuid
  123. tMsgData.uuidDes = tData.uuidDes
  124. tMsgData.nSrcServerID = tData.nSrcServerID
  125. tMsgData.nIsFight = nCanFight
  126. InnerMsg.sendMsg(0, tMsgData)
  127. end
  128. -- 通知中心服战斗结果
  129. function JjcNewLadderMiddle_FightEndO2C(uuid, uuidDes, nResult, tEnemyUid, nZhanDouLi)
  130. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C
  131. tMsgData.uuid = uuid
  132. tMsgData.uuidDes = uuidDes
  133. tMsgData.nResult = nResult
  134. tMsgData.nSrcServerID = Config.SVR_INDEX
  135. tMsgData.tEnemyUid = tEnemyUid
  136. tMsgData.nZhanDouLi = nZhanDouLi
  137. InnerMsg.sendMsg(0, tMsgData)
  138. end
  139. -- 回复中心服战斗后最新的排名等数据
  140. function JjcNewLadderMiddle_ReplyFightD2C(uuid, uuidDes, nSrcServerID, nNewRank, nNewPoint, tOldEnemyData, tNewOneEnemy)
  141. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C
  142. tMsgData.uuid = uuid
  143. tMsgData.uuidDes = uuidDes
  144. tMsgData.nSrcServerID = nSrcServerID
  145. tMsgData.nNewRank = nNewRank
  146. tMsgData.nNewPoint = nNewPoint
  147. tMsgData.tOldEnemyData = tOldEnemyData
  148. tMsgData.tNewOneEnemy = tNewOneEnemy
  149. InnerMsg.sendMsg(0, tMsgData)
  150. end
  151. -- 发送战败邮件
  152. function JjcNewLadderMiddle_SendFailMail(uuidDes, nServerID, SrcServerName, SrcName, nNewRank)
  153. print("[JjcNewLadderMiddle_SendFailMail] 开始发送战斗邮件 uuidDes = "..uuidDes.." nServerID = "..nServerID
  154. .." SrcServerName = "..SrcServerName.." SrcName = "..SrcName.." nNewRank = "..nNewRank)
  155. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_MAIL_D2C
  156. tMsgData.uuidDes = uuidDes
  157. tMsgData.nDesServerID = nServerID
  158. tMsgData.szServerName = SrcServerName
  159. tMsgData.szName = SrcName
  160. tMsgData.nNewRank = nNewRank
  161. InnerMsg.sendMsg(0, tMsgData)
  162. print("[JjcNewLadderMiddle_SendFailMail] 发送结束")
  163. end
  164. -- 发送奖励邮件
  165. function JjcNewLadderMiddle_SendPrizeMail(uuid, nServerID, nRank)
  166. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C
  167. tMsgData.uuid = uuid
  168. tMsgData.nServerID = nServerID
  169. tMsgData.nRank = nRank
  170. InnerMsg.sendMsg(0, tMsgData)
  171. end
  172. -- 请求玩家当前的点赞数
  173. function JjcNewLadderMiddle_QueryWorShip(tQueryWorShip)
  174. for _, v in ipairs(tQueryWorShip) do
  175. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_WORSHIP_D2C
  176. tMsgData.uuid = v.uuid
  177. tMsgData.nServerID = v.nServerID
  178. tMsgData.nFromServerID = Config.SVR_INDEX
  179. InnerMsg.sendMsg(0, tMsgData)
  180. end
  181. end
  182. function JjcNewLadderMiddle_QueryWorShipO2C(uuid, nFromServerID, nWorShip)
  183. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_WORSHIP_O2C
  184. tMsgData.uuid = uuid
  185. tMsgData.nFromServerID = nFromServerID
  186. tMsgData.nWorShip = nWorShip
  187. InnerMsg.sendMsg(0, tMsgData)
  188. end
  189. --------------------------- 收到跨服请求-----------------------------
  190. -- 收到其他服报名请求
  191. function WL_JJC_NEWLADDER_JOINLADDER_C2D(fd, msg)
  192. JjcNewLogic.JjcNewLadderLogic_JoinHuman(msg)
  193. end
  194. -- 收到报名回包
  195. function WL_JJC_NEWLADDER_JOINLADDER_C2O(fd, msg)
  196. JjcNewLogic.JjcNewLadderLogic_JoinHumanOk(msg)
  197. end
  198. -- 数据服收到刷新对战列表
  199. function WL_JJC_NEWLADDER_REFRESH_C2D(fd, msg)
  200. print("[WL_JJC_NEWLADDER_REFRESH_C2D] 数据服收到刷新对战列表")
  201. JjcNewLogic.JjcNewLadderLogic_RefeshEnemy(msg)
  202. end
  203. -- 请求刷新对战列表(中心-普通)
  204. function WL_JJC_NEWLADDER_REFRESH_C2O(fd, msg)
  205. JjcNewLogic.JjcNewLadderLogic_RefeshEnemyOK(msg)
  206. end
  207. -- 请求上一轮前3玩家信息(中心->数据)
  208. function WL_JJC_NEWLADDER_LAST3RANK_C2D(msg)
  209. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_LAST3RANK_D2O
  210. tMsgData.nSrcServerID = msg.nSrcServerID
  211. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  212. if not tLast3RankInfo then
  213. tMsgData.nExist = 0
  214. tMsgData.tLastRankInfo = {}
  215. else
  216. tMsgData.nExist = 1
  217. tMsgData.tLastRankInfo = tLast3RankInfo
  218. end
  219. print("[WL_JJC_NEWLADDER_LAST3RANK_C2D] 获取到数据开始回复中心服")
  220. InnerMsg.sendMsg(0, tMsgData)
  221. end
  222. -- 请求上一轮前3玩家信息(中心->普通)
  223. function WL_JJC_NEWLADDER_LAST3RANK_C2O(msg)
  224. JjcNewLogic.JjcNewLadderLogic_GetLast3RankOK(msg)
  225. end
  226. -- 进行点赞(中心->数据(被点赞玩家所在服))
  227. function WL_JJC_NEWLADDER_SEND_WORSHIP_C2D(msg)
  228. JjcNewLogic.JjcNewLadderLogic_AddWorShip(msg)
  229. end
  230. -- 进行点赞回复(中心->普通)
  231. function WL_JJC_NEWLADDER_SEND_WORSHIP_C2O(msg)
  232. JjcNewLogic.JjcNewLadderLogic_AddWorShipOK(msg)
  233. end
  234. -- 改变战区数据服记录的点赞数量
  235. function WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D(msg)
  236. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  237. local uuid, nAddNum = msg.uuidDes, msg.nAddNum
  238. local nNowWorShip, nSrcServerID
  239. for _, v in pairs(tLast3RankInfo) do
  240. if v.uuid == uuid then
  241. v.worshipCnt = v.worshipCnt + nAddNum
  242. nNowWorShip = v.worshipCnt + 1
  243. nSrcServerID = v.nServerID
  244. break
  245. end
  246. end
  247. if not nNowWorShip then
  248. print("[WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D] 获取不到对应的点赞数据")
  249. return
  250. end
  251. CommonDB.SetJjcLadderLast3RankInfo(tLast3RankInfo)
  252. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C
  253. tMsgData.uuidDes = uuid
  254. tMsgData.nNowWorShip = nNowWorShip
  255. tMsgData.nSrcServerID = nSrcServerID
  256. InnerMsg.sendMsg(0, tMsgData)
  257. end
  258. -- 通知对应战区所属服务器更新最新的点赞数
  259. function WL_JJC_NEWLADDER_WORSHIP_UPDATE_D2C(msg)
  260. JjcNewLogic.JjcNewLadderLogic_UpdateWorShip(msg)
  261. end
  262. -- 请求天梯赛排行榜数据(中心->战区数据服)
  263. function WL_JJC_NEWLADDER_QUERY_RANK_C2D(msg)
  264. JjcNewLogic.JjcNewLadderLogic_GetRankInfo(msg)
  265. end
  266. -- 获取到天梯赛排行榜数据(中心->普通)
  267. function WL_JJC_NEWLADDER_QUERY_RANK_C2O(msg)
  268. JjcNewLogic.JjcNewLadderLogic_GetRankInfoOK(msg)
  269. end
  270. -- 查询是否能够战斗(中心->战区数据服)
  271. function WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2D(msg)
  272. JjcNewLogic.JjcNewLadderLogic_CheckCanFight(msg)
  273. end
  274. -- 查询是否能够战斗(中心->普通)
  275. function WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2O(msg)
  276. JjcNewLogic.JjcNewLadderLogic_CheckCanFightOK(msg)
  277. end
  278. -- 战斗结束(中心->战区数据服)
  279. function WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2D(msg)
  280. JjcNewLogic.JjcNewLadderLogic_FightEnd(msg)
  281. end
  282. -- 战斗结束(中心 -> 普通)
  283. function WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2O(msg)
  284. JjcNewLogic.JjcNewLadderLogic_FightEndOK(msg)
  285. end
  286. function WL_JJC_NEWLADDER_SEND_MAIL_C2O(msg)
  287. JjcNewLogic.JjcNewLadderLogic_SendFailMailOK(msg)
  288. end
  289. function WL_JJC_NEWLADDER_SEND_RANK_PRIZE_C2O(msg)
  290. JjcNewLogic.JjcNewLadderLogic_SendPrizeMail(msg)
  291. end
  292. function WL_JJC_NEWLADDER_QUERY_WORSHIP_C20(msg)
  293. JjcNewLogic.JjcNewLadderLogic_QueryWorship(msg)
  294. end
  295. function WL_JJC_NEWLADDER_QUERY_WORSHIP_C2D(msg)
  296. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  297. if nil ~= _G.next(tLast3RankInfo) then
  298. for _, v in ipairs(tLast3RankInfo) do
  299. if v.uuid == msg.uuid then
  300. v.worshipCnt = msg.nWorShip
  301. break
  302. end
  303. end
  304. CommonDB.SetJjcLadderLast3RankInfo(tLast3RankInfo)
  305. end
  306. end