MiddleConnect.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. MiddleManager.addLogicServer(fd, msg.svrIndex)
  149. local szMsgData = InnerMsg.wl.WL_HELLO
  150. --table.print_lua_table(szMsgData)
  151. szMsgData.nGetSvrID = msg.svrIndex
  152. szMsgData.nNowSvrID = Config.SVR_INDEX
  153. --table.print_lua_table(msg)
  154. --table.print_lua_table(szMsgData)
  155. InnerMsg.sendMsg(fd, szMsgData)
  156. msg = InnerMsg.wl.WL_HEARTBEAT
  157. InnerMsg.sendMsg(fd, msg)
  158. -- 同步其它信息
  159. -- JjcLadderMiddle.sendWLMobaiCnt(fd)
  160. end
  161. function WL_HELLO(fd, msg)
  162. print("WL hello fd = "..fd)
  163. Log.write(Log.LOGID_INNER_CLOSE, "WL_HELLO")
  164. if not IS_MIDDLE_CONNECT then
  165. print("middle server upup!!!---")
  166. IS_MIDDLE_CONNECT = true
  167. local openTime = CommonDB.getServerOpenTime()
  168. if openTime ~= 0 then
  169. -- local msg = InnerMsg.lw.LW_SET
  170. -- msg.openTime = openTime or 0
  171. -- msg.svrIndex = Config.SVR_INDEX
  172. -- InnerMsg.sendMsg(fd, msg)
  173. end
  174. -- BanLogic.NS_Get_BanData()
  175. end
  176. end
  177. function LW_SET(fd,msg)
  178. MiddleManager.setServerOpenDay(fd,msg.svrIndex,msg.openTime)
  179. end
  180. function LW_DISCONNECT(fd, msg)
  181. print("LW_DISCONNECT")
  182. MiddleManager.delLogicServer(fd)
  183. end
  184. --middle断线,C++层触发
  185. function WL_DISCONNECT(fd, msg)
  186. if IS_MIDDLE_CONNECT then
  187. IS_MIDDLE_CONNECT = nil
  188. MiddleHeartBeat.LAST_HEARTBEAT_TIME = nil
  189. MiddleHeartBeat.LAST_SEND_HB_TS = nil
  190. Log.write(Log.LOGID_INNER_CLOSE, "middle server disconnect!!!")
  191. print("middle server disconnect!!!---")
  192. end
  193. end
  194. -- 跨服聊天请求
  195. function LW_MIDDLE_CHAT(fd, msg)
  196. local tAllConnectFD = MiddleManager.MiddleManager_GetAllFD()
  197. if not _G.next(tAllConnectFD) then
  198. print("[LW_MIDDLE_CHAT] 不存在连接上的服务器")
  199. return
  200. end
  201. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT
  202. szMsgData.tChatMsg = msg.tChatMsg
  203. local nMsgType = szMsgData.tChatMsg.item.msgType
  204. if ChatHandler.CHAT_TYPE_MIDDLE == nMsgType then
  205. for _, nFD in pairs(tAllConnectFD) do
  206. InnerMsg.sendMsg(nFD, szMsgData)
  207. end
  208. print("[LW_MIDDLE_CHAT] 全服发送消息结束")
  209. elseif ChatHandler.CHAT_TYPE_WARZONE == nMsgType then
  210. local nSendServerID = msg.svrIndex
  211. local nConfServerID = nSendServerID - nServerOffSet + 1
  212. local nMinServerID, nMaxServerID = MiddleConnect_GetWarZoneServer(nConfServerID)
  213. if 0 >= nMinServerID or 0 >= nMaxServerID then
  214. print("[LW_MIDDLE_CHAT 获取不到配置 nSendServerID = "..nSendServerID.." nConfServerID = "..nConfServerID)
  215. return
  216. end
  217. local nServeL, nServerR = nMinServerID + nServerOffSet - 1, nMaxServerID + nServerOffSet - 1
  218. for i = nServeL, nServerR, 1 do
  219. local nFD = MiddleManager.getFDBySvrIndex(i)
  220. if nFD then
  221. InnerMsg.sendMsg(nFD, szMsgData)
  222. else
  223. print("[LW_MIDDLE_CHAT] 不存在对应的fd i = "..i)
  224. end
  225. end
  226. print("[LW_MIDDLE_CHAT] 战区发送消息结束")
  227. else
  228. print("[LW_MIDDLE_CHAT] 未处理的发送消息结束")
  229. end
  230. end
  231. -- 获取聊天英雄信息
  232. function LW_MIDDLE_CHAT_QUERY_HERO_DATA(fd, msg)
  233. local nDesServerID = msg.nDesServerID
  234. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  235. if not nDesFD then
  236. print("[LW_MIDDLE_CHAT_QUERY_HERO_DATA] 不存在对应的fd nDesServerID = "..nDesServerID)
  237. return
  238. end
  239. print("[LW_MIDDLE_CHAT_QUERY_HERO_DATA] nDesServerID = "..nDesServerID.." nDesFD = "..nDesFD)
  240. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT_QUERY_HERO_DATA
  241. szMsgData.nSrcServerID = msg.nSrcServerID
  242. szMsgData.nSrcUID = msg.nSrcUID
  243. szMsgData.nDesUID = msg.nDesUID
  244. szMsgData.nHeroIndex = msg.nHeroIndex
  245. szMsgData.nChatType = msg.nChatType
  246. InnerMsg.sendMsg(nDesFD, szMsgData)
  247. end
  248. function LW_MIDDLE_CHAT_GET_HERO_DATA(fd, msg)
  249. local nSrcServerID = msg.nSrcServerID
  250. local nSrcFD = MiddleManager.getFDBySvrIndex(nSrcServerID)
  251. if not nSrcFD then
  252. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] 不存在对应的fd nSrcServerID = "..nSrcServerID)
  253. return
  254. end
  255. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] nSrcServerID = "..nSrcServerID.." nSrcFD = "..nSrcFD)
  256. local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT_GET_HERO_DATA
  257. szMsgData.nSrcUID = msg.nSrcUID
  258. szMsgData.tHeroData = msg.tHeroData
  259. InnerMsg.sendMsg(nSrcFD, szMsgData)
  260. end
  261. function LW_WARREPORT_GET_COMBATINFO(fd, msg)
  262. local nDesServerID = msg.nDesServerID
  263. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  264. --local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  265. if not nDesFD then
  266. print("[LW_WARREPORT_GET_COMBATINFO] 不存在对应的fd nDesServerID = "..nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  267. return
  268. end
  269. local tMsgData = InnerMsg.wl.WL_WARREPORT_GET_COMBATINFO
  270. tMsgData.nSrcUID = msg.nSrcUID
  271. tMsgData.type = msg.type
  272. tMsgData.id = msg.id
  273. tMsgData.nSrcServerID = msg.nSrcServerID
  274. tMsgData.mode = msg.mode
  275. InnerMsg.sendMsg(nDesFD, tMsgData)
  276. end
  277. function LW_WARREPORT_SEND_COMBATINFO(fd, msg)
  278. local nSrcServerID = msg.nSrcServerID
  279. local nSrcFD = MiddleManager.getFDBySvrIndex(nSrcServerID)
  280. if not nSrcFD then
  281. print("[LW_MIDDLE_CHAT_GET_HERO_DATA] 不存在对应的fd nSrcServerID = "..nSrcServerID)
  282. return
  283. end
  284. local tMsgData = InnerMsg.wl.WL_WARREPORT_SEND_COMBATINFO
  285. tMsgData.nSrcUID = msg.nSrcUID
  286. tMsgData.combatInfo = msg.combatInfo
  287. tMsgData.mode = msg.mode
  288. InnerMsg.sendMsg(nSrcFD, tMsgData)
  289. end
  290. -------------------- 跨服玩家头像数据开始 --------------------
  291. function LW_CHAT_PLAYER_INFO(fd, msg)
  292. local nDesFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  293. if not nDesFD then
  294. print("[LW_CHAT_PLAYER_INFO] 不存在对应的fd nDesServerID = "..msg.nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  295. return
  296. end
  297. local tMsgData = InnerMsg.wl.WL_CHAT_PLAYER_INFO
  298. tMsgData.nSrcUID = msg.nSrcUID
  299. tMsgData.nDesUID = msg.nDesUID
  300. tMsgData.nSrcServerID = msg.nSrcServerID
  301. InnerMsg.sendMsg(nDesFD, tMsgData)
  302. end
  303. function LW_CHAT_PLAYER_INFO_SEND(fd, msg)
  304. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  305. if not nSrcFD then
  306. print("[LW_CHAT_PLAYER_INFO_SEND] 不存在对应的fd nSrcServerID = "..msg.nSrcServerID)
  307. return
  308. end
  309. local tMsgData = InnerMsg.wl.WL_CHAT_PLAYER_INFO_SEND
  310. tMsgData.nSrcUID = msg.nSrcUID
  311. tMsgData.tData = msg.tData
  312. InnerMsg.sendMsg(nSrcFD, tMsgData)
  313. end
  314. -------------------- 跨服玩家头像数据结束 --------------------
  315. -------------------- 跨服请求战斗数据开始 --------------------
  316. function LW_COMBAT_GETINFO(fd, msg)
  317. local nDesFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  318. if not nDesFD then
  319. print("[LW_COMBAT_QIECUO_GETINFO] 不存在对应的fd nDesServerID = "..msg.nDesServerID.." nSrcServerID = "..msg.nSrcServerID)
  320. return
  321. end
  322. print("[LW_COMBAT_GETINFO] 收到")
  323. local tMsgData = InnerMsg.wl.WL_COMBAT_GETINFO
  324. tMsgData.nSrcUID = msg.nSrcUID
  325. tMsgData.nDesUID = msg.nDesUID
  326. tMsgData.nSrcServerID = msg.nSrcServerID
  327. tMsgData.nCombatType = msg.nCombatType
  328. InnerMsg.sendMsg(nDesFD, tMsgData)
  329. print("[LW_COMBAT_GETINFO] 发送 WL_COMBAT_QIECUO_GETINFO")
  330. end
  331. function LW_COMBAT_GETINFO_SEND(fd, msg)
  332. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  333. if not nSrcFD then
  334. print("[LW_COMBAT_GETINFO_SEND] 不存在对应的fd nSrcServerID = "..msg.nSrcServerID)
  335. return
  336. end
  337. print("[LW_COMBAT_GETINFO_SEND] 收到")
  338. local tMsgData = InnerMsg.wl.WL_COMBAT_GETINFO_SEND
  339. tMsgData.nResult = msg.nResult
  340. tMsgData.nSrcUID = msg.nSrcUID
  341. tMsgData.tObjList = msg.tObjList
  342. tMsgData.tHelpList = msg.tHelpList
  343. tMsgData.tRoleBase = msg.tRoleBase
  344. tMsgData.formation = msg.formation
  345. tMsgData.tJiBan = msg.tJiBan
  346. InnerMsg.sendMsg(nSrcFD, tMsgData)
  347. print("[LW_COMBAT_GETINFO_SEND] 发送 WL_COMBAT_GETINFO_SEND")
  348. end
  349. -------------------- 跨服请求战斗数据结束 --------------------
  350. -------------------- 天梯赛开始 ---------------------------
  351. -- 请求参加天梯赛(普通->中心)
  352. function LW_JJC_NEWLADDER_JOINLADDER_O2C(fd, msg)
  353. local nSrcServerID = msg.nSrcServerID
  354. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  355. if not nWarFD then
  356. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  357. return
  358. end
  359. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛")
  360. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2D
  361. tMsgData.uuid = msg.uuid
  362. tMsgData.name = msg.name
  363. tMsgData.head = msg.head
  364. tMsgData.headFrame = msg.headFrame
  365. tMsgData.nSrcServerID = msg.nSrcServerID
  366. tMsgData.szServerName = msg.szServerName
  367. InnerMsg.sendMsg(nWarFD, tMsgData)
  368. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛, 发送到对应的战区数据服成功")
  369. end
  370. -- 请求参加天梯赛(数据->中心)
  371. function LW_JJC_NEWLADDER_JOINLADDER_D2C(fd, msg)
  372. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  373. if not nFd then
  374. print("[LW_JJC_NEWLADDER_JOINLADDER_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  375. return
  376. end
  377. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2O
  378. tMsgData.uuid = msg.uuid
  379. tMsgData.nRank = msg.nRank
  380. tMsgData.tEnemy = msg.tEnemy
  381. InnerMsg.sendMsg(nFd, tMsgData)
  382. end
  383. -- 请求刷新对战列表(普通->中心)
  384. function LW_JJC_NEWLADDER_REFRESH_O2C(msg)
  385. local nSrcServerID = msg.nSrcServerID
  386. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  387. if not nWarFD then
  388. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  389. return
  390. end
  391. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表")
  392. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2D
  393. tMsgData.uuid = msg.uuid
  394. tMsgData.nSrcServerID = msg.nSrcServerID
  395. InnerMsg.sendMsg(nWarFD, tMsgData)
  396. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表, 发送到对应的战区数据服成功")
  397. end
  398. -- 请求刷新对战列表(数据->中心)
  399. function LW_JJC_NEWLADDER_REFRESH_D2C(msg)
  400. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  401. if not nFd then
  402. print("[LW_JJC_NEWLADDER_REFRESH_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  403. return
  404. end
  405. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2O
  406. tMsgData.uuid = msg.uuid
  407. tMsgData.tEnemy = msg.tEnemy
  408. InnerMsg.sendMsg(nFd, tMsgData)
  409. end
  410. -- 请求上一轮排名前三数据(普通->中心)
  411. function LW_JJC_NEWLADDER_LAST3RANK_O2C(msg)
  412. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  413. if not nWarFD then
  414. print("[LW_JJC_NEWLADDER_LAST3RANK_O2C] 获取不到对应的战区的FD nSrcServerID = "..msg.nSrcServerID)
  415. return
  416. end
  417. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2D
  418. tMsgData.nSrcServerID = msg.nSrcServerID
  419. InnerMsg.sendMsg(nWarFD, tMsgData)
  420. end
  421. -- 请求上一轮排名前三数据(数据->中心)
  422. function LW_JJC_NEWLADDER_LAST3RANK_D2O(msg)
  423. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  424. if not nFd then
  425. print("[LW_JJC_NEWLADDER_LAST3RANK_D2O] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  426. return
  427. end
  428. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2O
  429. tMsgData.nExist = msg.nExist
  430. tMsgData.tLastRankInfo = msg.tLastRankInfo
  431. InnerMsg.sendMsg(nFd, tMsgData)
  432. end
  433. -- 进行点赞(普通->中心)
  434. function LW_JJC_NEWLADDER_SEND_WORSHIP_O2C(msg)
  435. local nDesServerID = msg.nDesServerID
  436. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  437. if not nDesFD then
  438. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_O2C] 获取不到需要传递的服务器FD nSrcServerID = "..msg.nSrcServerID.." nDesServerID = "..nDesServerID)
  439. return
  440. end
  441. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2D
  442. tMsgData.uuidSrc = msg.uuidSrc
  443. tMsgData.uuidDes = msg.uuidDes
  444. tMsgData.nSrcServerID = msg.nSrcServerID
  445. InnerMsg.sendMsg(nDesFD, tMsgData)
  446. end
  447. -- 进行点赞(数据(被点赞玩家所在服)->中心)
  448. function LW_JJC_NEWLADDER_SEND_WORSHIP_D2C(msg)
  449. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  450. if not nSrcFD then
  451. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 获取不到回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  452. return
  453. end
  454. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2O
  455. tMsgData.uuidSrc = msg.uuidSrc
  456. tMsgData.uuidDes = msg.uuidDes
  457. tMsgData.nNowWorShip = msg.nNowWorShip
  458. -- 回复对应的服务器
  459. InnerMsg.sendMsg(nSrcFD, tMsgData)
  460. -- 发给战区数据服,更新点赞数
  461. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  462. if nWarFD then
  463. tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D
  464. tMsgData.uuidDes = msg.uuidDes
  465. tMsgData.nAddNum = 1
  466. InnerMsg.sendMsg(nWarFD, tMsgData)
  467. else
  468. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 不存在对应的战区fd")
  469. end
  470. end
  471. -- 通知战区下属服务器最新的点赞数
  472. function LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C(msg)
  473. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_UPDATE_D2C
  474. tMsgData.uuidDes = msg.uuidDes
  475. tMsgData.nNowWorShip = msg.nNowWorShip
  476. local nConfigServerID = MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
  477. local nMinServerID, nMaxServerID = MiddleConnect_GetWarZoneServer(nConfigServerID)
  478. for i = nMinServerID, nMaxServerID, 1 do
  479. local nTrueServerID = MiddleConnect_ConfServerID2TrueServerID(i)
  480. local nFD = MiddleManager.getFDBySvrIndex(nTrueServerID)
  481. if nFD then
  482. InnerMsg.sendMsg(nFD, tMsgData)
  483. else
  484. print("[LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C] 没有获取到对应的 nTrueServerID = "..nTrueServerID)
  485. end
  486. end
  487. end
  488. -- 请求天梯赛排行榜数据(普通->中心)
  489. function LW_JJC_NEWLADDER_QUERY_RANK_O2C(msg)
  490. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  491. if not nWarFD then
  492. print("[LW_JJC_NEWLADDER_QUERY_RANK_O2C] 获取不到对应的战区的FD")
  493. return
  494. end
  495. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2D
  496. tMsgData.nSrcServerID = msg.nSrcServerID
  497. InnerMsg.sendMsg(nWarFD, tMsgData)
  498. end
  499. -- 回复天梯赛排行榜数据(中心->数据服)
  500. function LW_JJC_NEWLADDER_QUERY_RANK_D2C(msg)
  501. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  502. if not nFD then
  503. print("[LW_JJC_NEWLADDER_QUERY_RANK_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  504. return
  505. end
  506. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2O
  507. tMsgData.nIsEnd = msg.nIsEnd
  508. tMsgData.nFirst = msg.nFirst
  509. tMsgData.tRankInfo = msg.tRankInfo
  510. InnerMsg.sendMsg(nFD, tMsgData)
  511. end
  512. -- 查询是否能够战斗(普通->中心)
  513. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C(msg)
  514. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  515. if not nWarFD then
  516. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C] 获取不到对应的战区的FD")
  517. return
  518. end
  519. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2D
  520. tMsgData.uuid = msg.uuid
  521. tMsgData.uuidDes = msg.uuidDes
  522. tMsgData.nSrcServerID = msg.nSrcServerID
  523. InnerMsg.sendMsg(nWarFD, tMsgData)
  524. end
  525. -- 查询是否能够战斗(数据服->中心)
  526. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C(msg)
  527. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  528. if not nFD then
  529. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  530. return
  531. end
  532. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2O
  533. tMsgData.uuid = msg.uuid
  534. tMsgData.uuidDes = msg.uuidDes
  535. tMsgData.nIsFight = msg.nIsFight
  536. InnerMsg.sendMsg(nFD, tMsgData)
  537. end
  538. -- 战斗结束(普通->中心)
  539. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C(msg)
  540. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  541. if not nWarFD then
  542. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C] 获取不到对应的战区的FD")
  543. return
  544. end
  545. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2D
  546. tMsgData.uuid = msg.uuid
  547. tMsgData.uuidDes = msg.uuidDes
  548. tMsgData.nSrcServerID = msg.nSrcServerID
  549. tMsgData.nResult = msg.nResult
  550. tMsgData.tEnemyUid = msg.tEnemyUid
  551. InnerMsg.sendMsg(nWarFD, tMsgData)
  552. end
  553. -- 战斗结束(数据服->中心)
  554. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C(msg)
  555. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  556. if not nFD then
  557. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  558. return
  559. end
  560. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2O
  561. tMsgData.uuid = msg.uuid
  562. tMsgData.nNewRank = msg.nNewRank
  563. tMsgData.nNewPoint = msg.nNewPoint
  564. tMsgData.uuidDes = msg.uuidDes
  565. tMsgData.tNewOneEnemy = msg.tNewOneEnemy
  566. tMsgData.tOldEnemyData = msg.tOldEnemyData
  567. InnerMsg.sendMsg(nFD, tMsgData)
  568. end
  569. --发送失败邮件
  570. function LW_JJC_NEWLADDER_SEND_MAIL_D2C(msg)
  571. local nFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  572. if not nFD then
  573. print("[LW_JJC_NEWLADDER_SEND_MAIL_D2C] 找不到请求服务器对应的FD nDesServerID = "..msg.nDesServerID)
  574. return
  575. end
  576. local tMsgData = InnerMsg.lw.WL_JJC_NEWLADDER_SEND_MAIL_C2O
  577. tMsgData.uuidDes = msg.uuidDes
  578. tMsgData.szServerName = msg.szServerName
  579. tMsgData.szName = msg.szName
  580. tMsgData.nNewRank = msg.nNewRank
  581. InnerMsg.sendMsg(nFD, tMsgData)
  582. end
  583. function LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C(msg)
  584. local nFD = MiddleManager.getFDBySvrIndex(msg.nServerID)
  585. if not nFD then
  586. print("[LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C] 找不到请求服务器对应的FD nServerID = "..msg.nServerID)
  587. return
  588. end
  589. local tMsgData = InnerMsg.lw.WL_JJC_NEWLADDER_SEND_RANK_PRIZE_C2O
  590. tMsgData.uuid = msg.uuid
  591. tMsgData.nRank = msg.nRank
  592. InnerMsg.sendMsg(nFD, tMsgData)
  593. end
  594. -------------------- 天梯赛结束 ---------------------------