MiddleConnect.lua 27 KB

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