MiddleConnect.lua 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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. InnerMsg.sendMsg(nSrcFD, tMsgData)
  354. print("[LW_COMBAT_GETINFO_SEND] 发送 WL_COMBAT_GETINFO_SEND")
  355. end
  356. -------------------- 跨服请求战斗数据结束 --------------------
  357. -------------------- 天梯赛开始 ---------------------------
  358. -- 请求参加天梯赛(普通->中心)
  359. function LW_JJC_NEWLADDER_JOINLADDER_O2C(fd, msg)
  360. local nSrcServerID = msg.nSrcServerID
  361. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  362. if not nWarFD then
  363. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  364. return
  365. end
  366. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛")
  367. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2D
  368. tMsgData.uuid = msg.uuid
  369. tMsgData.name = msg.name
  370. tMsgData.head = msg.head
  371. tMsgData.headFrame = msg.headFrame
  372. tMsgData.nSrcServerID = msg.nSrcServerID
  373. tMsgData.szServerName = msg.szServerName
  374. tMsgData.zhandouli = msg.zhandouli
  375. InnerMsg.sendMsg(nWarFD, tMsgData)
  376. print("[LW_JJC_NEWLADDER_JOINLADDER_O2C] 玩家请求参加天梯赛, 发送到对应的战区数据服成功")
  377. end
  378. -- 请求参加天梯赛(数据->中心)
  379. function LW_JJC_NEWLADDER_JOINLADDER_D2C(fd, msg)
  380. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  381. if not nFd then
  382. print("[LW_JJC_NEWLADDER_JOINLADDER_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  383. return
  384. end
  385. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_JOINLADDER_C2O
  386. tMsgData.uuid = msg.uuid
  387. tMsgData.nRank = msg.nRank
  388. tMsgData.tEnemy = msg.tEnemy
  389. tMsgData.nPoint = msg.nPoint
  390. InnerMsg.sendMsg(nFd, tMsgData)
  391. print("[LW_JJC_NEWLADDER_JOINLADDER_D2C] 请求参加天梯赛(数据->中心) 回复结束")
  392. end
  393. -- 请求刷新对战列表(普通->中心)
  394. function LW_JJC_NEWLADDER_REFRESH_O2C(msg)
  395. local nSrcServerID = msg.nSrcServerID
  396. local nWarFD = MiddleConnect_GetWarFirstServerFD(nSrcServerID)
  397. if not nWarFD then
  398. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 获取不到对应的战区的FD nSrcServerID = "..nSrcServerID)
  399. return
  400. end
  401. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表")
  402. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2D
  403. tMsgData.uuid = msg.uuid
  404. tMsgData.nSrcServerID = msg.nSrcServerID
  405. InnerMsg.sendMsg(nWarFD, tMsgData)
  406. print("[LW_JJC_NEWLADDER_REFRESH_O2C] 玩家请求刷新对战列表, 发送到对应的战区数据服成功")
  407. end
  408. -- 请求刷新对战列表(数据->中心)
  409. function LW_JJC_NEWLADDER_REFRESH_D2C(msg)
  410. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  411. if not nFd then
  412. print("[LW_JJC_NEWLADDER_REFRESH_D2C] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  413. return
  414. end
  415. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_REFRESH_C2O
  416. tMsgData.uuid = msg.uuid
  417. tMsgData.tEnemy = msg.tEnemy
  418. InnerMsg.sendMsg(nFd, tMsgData)
  419. print("[LW_JJC_NEWLADDER_REFRESH_D2C] 请求刷新对战列表(数据->中心) 发送完成")
  420. end
  421. -- 请求上一轮排名前三数据(普通->中心)
  422. function LW_JJC_NEWLADDER_LAST3RANK_O2C(msg)
  423. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  424. if not nWarFD then
  425. print("[LW_JJC_NEWLADDER_LAST3RANK_O2C] 获取不到对应的战区的FD nSrcServerID = "..msg.nSrcServerID)
  426. return
  427. end
  428. print("[LW_JJC_NEWLADDER_LAST3RANK_O2C] 开始先数据服发送请求上一轮前三")
  429. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2D
  430. tMsgData.nSrcServerID = msg.nSrcServerID
  431. InnerMsg.sendMsg(nWarFD, tMsgData)
  432. end
  433. -- 请求上一轮排名前三数据(数据->中心)
  434. function LW_JJC_NEWLADDER_LAST3RANK_D2O(msg)
  435. local nFd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  436. if not nFd then
  437. print("[LW_JJC_NEWLADDER_LAST3RANK_D2O] 获取不到对应的天梯赛回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  438. return
  439. end
  440. print("[LW_JJC_NEWLADDER_LAST3RANK_D2O] 获取到对应的 上一轮排名前三数据")
  441. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_LAST3RANK_C2O
  442. tMsgData.nExist = msg.nExist
  443. tMsgData.tLastRankInfo = msg.tLastRankInfo
  444. InnerMsg.sendMsg(nFd, tMsgData)
  445. end
  446. -- 进行点赞(普通->中心)
  447. function LW_JJC_NEWLADDER_SEND_WORSHIP_O2C(msg)
  448. local nDesServerID = msg.nDesServerID
  449. local nDesFD = MiddleManager.getFDBySvrIndex(nDesServerID)
  450. if not nDesFD then
  451. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_O2C] 获取不到需要传递的服务器FD nSrcServerID = "..msg.nSrcServerID.." nDesServerID = "..nDesServerID)
  452. return
  453. end
  454. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2D
  455. tMsgData.uuidSrc = msg.uuidSrc
  456. tMsgData.uuidDes = msg.uuidDes
  457. tMsgData.nSrcServerID = msg.nSrcServerID
  458. InnerMsg.sendMsg(nDesFD, tMsgData)
  459. end
  460. -- 进行点赞(数据(被点赞玩家所在服)->中心)
  461. function LW_JJC_NEWLADDER_SEND_WORSHIP_D2C(msg)
  462. local nSrcFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  463. if not nSrcFD then
  464. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 获取不到回复的服务器FD nSrcServerID = "..msg.nSrcServerID)
  465. return
  466. end
  467. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_WORSHIP_C2O
  468. tMsgData.uuidSrc = msg.uuidSrc
  469. tMsgData.uuidDes = msg.uuidDes
  470. tMsgData.nNowWorShip = msg.nNowWorShip
  471. -- 回复对应的服务器
  472. InnerMsg.sendMsg(nSrcFD, tMsgData)
  473. -- 发给战区数据服,更新点赞数
  474. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  475. if nWarFD then
  476. tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_CHANGE_C2D
  477. tMsgData.uuidDes = msg.uuidDes
  478. tMsgData.nAddNum = 1
  479. InnerMsg.sendMsg(nWarFD, tMsgData)
  480. else
  481. print("[LW_JJC_NEWLADDER_SEND_WORSHIP_D2C] 不存在对应的战区fd")
  482. end
  483. end
  484. -- 通知战区下属服务器最新的点赞数
  485. function LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C(msg)
  486. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_WORSHIP_UPDATE_D2C
  487. tMsgData.uuidDes = msg.uuidDes
  488. tMsgData.nNowWorShip = msg.nNowWorShip
  489. local nConfigServerID = MiddleConnect_TrueServerID2ConfServerID(msg.nSrcServerID)
  490. local nMinServerID, nMaxServerID = MiddleConnect_GetWarZoneServer(nConfigServerID)
  491. for i = nMinServerID, nMaxServerID, 1 do
  492. local nTrueServerID = MiddleConnect_ConfServerID2TrueServerID(i)
  493. local nFD = MiddleManager.getFDBySvrIndex(nTrueServerID)
  494. if nFD then
  495. InnerMsg.sendMsg(nFD, tMsgData)
  496. else
  497. print("[LW_JJC_NEWLADDER_WORSHIP_CHANGE_D2C] 没有获取到对应的 nTrueServerID = "..nTrueServerID)
  498. end
  499. end
  500. end
  501. -- 请求天梯赛排行榜数据(普通->中心)
  502. function LW_JJC_NEWLADDER_QUERY_RANK_O2C(msg)
  503. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  504. if not nWarFD then
  505. print("[LW_JJC_NEWLADDER_QUERY_RANK_O2C] 获取不到对应的战区的FD")
  506. return
  507. end
  508. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2D
  509. tMsgData.nSrcServerID = msg.nSrcServerID
  510. InnerMsg.sendMsg(nWarFD, tMsgData)
  511. end
  512. -- 回复天梯赛排行榜数据(中心->数据服)
  513. function LW_JJC_NEWLADDER_QUERY_RANK_D2C(msg)
  514. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  515. if not nFD then
  516. print("[LW_JJC_NEWLADDER_QUERY_RANK_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  517. return
  518. end
  519. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_RANK_C2O
  520. tMsgData.nIsEnd = msg.nIsEnd
  521. tMsgData.nFirst = msg.nFirst
  522. tMsgData.tRankInfo = msg.tRankInfo
  523. InnerMsg.sendMsg(nFD, tMsgData)
  524. end
  525. -- 查询是否能够战斗(普通->中心)
  526. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C(msg)
  527. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  528. if not nWarFD then
  529. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C] 获取不到对应的战区的FD")
  530. return
  531. end
  532. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2D
  533. tMsgData.uuid = msg.uuid
  534. tMsgData.uuidDes = msg.uuidDes
  535. tMsgData.nSrcServerID = msg.nSrcServerID
  536. InnerMsg.sendMsg(nWarFD, tMsgData)
  537. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_O2C] 查询是否能够战斗(普通->中心)")
  538. end
  539. -- 查询是否能够战斗(数据服->中心)
  540. function LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C(msg)
  541. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  542. if not nFD then
  543. print("[LW_JJC_NEWLADDER_QUERY_CAN_FIGHT_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  544. return
  545. end
  546. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_CAN_FIGHT_C2O
  547. tMsgData.uuid = msg.uuid
  548. tMsgData.uuidDes = msg.uuidDes
  549. tMsgData.nIsFight = msg.nIsFight
  550. InnerMsg.sendMsg(nFD, tMsgData)
  551. end
  552. -- 战斗结束(普通->中心)
  553. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C(msg)
  554. local nWarFD = MiddleConnect_GetWarFirstServerFD(msg.nSrcServerID)
  555. if not nWarFD then
  556. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_O2C] 获取不到对应的战区的FD")
  557. return
  558. end
  559. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2D
  560. tMsgData.uuid = msg.uuid
  561. tMsgData.uuidDes = msg.uuidDes
  562. tMsgData.nSrcServerID = msg.nSrcServerID
  563. tMsgData.nResult = msg.nResult
  564. tMsgData.tEnemyUid = msg.tEnemyUid
  565. tMsgData.nZhanDouLi = msg.nZhanDouLi
  566. InnerMsg.sendMsg(nWarFD, tMsgData)
  567. end
  568. -- 战斗结束(数据服->中心)
  569. function LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C(msg)
  570. local nFD = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  571. if not nFD then
  572. print("[LW_JJC_NEWLADDER_CANCEL_FIGHT_END_D2C] 找不到请求服务器对应的FD nSrcServerID = "..msg.nSrcServerID)
  573. return
  574. end
  575. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_CANCEL_FIGHT_END_C2O
  576. tMsgData.uuid = msg.uuid
  577. tMsgData.nNewRank = msg.nNewRank
  578. tMsgData.nNewPoint = msg.nNewPoint
  579. tMsgData.uuidDes = msg.uuidDes
  580. tMsgData.tNewOneEnemy = msg.tNewOneEnemy
  581. tMsgData.tOldEnemyData = msg.tOldEnemyData
  582. InnerMsg.sendMsg(nFD, tMsgData)
  583. end
  584. --发送失败邮件
  585. function LW_JJC_NEWLADDER_SEND_MAIL_D2C(msg)
  586. local nFD = MiddleManager.getFDBySvrIndex(msg.nDesServerID)
  587. if not nFD then
  588. print("[LW_JJC_NEWLADDER_SEND_MAIL_D2C] 找不到请求服务器对应的FD nDesServerID = "..msg.nDesServerID)
  589. return
  590. end
  591. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_MAIL_C2O
  592. tMsgData.uuidDes = msg.uuidDes
  593. tMsgData.szServerName = msg.szServerName
  594. tMsgData.szName = msg.szName
  595. tMsgData.nNewRank = msg.nNewRank
  596. InnerMsg.sendMsg(nFD, tMsgData)
  597. end
  598. function LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C(msg)
  599. local nFD = MiddleManager.getFDBySvrIndex(msg.nServerID)
  600. if not nFD then
  601. print("[LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C] 找不到请求服务器对应的FD nServerID = "..msg.nServerID)
  602. return
  603. end
  604. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_SEND_RANK_PRIZE_C2O
  605. tMsgData.uuid = msg.uuid
  606. tMsgData.nRank = msg.nRank
  607. InnerMsg.sendMsg(nFD, tMsgData)
  608. print("[LW_JJC_NEWLADDER_SEND_RANK_PRIZE_D2C] 发送对应玩家的奖励邮件")
  609. end
  610. function LW_JJC_NEWLADDER_QUERY_WORSHIP_D2C(msg)
  611. local nFD = MiddleManager.getFDBySvrIndex(msg.nServerID)
  612. if not nFD then
  613. print("[LW_JJC_NEWLADDER_QUERY_WORSHIP_D2C] 找不到请求服务器对应的FD nServerID = "..msg.nServerID)
  614. return
  615. end
  616. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_WORSHIP_C20
  617. tMsgData.uuid = msg.uuid
  618. tMsgData.nFromServerID = msg.nFromServerID
  619. InnerMsg.sendMsg(nFD, tMsgData)
  620. end
  621. function LW_JJC_NEWLADDER_QUERY_WORSHIP_O2C(msg)
  622. local nFD = MiddleManager.getFDBySvrIndex(msg.nFromServerID)
  623. if not nFD then
  624. print("[LW_JJC_NEWLADDER_QUERY_WORSHIP_O2C] 找不到请求服务器对应的FD nServerID = "..msg.nFromServerID)
  625. return
  626. end
  627. local tMsgData = InnerMsg.wl.WL_JJC_NEWLADDER_QUERY_WORSHIP_C2D
  628. tMsgData.uuid = msg.uuid
  629. tMsgData.nWorShip = msg.nWorShip
  630. InnerMsg.sendMsg(nFD, tMsgData)
  631. end
  632. -------------------- 天梯赛结束 ---------------------------