MiddleConnect.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. -- 跨服鏈接和重连管理
  2. local msg_parse = _G.msg_inner_parse
  3. local Config = require("Config")
  4. local Log = require("common.Log")
  5. local CommonDB = require("common.CommonDB")
  6. local InnerMsg = require("core.InnerMsg")
  7. local MiddleManager = require("middle.MiddleManager")
  8. local MiddleHeartBeat = require("middle.MiddleHeartBeat")
  9. local Define = require("platform.Define")
  10. local Json = require("common.Json")
  11. local JjcLadderMiddle = require("jjcLadder.JjcLadderMiddle")
  12. local WarZoneConf = require("excel.WarZone") --- 战区配置
  13. local ChatHandler = require("chat.Handler")
  14. local MiddleCommonRank = require("middle.MiddleCommonRank")
  15. local BanLogic = require("scene.BanLogic")
  16. IS_MIDDLE_CONNECT = IS_MIDDLE_CONNECT or nil -- 是否連上跨服 收到WLhello才認為連上了
  17. local nServerOffSet = 810538 -- 配置中服务器ID偏移量
  18. YY_ACT_FLAG = nil
  19. -- 请求middleInfo
  20. local s2aParam = {}
  21. local function questMiddleInfo()
  22. s2aParam.sid = Config.SVR_INDEX
  23. s2aParam.api_cbMethod = "setMiddleInfo"
  24. _G.thread_http.send(Define.MIDDLE_INFO_URL, Json.Encode(s2aParam))
  25. end
  26. -- 获取战区最小和最大服务器ID
  27. function MiddleConnect_GetWarZoneServer(nSeverID)
  28. local tWarZoneConf = WarZoneConf.group
  29. if not tWarZoneConf then
  30. return 0, 0
  31. end
  32. for _, v in pairs(tWarZoneConf) do
  33. if v.nMinServerID <= nSeverID and v.nMaxServerID >= nSeverID then
  34. return v.nMinServerID, v.nMaxServerID
  35. end
  36. end
  37. return 0, 0
  38. end
  39. -- 获取战区服务器ID
  40. function MiddleConnect_ConfServerID2TrueServerID(nServerIDConf)
  41. return nServerIDConf + nServerOffSet - 1
  42. end
  43. -- 获取战区配置服务器ID
  44. function MiddleConnect_TrueServerID2ConfServerID(nServerID)
  45. return nServerID - nServerOffSet + 1
  46. end
  47. local function MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  48. local nConfigServerID = MiddleConnect_TrueServerID2ConfServerID(nSrcServerID)
  49. local nWarServerID = MiddleConnect_GetWarZoneServer(nConfigServerID)
  50. if 0 >= nWarServerID then
  51. print("[MiddleConnect_GetWarFirstServerFD] 获取不到对应的战区ID nSrcServerID = "..nSrcServerID
  52. .." nConfigServerID = "..nConfigServerID.." nWarServerID = "..nWarServerID)
  53. return
  54. end
  55. local nWarFD = MiddleManager.getFDBySvrIndex(nWarServerID)
  56. if not nWarFD then
  57. print("[MiddleConnect_GetWarFirstServerFD] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID
  58. .." nConfigServerID = "..nConfigServerID.." nWarServerID = "..nWarServerID)
  59. return
  60. end
  61. return nWarFD
  62. end
  63. function setMiddleInfo(ip, port, host)
  64. if _G.is_middle == true then return end
  65. local middleDBInfo = CommonDB.getMiddleInfo()
  66. if middleDBInfo.ip == ip and middleDBInfo.port == port and middleDBInfo.host == host then
  67. -- 沒變化
  68. return
  69. end
  70. local oldIp = middleDBInfo.ip
  71. local oldPort = middleDBInfo.port
  72. CommonDB.setMiddleInfo(ip, port, host)
  73. if oldIp == ip and oldPort == port then
  74. -- 只有host变了 不需要重連
  75. return
  76. else
  77. tryConnectMiddle(ip, port) -- try的時候會把之前的鏈接斷開
  78. end
  79. end
  80. function getMiddleInfo()
  81. --调试模式使用配置的IP
  82. if Config.IS_DEBUG then
  83. return Config.MIDDLE_IP, Config.MIDDLE_PORT, Config.MIDDLE_HOST
  84. end
  85. local middleDBInfo = CommonDB.getMiddleInfo()
  86. return middleDBInfo.ip, middleDBInfo.port, middleDBInfo.host
  87. end
  88. function initAfterStart()
  89. onTimer() -- 啟動拉取一下middleInfo
  90. MiddleCommonRank.MiddleCommonRank_InitAfterStart()
  91. end
  92. function onTimer()
  93. if _G.is_middle == true then return end
  94. -- 如果没有middleip 去找后台请求middleip 1分钟1次
  95. local ip, port = getMiddleInfo()
  96. if ip == nil then
  97. -- reyes todo get ip
  98. print("no middleInfo try to get")
  99. questMiddleInfo()
  100. return
  101. end
  102. -- 如果ip有了 但是一直没连上 1分钟重连1次
  103. if isConnect() ~= true then
  104. tryConnectMiddle(ip, port)
  105. return
  106. end
  107. -- 如果3分钟之内 没有收到middle的心跳包 并且底层还是连接中的状态 我们认为出故障了 这个时候重连一下middle 这是一个异常处理
  108. if MiddleHeartBeat.LAST_HEARTBEAT_TIME then
  109. local now = os.time()
  110. if now - MiddleHeartBeat.LAST_HEARTBEAT_TIME > 180 then
  111. stopConnectMiddle()
  112. end
  113. end
  114. end
  115. function autoResetMiddle()
  116. if _G.is_middle == true then return end
  117. -- 每周一凌晨2點 斷開鏈接 并且重新取一下php的跨服信息 重新連新跨服
  118. CommonDB.setMiddleInfo(nil, nil, nil)
  119. stopConnectMiddle()
  120. onTimer() -- 拉取一下middleInfo
  121. end
  122. function isConnect()
  123. -- 這個接口和IS_MIDDLE_CONNECT的區別是 這個表示底層鏈接連上了 但是不一定正確收到了middle會包 lua層業務判斷最好別用這個接口 盡量用IS_MIDDLE_CONNECT
  124. local ret = msg_parse.check_connect()
  125. if ret == true then
  126. return true
  127. end
  128. end
  129. function tryConnectMiddle(ip, port)
  130. print("try connect middle ", ip, port)
  131. Log.write(Log.LOGID_INNER_CLOSE, "tryConnectMiddle", ip, port)
  132. msg_parse.set_connect(ip, port)
  133. end
  134. function stopConnectMiddle()
  135. print("stop connect middle ")
  136. Log.write(Log.LOGID_INNER_CLOSE, "stopConnectMiddle")
  137. msg_parse.close_connect()
  138. IS_MIDDLE_CONNECT = nil
  139. MiddleHeartBeat.LAST_HEARTBEAT_TIME = nil
  140. MiddleHeartBeat.LAST_SEND_HB_TS = nil
  141. end
  142. function LW_HELLO(fd, msg)
  143. print("LW Hello fd = "..fd)
  144. --table.print_lua_table(msg)
  145. --local stackTrace = debug.traceback("", 2)
  146. --print("[LW_HELLO] 堆栈信息 "..stackTrace)
  147. -- Log.write(Log.LOGID_INNER_CLOSE, "LW_HELLO")
  148. Log.write(Log.LOGID_INNER_CLOSE, string.format("LW_HELLO, client: %s, fd: %s", msg.svrIndex, fd))
  149. MiddleManager.addLogicServer(fd, msg.svrIndex)
  150. local szMsgData = InnerMsg.wl.WL_HELLO
  151. --table.print_lua_table(szMsgData)
  152. szMsgData.nGetSvrID = msg.svrIndex
  153. szMsgData.nNowSvrID = Config.SVR_INDEX
  154. --table.print_lua_table(msg)
  155. --table.print_lua_table(szMsgData)
  156. InnerMsg.sendMsg(fd, szMsgData)
  157. msg = InnerMsg.wl.WL_HEARTBEAT
  158. InnerMsg.sendMsg(fd, msg)
  159. -- 同步其它信息
  160. -- JjcLadderMiddle.sendWLMobaiCnt(fd)
  161. end
  162. function WL_HELLO(fd, msg)
  163. print("WL hello fd = "..fd)
  164. Log.write(Log.LOGID_INNER_CLOSE, "WL_HELLO")
  165. if not IS_MIDDLE_CONNECT then
  166. print("middle server upup!!!---")
  167. IS_MIDDLE_CONNECT = true
  168. local openTime = CommonDB.getServerOpenTime()
  169. if openTime ~= 0 then
  170. -- local msg = InnerMsg.lw.LW_SET
  171. -- msg.openTime = openTime or 0
  172. -- msg.svrIndex = Config.SVR_INDEX
  173. -- InnerMsg.sendMsg(fd, msg)
  174. end
  175. BanLogic.NS_Get_BanData()
  176. end
  177. end
  178. function LW_SET(fd,msg)
  179. MiddleManager.setServerOpenDay(fd,msg.svrIndex,msg.openTime)
  180. end
  181. function LW_DISCONNECT(fd, msg)
  182. print("LW_DISCONNECT")
  183. MiddleManager.delLogicServer(fd)
  184. end
  185. --middle断线,C++层触发
  186. function WL_DISCONNECT(fd, msg)
  187. if IS_MIDDLE_CONNECT then
  188. IS_MIDDLE_CONNECT = nil
  189. MiddleHeartBeat.LAST_HEARTBEAT_TIME = nil
  190. MiddleHeartBeat.LAST_SEND_HB_TS = nil
  191. Log.write(Log.LOGID_INNER_CLOSE, "middle server disconnect!!!")
  192. print("middle server disconnect!!!---")
  193. end
  194. end
  195. -- 跨服聊天请求
  196. function LW_MIDDLE_CHAT(fd, msg)
  197. local tAllConnectFD = MiddleManager.MiddleManager_GetAllFD()
  198. if not _G.next(tAllConnectFD) then
  199. print("[LW_MIDDLE_CHAT] 不存在连接上的服务器")
  200. return
  201. end
  202. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT
  203. szMsgData.tChatMsg = msg.tChatMsg
  204. local nMsgType = szMsgData.tChatMsg.item.msgType
  205. if ChatHandler.CHAT_TYPE_MIDDLE == nMsgType then
  206. for _, nFD in pairs(tAllConnectFD) do
  207. InnerMsg.sendMsg(nFD, szMsgData)
  208. end
  209. print("[LW_MIDDLE_CHAT] 全服发送消息结束")
  210. elseif ChatHandler.CHAT_TYPE_WARZONE == nMsgType then
  211. local nSendServerID = msg.svrIndex
  212. local nConfServerID = nSendServerID - nServerOffSet + 1
  213. local nMinServerID, nMaxServerID = MiddleConnect_GetWarZoneServer(nConfServerID)
  214. if 0 >= nMinServerID or 0 >= nMaxServerID then
  215. print("[LW_MIDDLE_CHAT 获取不到配置 nSendServerID = "..nSendServerID.." nConfServerID = "..nConfServerID)
  216. return
  217. end
  218. local nServeL, nServerR = nMinServerID + nServerOffSet - 1, nMaxServerID + nServerOffSet - 1
  219. for i = nServeL, nServerR, 1 do
  220. local nFD = MiddleManager.getFDBySvrIndex(i)
  221. if nFD then
  222. InnerMsg.sendMsg(nFD, szMsgData)
  223. else
  224. print("[LW_MIDDLE_CHAT] 不存在对应的fd i = "..i)
  225. end
  226. end
  227. print("[LW_MIDDLE_CHAT] 战区发送消息结束")
  228. else
  229. print("[LW_MIDDLE_CHAT] 未处理的发送消息结束")
  230. end
  231. end
  232. -- 获取聊天英雄信息
  233. function LW_MIDDLE_CHAT_QUERY_HERO_DATA(fd, msg)
  234. local nDesServerID = msg.nDesServerID
  235. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  236. if not nDesFD then
  237. print("[LW_MIDDLE_CHAT_QUERY_HERO_DATA] 不存在对应的fd nDesServerID = "..nDesServerID)
  238. return
  239. end
  240. print("[LW_MIDDLE_CHAT_QUERY_HERO_DATA] nDesServerID = "..nDesServerID.." nDesFD = "..nDesFD)
  241. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT_QUERY_HERO_DATA
  242. szMsgData.nSrcServerID = msg.nSrcServerID
  243. szMsgData.nSrcUID = msg.nSrcUID
  244. szMsgData.nDesUID = msg.nDesUID
  245. szMsgData.nHeroIndex = msg.nHeroIndex
  246. szMsgData.nChatType = msg.nChatType
  247. InnerMsg.sendMsg(nDesFD, szMsgData)
  248. end
  249. function LW_MIDDLE_CHAT_GET_HERO_DATA(fd, msg)
  250. local nSrcServerID = msg.nSrcServerID
  251. local nSrcFD = MiddleManager.getFDBySvrIndex(nSrcServerID)
  252. if not nSrcFD then
  253. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] 不存在对应的fd nSrcServerID = "..nSrcServerID)
  254. return
  255. end
  256. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] nSrcServerID = "..nSrcServerID.." nSrcFD = "..nSrcFD)
  257. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT_GET_HERO_DATA
  258. szMsgData.nSrcUID = msg.nSrcUID
  259. szMsgData.tHeroData = msg.tHeroData
  260. InnerMsg.sendMsg(nSrcFD, szMsgData)
  261. end
  262. function LW_WARREPORT_GET_COMBATINFO(fd, msg)
  263. local nDesServerID = msg.nDesServerID
  264. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  265. --local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  266. if not nDesFD then
  267. print("[LW_WARREPORT_GET_COMBATINFO] 不存在对应的fd nDesServerID = "..nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  268. return
  269. end
  270. local tMsgData = InnerMsg.wl.WL_WARREPORT_GET_COMBATINFO
  271. tMsgData.nSrcUID = msg.nSrcUID
  272. tMsgData.type = msg.type
  273. tMsgData.id = msg.id
  274. tMsgData.nSrcServerID = msg.nSrcServerID
  275. tMsgData.mode = msg.mode
  276. InnerMsg.sendMsg(nDesFD, tMsgData)
  277. end
  278. function LW_WARREPORT_SEND_COMBATINFO(fd, msg)
  279. local nSrcServerID = msg.nSrcServerID
  280. local nSrcFD = MiddleManager.getFDBySvrIndex(nSrcServerID)
  281. if not nSrcFD then
  282. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] 不存在对应的fd nSrcServerID = "..nSrcServerID)
  283. return
  284. end
  285. local tMsgData = InnerMsg.wl.WL_WARREPORT_SEND_COMBATINFO
  286. tMsgData.nSrcUID = msg.nSrcUID
  287. tMsgData.combatInfo = msg.combatInfo
  288. tMsgData.mode = msg.mode
  289. InnerMsg.sendMsg(nSrcFD, tMsgData)
  290. end
  291. -------------------- 跨服玩家头像数据开始 --------------------
  292. function LW_CHAT_PLAYER_INFO(fd, msg)
  293. local nDesFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  294. if not nDesFD then
  295. print("[LW_CHAT_PLAYER_INFO] 不存在对应的fd nDesServerID = "..msg.nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  296. return
  297. end
  298. local tMsgData = InnerMsg.wl.WL_CHAT_PLAYER_INFO
  299. tMsgData.nSrcUID = msg.nSrcUID
  300. tMsgData.nDesUID = msg.nDesUID
  301. tMsgData.nSrcServerID = msg.nSrcServerID
  302. InnerMsg.sendMsg(nDesFD, tMsgData)
  303. end
  304. function LW_CHAT_PLAYER_INFO_SEND(fd, msg)
  305. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  306. if not nSrcFD then
  307. print("[LW_CHAT_PLAYER_INFO_SEND] 不存在对应的fd nSrcServerID = "..msg.nSrcServerID)
  308. return
  309. end
  310. local tMsgData = InnerMsg.wl.WL_CHAT_PLAYER_INFO_SEND
  311. tMsgData.nSrcUID = msg.nSrcUID
  312. tMsgData.tData = msg.tData
  313. InnerMsg.sendMsg(nSrcFD, tMsgData)
  314. end
  315. -------------------- 跨服玩家头像数据结束 --------------------
  316. -------------------- 跨服请求战斗数据开始 --------------------
  317. function LW_COMBAT_GETINFO(fd, msg)
  318. local nDesFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  319. if not nDesFD then
  320. print("[LW_COMBAT_QIECUO_GETINFO] 不存在对应的fd nDesServerID = "..msg.nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  321. return
  322. end
  323. print("[LW_COMBAT_GETINFO] 收到")
  324. local tMsgData = InnerMsg.wl.WL_COMBAT_GETINFO
  325. tMsgData.nSrcUID = msg.nSrcUID
  326. tMsgData.nDesUID = msg.nDesUID
  327. tMsgData.nSrcServerID = msg.nSrcServerID
  328. tMsgData.nCombatType = msg.nCombatType
  329. InnerMsg.sendMsg(nDesFD, tMsgData)
  330. print("[LW_COMBAT_GETINFO] 发送 WL_COMBAT_QIECUO_GETINFO")
  331. end
  332. function LW_COMBAT_GETINFO_SEND(fd, msg)
  333. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  334. if not nSrcFD then
  335. print("[LW_COMBAT_GETINFO_SEND] 不存在对应的fd nSrcServerID = "..msg.nSrcServerID)
  336. return
  337. end
  338. print("[LW_COMBAT_GETINFO_SEND] 收到")
  339. local tMsgData = InnerMsg.wl.WL_COMBAT_GETINFO_SEND
  340. tMsgData.nResult = msg.nResult
  341. tMsgData.nSrcUID = msg.nSrcUID
  342. tMsgData.tObjList = msg.tObjList
  343. tMsgData.tHelpList = msg.tHelpList
  344. tMsgData.tRoleBase = msg.tRoleBase
  345. tMsgData.formation = msg.formation
  346. tMsgData.tJiBan = msg.tJiBan
  347. InnerMsg.sendMsg(nSrcFD, tMsgData)
  348. print("[LW_COMBAT_GETINFO_SEND] 发送 WL_COMBAT_GETINFO_SEND")
  349. end
  350. -------------------- 跨服请求战斗数据结束 --------------------
  351. -------------------- 天梯赛开始 ---------------------------
  352. -- 请求参加天梯赛(普通->中心)
  353. function LW_JJC_NEWLADDER_JOINLADDER_O2C(fd, msg)
  354. local nSrcServerID = msg.nSrcServerID
  355. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  356. if not nWarFD then
  357. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  358. return
  359. end
  360. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛")
  361. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2D
  362. tMsgData.uuid = msg.uuid
  363. tMsgData.name = msg.name
  364. tMsgData.head = msg.head
  365. tMsgData.headFrame = msg.headFrame
  366. tMsgData.nSrcServerID = msg.nSrcServerID
  367. tMsgData.szServerName = msg.szServerName
  368. InnerMsg.sendMsg(nWarFD, tMsgData)
  369. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛, 发送到对应的战区数据服成功")
  370. end
  371. -- 请求参加天梯赛(数据->中心)
  372. function LW_JJC_NEWLADDER_JOINLADDER_D2C(fd, msg)
  373. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  374. if not nFd then
  375. print("[LW_JJC_NEWLADDER_JOINLADDER_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  376. return
  377. end
  378. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2O
  379. tMsgData.uuid = msg.uuid
  380. tMsgData.nRank = msg.nRank
  381. tMsgData.tEnemy = msg.tEnemy
  382. InnerMsg.sendMsg(nFd, tMsgData)
  383. end
  384. -- 请求刷新对战列表(普通->中心)
  385. function LW_JJC_NEWLADDER_REFRESH_O2C(msg)
  386. local nSrcServerID = msg.nSrcServerID
  387. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  388. if not nWarFD then
  389. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  390. return
  391. end
  392. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表")
  393. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2D
  394. tMsgData.uuid = msg.uuid
  395. tMsgData.nSrcServerID = msg.nSrcServerID
  396. InnerMsg.sendMsg(nWarFD, tMsgData)
  397. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表, 发送到对应的战区数据服成功")
  398. end
  399. -- 请求刷新对战列表(数据->中心)
  400. function LW_JJC_NEWLADDER_REFRESH_D2C(msg)
  401. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  402. if not nFd then
  403. print("[LW_JJC_NEWLADDER_REFRESH_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  404. return
  405. end
  406. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2O
  407. tMsgData.uuid = msg.uuid
  408. tMsgData.tEnemy = msg.tEnemy
  409. InnerMsg.sendMsg(nFd, tMsgData)
  410. end
  411. -- 请求上一轮排名前三数据(普通->中心)
  412. function LW_JJC_NEWLADDER_LAST3RANK_O2C(msg)
  413. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  414. if not nWarFD then
  415. print("[LW_JJC_NEWLADDER_LAST3RANK_O2C] 获取不到对应的战区的FD nSrcServerID = "..msg.nSrcServerID)
  416. return
  417. end
  418. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2D
  419. tMsgData.nSrcServerID = msg.nSrcServerID
  420. InnerMsg.sendMsg(nWarFD, tMsgData)
  421. end
  422. -- 请求上一轮排名前三数据(数据->中心)
  423. function LW_JJC_NEWLADDER_LAST3RANK_D2O(msg)
  424. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  425. if not nFd then
  426. print("[LW_JJC_NEWLADDER_LAST3RANK_D2O] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  427. return
  428. end
  429. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2O
  430. tMsgData.nExist = msg.nExist
  431. tMsgData.tLastRankInfo = msg.tLastRankInfo
  432. InnerMsg.sendMsg(nFd, tMsgData)
  433. end
  434. -- 进行点赞(普通->中心)
  435. function LW_JJC_NEWLADDER_SEND_WORSHIP_O2C(msg)
  436. local nDesServerID = msg.nDesServerID
  437. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  438. if not nDesFD then
  439. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_O2C] 获取不到需要传递的服务器FD nSrcServerID = "..msg.nSrcServerID.." nDesServerID = "..nDesServerID)
  440. return
  441. end
  442. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2D
  443. tMsgData.uuidSrc = msg.uuidSrc
  444. tMsgData.uuidDes = msg.uuidDes
  445. tMsgData.nSrcServerID = msg.nSrcServerID
  446. InnerMsg.sendMsg(nDesFD, tMsgData)
  447. end
  448. -- 进行点赞(数据(被点赞玩家所在服)->中心)
  449. function LW_JJC_NEWLADDER_SEND_WORSHIP_D2C(msg)
  450. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  451. if not nSrcFD then
  452. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 获取不到回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  453. return
  454. end
  455. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2O
  456. tMsgData.uuidSrc = msg.uuidSrc
  457. tMsgData.uuidDes = msg.uuidDes
  458. tMsgData.nNowWorShip = msg.nNowWorShip
  459. -- 回复对应的服务器
  460. InnerMsg.sendMsg(nSrcFD, tMsgData)
  461. -- 发给战区数据服,更新点赞数
  462. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  463. if nWarFD then
  464. tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D
  465. tMsgData.uuidDes = msg.uuidDes
  466. tMsgData.nAddNum = 1
  467. InnerMsg.sendMsg(nWarFD, tMsgData)
  468. else
  469. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 不存在对应的战区fd")
  470. end
  471. end
  472. -- 通知战区下属服务器最新的点赞数
  473. function LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C(msg)
  474. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_UPDATE_D2C
  475. tMsgData.uuidDes = msg.uuidDes
  476. tMsgData.nNowWorShip = msg.nNowWorShip
  477. local nConfigServerID = MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
  478. local nMinServerID, nMaxServerID = MiddleConnect_GetWarZoneServer(nConfigServerID)
  479. for i = nMinServerID, nMaxServerID, 1 do
  480. local nTrueServerID = MiddleConnect_ConfServerID2TrueServerID(i)
  481. local nFD = MiddleManager.getFDBySvrIndex(nTrueServerID)
  482. if nFD then
  483. InnerMsg.sendMsg(nFD, tMsgData)
  484. else
  485. print("[LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C] 没有获取到对应的 nTrueServerID = "..nTrueServerID)
  486. end
  487. end
  488. end
  489. -- 请求天梯赛排行榜数据(普通->中心)
  490. function LW_JJC_NEWLADDER_QUERY_RANK_O2C(msg)
  491. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  492. if not nWarFD then
  493. print("[LW_JJC_NEWLADDER_QUERY_RANK_O2C] 获取不到对应的战区的FD")
  494. return
  495. end
  496. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2D
  497. tMsgData.nSrcServerID = msg.nSrcServerID
  498. InnerMsg.sendMsg(nWarFD, tMsgData)
  499. end
  500. -- 回复天梯赛排行榜数据(中心->数据服)
  501. function LW_JJC_NEWLADDER_QUERY_RANK_D2C(msg)
  502. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  503. if not nFD then
  504. print("[LW_JJC_NEWLADDER_QUERY_RANK_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  505. return
  506. end
  507. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2O
  508. tMsgData.nIsEnd = msg.nIsEnd
  509. tMsgData.nFirst = msg.nFirst
  510. tMsgData.tRankInfo = msg.tRankInfo
  511. InnerMsg.sendMsg(nFD, tMsgData)
  512. end
  513. -- 查询是否能够战斗(普通->中心)
  514. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C(msg)
  515. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  516. if not nWarFD then
  517. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C] 获取不到对应的战区的FD")
  518. return
  519. end
  520. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2D
  521. tMsgData.uuid = msg.uuid
  522. tMsgData.uuidDes = msg.uuidDes
  523. tMsgData.nSrcServerID = msg.nSrcServerID
  524. InnerMsg.sendMsg(nWarFD, tMsgData)
  525. end
  526. -- 查询是否能够战斗(数据服->中心)
  527. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C(msg)
  528. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  529. if not nFD then
  530. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  531. return
  532. end
  533. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2O
  534. tMsgData.uuid = msg.uuid
  535. tMsgData.uuidDes = msg.uuidDes
  536. tMsgData.nIsFight = msg.nIsFight
  537. InnerMsg.sendMsg(nFD, tMsgData)
  538. end
  539. -- 战斗结束(普通->中心)
  540. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C(msg)
  541. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  542. if not nWarFD then
  543. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C] 获取不到对应的战区的FD")
  544. return
  545. end
  546. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2D
  547. tMsgData.uuid = msg.uuid
  548. tMsgData.uuidDes = msg.uuidDes
  549. tMsgData.nSrcServerID = msg.nSrcServerID
  550. tMsgData.nResult = msg.nResult
  551. tMsgData.tEnemyUid = msg.tEnemyUid
  552. InnerMsg.sendMsg(nWarFD, tMsgData)
  553. end
  554. -- 战斗结束(数据服->中心)
  555. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C(msg)
  556. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  557. if not nFD then
  558. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  559. return
  560. end
  561. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2O
  562. tMsgData.uuid = msg.uuid
  563. tMsgData.nNewRank = msg.nNewRank
  564. tMsgData.nNewPoint = msg.nNewPoint
  565. tMsgData.uuidDes = msg.uuidDes
  566. tMsgData.tNewOneEnemy = msg.tNewOneEnemy
  567. tMsgData.tOldEnemyData = msg.tOldEnemyData
  568. InnerMsg.sendMsg(nFD, tMsgData)
  569. end
  570. --发送失败邮件
  571. function LW_JJC_NEWLADDER_SEND_MAIL_D2C(msg)
  572. local nFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  573. if not nFD then
  574. print("[LW_JJC_NEWLADDER_SEND_MAIL_D2C] 找不到请求服务器对应的FD nDesServerID = "..msg.nDesServerID)
  575. return
  576. end
  577. local tMsgData = InnerMsg.lw.WL_JJC_NEWLADDER_SEND_MAIL_C2O
  578. tMsgData.uuidDes = msg.uuidDes
  579. tMsgData.szServerName = msg.szServerName
  580. tMsgData.szName = msg.szName
  581. tMsgData.nNewRank = msg.nNewRank
  582. InnerMsg.sendMsg(nFD, tMsgData)
  583. end
  584. function LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C(msg)
  585. local nFD = MiddleManager.getFDBySvrIndex(msg.nServerID)
  586. if not nFD then
  587. print("[LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C] 找不到请求服务器对应的FD nServerID = "..msg.nServerID)
  588. return
  589. end
  590. local tMsgData = InnerMsg.lw.WL_JJC_NEWLADDER_SEND_RANK_PRIZE_C2O
  591. tMsgData.uuid = msg.uuid
  592. tMsgData.nRank = msg.nRank
  593. InnerMsg.sendMsg(nFD, tMsgData)
  594. end
  595. -------------------- 天梯赛结束 ---------------------------