jjcNewLadderMiddle.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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)
  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. InnerMsg.sendMsg(0, tMsgData)
  137. end
  138. -- 回复中心服战斗后最新的排名等数据
  139. function JjcNewLadderMiddle_ReplyFightD2C(uuid, uuidDes, nSrcServerID, nNewRank, nNewPoint, tOldEnemyData, tNewOneEnemy)
  140. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C
  141. tMsgData.uuid = uuid
  142. tMsgData.uuidDes = uuidDes
  143. tMsgData.nSrcServerID = nSrcServerID
  144. tMsgData.nNewRank = nNewRank
  145. tMsgData.nNewPoint = nNewPoint
  146. tMsgData.tOldEnemyData = tOldEnemyData
  147. tMsgData.tNewOneEnemy = tNewOneEnemy
  148. InnerMsg.sendMsg(0, tMsgData)
  149. end
  150. -- 发送战败邮件
  151. function JjcNewLadderMiddle_SendFailMail(uuidDes, nServerID, SrcServerName, SrcName, nNewRank)
  152. print("[JjcNewLadderMiddle_SendFailMail] 开始发送战斗邮件 uuidDes = "..uuidDes.." nServerID = "..nServerID
  153. .." SrcServerName = "..SrcServerName.." SrcName = "..SrcName.." nNewRank = "..nNewRank)
  154. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_MAIL_D2C
  155. tMsgData.uuidDes = uuidDes
  156. tMsgData.nDesServerID = nServerID
  157. tMsgData.szServerName = SrcServerName
  158. tMsgData.szName = SrcName
  159. tMsgData.nNewRank = nNewRank
  160. InnerMsg.sendMsg(0, tMsgData)
  161. print("[JjcNewLadderMiddle_SendFailMail] 发送结束")
  162. end
  163. -- 发送奖励邮件
  164. function JjcNewLadderMiddle_SendPrizeMail(uuid, nServerID, nRank)
  165. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C
  166. tMsgData.uuid = uuid
  167. tMsgData.nServerID = nServerID
  168. tMsgData.nRank = nRank
  169. InnerMsg.sendMsg(0, tMsgData)
  170. end
  171. -- 请求玩家当前的点赞数
  172. function JjcNewLadderMiddle_QueryWorShip(tQueryWorShip)
  173. for _, v in ipairs(tQueryWorShip) do
  174. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_WORSHIP_D2C
  175. tMsgData.uuid = v.uuid
  176. tMsgData.nServerID = v.nServerID
  177. tMsgData.nFromServerID = Config.SVR_INDEX
  178. InnerMsg.sendMsg(0, tMsgData)
  179. end
  180. end
  181. function JjcNewLadderMiddle_QueryWorShipO2C(uuid, nFromServerID, nWorShip)
  182. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_QUERY_WORSHIP_O2C
  183. tMsgData.uuid = uuid
  184. tMsgData.nFromServerID = nFromServerID
  185. tMsgData.nWorShip = nWorShip
  186. InnerMsg.sendMsg(0, tMsgData)
  187. end
  188. --------------------------- 收到跨服请求-----------------------------
  189. -- 收到其他服报名请求
  190. function WL_JJC_NEWLADDER_JOINLADDER_C2D(fd, msg)
  191. JjcNewLogic.JjcNewLadderLogic_JoinHuman(msg)
  192. end
  193. -- 收到报名回包
  194. function WL_JJC_NEWLADDER_JOINLADDER_C2O(fd, msg)
  195. JjcNewLogic.JjcNewLadderLogic_JoinHumanOk(msg)
  196. end
  197. -- 数据服收到刷新对战列表
  198. function WL_JJC_NEWLADDER_REFRESH_C2D(fd, msg)
  199. print("[WL_JJC_NEWLADDER_REFRESH_C2D] 数据服收到刷新对战列表")
  200. JjcNewLogic.JjcNewLadderLogic_RefeshEnemy(msg)
  201. end
  202. -- 请求刷新对战列表(中心-普通)
  203. function WL_JJC_NEWLADDER_REFRESH_C2O(fd, msg)
  204. JjcNewLogic.JjcNewLadderLogic_RefeshEnemyOK(msg)
  205. end
  206. -- 请求上一轮前3玩家信息(中心->数据)
  207. function WL_JJC_NEWLADDER_LAST3RANK_C2D(msg)
  208. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_LAST3RANK_D2O
  209. tMsgData.nSrcServerID = msg.nSrcServerID
  210. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  211. if not tLast3RankInfo then
  212. tMsgData.nExist = 0
  213. tMsgData.tLastRankInfo = {}
  214. else
  215. tMsgData.nExist = 1
  216. tMsgData.tLastRankInfo = tLast3RankInfo
  217. end
  218. print("[WL_JJC_NEWLADDER_LAST3RANK_C2D] 获取到数据开始回复中心服")
  219. InnerMsg.sendMsg(0, tMsgData)
  220. end
  221. -- 请求上一轮前3玩家信息(中心->普通)
  222. function WL_JJC_NEWLADDER_LAST3RANK_C2O(msg)
  223. JjcNewLogic.JjcNewLadderLogic_GetLast3RankOK(msg)
  224. end
  225. -- 进行点赞(中心->数据(被点赞玩家所在服))
  226. function WL_JJC_NEWLADDER_SEND_WORSHIP_C2D(msg)
  227. JjcNewLogic.JjcNewLadderLogic_AddWorShip(msg)
  228. end
  229. -- 进行点赞回复(中心->普通)
  230. function WL_JJC_NEWLADDER_SEND_WORSHIP_C2O(msg)
  231. JjcNewLogic.JjcNewLadderLogic_AddWorShipOK(msg)
  232. end
  233. -- 改变战区数据服记录的点赞数量
  234. function WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D(msg)
  235. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  236. local uuid, nAddNum = msg.uuidDes, msg.nAddNum
  237. local nNowWorShip
  238. for _, v in pairs(tLast3RankInfo) do
  239. if v.uuid == uuid then
  240. v.worshipCnt = v.worshipCnt + nAddNum
  241. nNowWorShip = v.worshipCnt + 1
  242. break
  243. end
  244. end
  245. if not nNowWorShip then
  246. print("[WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D] 获取不到对应的点赞数据")
  247. return
  248. end
  249. CommonDB.SetJjcLadderLast3RankInfo(tLast3RankInfo)
  250. local tMsgData = InnerMsg.lw.LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C
  251. tMsgData.uuidDes = uuid
  252. tMsgData.nNowWorShip = nNowWorShip
  253. InnerMsg.sendMsg(0, tMsgData)
  254. end
  255. -- 通知对应战区所属服务器更新最新的点赞数
  256. function WL_JJC_NEWLADDER_WORSHIP_UPDATE_D2C(msg)
  257. JjcNewLogic.JjcNewLadderLogic_UpdateWorShip(msg)
  258. end
  259. -- 请求天梯赛排行榜数据(中心->战区数据服)
  260. function WL_JJC_NEWLADDER_QUERY_RANK_C2D(msg)
  261. JjcNewLogic.JjcNewLadderLogic_GetRankInfo(msg)
  262. end
  263. -- 获取到天梯赛排行榜数据(中心->普通)
  264. function WL_JJC_NEWLADDER_QUERY_RANK_C2O(msg)
  265. JjcNewLogic.JjcNewLadderLogic_GetRankInfoOK(msg)
  266. end
  267. -- 查询是否能够战斗(中心->战区数据服)
  268. function WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2D(msg)
  269. JjcNewLogic.JjcNewLadderLogic_CheckCanFight(msg)
  270. end
  271. -- 查询是否能够战斗(中心->普通)
  272. function WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2O(msg)
  273. JjcNewLogic.JjcNewLadderLogic_CheckCanFightOK(msg)
  274. end
  275. -- 战斗结束(中心->战区数据服)
  276. function WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2D(msg)
  277. JjcNewLogic.JjcNewLadderLogic_FightEnd(msg)
  278. end
  279. -- 战斗结束(中心 -> 普通)
  280. function WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2O(msg)
  281. JjcNewLogic.JjcNewLadderLogic_FightEndOK(msg)
  282. end
  283. function WL_JJC_NEWLADDER_SEND_MAIL_C2O(msg)
  284. JjcNewLogic.JjcNewLadderLogic_SendFailMailOK(msg)
  285. end
  286. function WL_JJC_NEWLADDER_SEND_RANK_PRIZE_C2O(msg)
  287. JjcNewLogic.JjcNewLadderLogic_SendPrizeMail(msg)
  288. end
  289. function WL_JJC_NEWLADDER_QUERY_WORSHIP_C20(msg)
  290. JjcNewLogic.JjcNewLadderLogic_QueryWorship(msg)
  291. end
  292. function WL_JJC_NEWLADDER_QUERY_WORSHIP_C2D(msg)
  293. local tLast3RankInfo = CommonDB.GetJjcLadderLast3RankInfo()
  294. if nil ~= _G.next(tLast3RankInfo) then
  295. for _, v in ipairs(tLast3RankInfo) do
  296. if v.uuid == msg.uuid then
  297. v.worshipCnt = msg.nWorShip
  298. break
  299. end
  300. end
  301. CommonDB.SetJjcLadderLast3RankInfo(tLast3RankInfo)
  302. end
  303. end