NoticeProxy.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local NoticeProxy = class("NoticeProxy", RemoteProxy)
  3. NoticeProxy.NAME = global.ProxyTable.NoticeProxy
  4. local cjson = require("cjson")
  5. function NoticeProxy:ctor()
  6. NoticeProxy.super.ctor(self)
  7. self._isDelete = false
  8. end
  9. function NoticeProxy:handle_MSG_SC_SERVICE_TIPS(msg)
  10. local jsonData = ParseRawMsgToJson(msg)
  11. if not jsonData then
  12. return false
  13. end
  14. dump(jsonData)
  15. -- close
  16. if not next(jsonData) or (not jsonData.Msg) or (jsonData.Msg == "") then
  17. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Close)
  18. return false
  19. end
  20. local btn = {}
  21. if jsonData.Btn1 and string.len(jsonData.Btn1) > 1 then
  22. table.insert(btn, {name = GET_STRING(1001), act = jsonData.Btn1})
  23. end
  24. if jsonData.Btn2 and string.len(jsonData.Btn2) > 1 then
  25. table.insert(btn, {name = GET_STRING(1000), act = jsonData.Btn2})
  26. end
  27. local tips = string.gsub(jsonData.Msg, "\\", "<br>")
  28. local data = {}
  29. data.str = tips
  30. data.btnDesc = #btn > 0 and {btn[1].name, btn[2] and btn[2].name or nil} or {GET_STRING(1001)}
  31. data.callback = function(eventIndex)
  32. if #btn > 0 then
  33. local cdata = {}
  34. cdata.UserID = jsonData.UserID
  35. cdata.newIndex = jsonData.newIndex
  36. cdata.Act = btn[eventIndex].act
  37. local NPCProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
  38. NPCProxy:ExecuteWithJsonData(cdata)
  39. end
  40. end
  41. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  42. end
  43. function NoticeProxy:handle_MSG_SC_SYSTEM_INFO(msg)
  44. local jsonData = ParseRawMsgToJson(msg)
  45. if not jsonData then
  46. return
  47. end
  48. local msgHdr = msg:GetHeader()
  49. -- 掉落组别 1 - 10
  50. local dropGroup = msgHdr.param3 > 0 and msgHdr.param3 or nil
  51. -- print("------------------------------------")
  52. -- print(" into here to get system info ")
  53. -- dump(jsonData,"handle_MSG_SC_SYSTEM_INFO__")
  54. -- print("dropGroup======", dropGroup)
  55. -- print("------------------------------------")
  56. -- Type:
  57. -- 1 系统频道
  58. -- 2 行会频道
  59. -- 3 组队频道
  60. -- 4 顶部跑马灯公告
  61. -- 5 屏幕跑马灯公告 可控制Y轴
  62. -- 6 聊天上方公告
  63. -- 7 服务器说是怪物说话?什么鬼
  64. -- 8 固定聊天
  65. -- 9 systemtips
  66. -- 10 可控制xy坐标广播
  67. -- 11 屏幕跑马灯公告 系统公告
  68. -- 12 系统频道 带超链
  69. -- 13 系统公告缩放
  70. -- 14 倒计时提示 可配置X坐标
  71. -- 15 物品掉落在屏幕最上方公告
  72. -- Msg:提示内容
  73. -- FColor:文字色值ID
  74. -- BColor:背景色值ID
  75. -- Y:坐标Y
  76. -- Count:播放次数
  77. -- Time:倒计时
  78. -- Label:响应Link
  79. -- Prefix: 聊天消息前缀
  80. -- 用于区分PC端/手机端不同内容
  81. if global.isWinPlayMode and jsonData.Msg1 then
  82. jsonData.Msg = jsonData.Msg1
  83. end
  84. if jsonData.Type == 1 or jsonData.Type == 0 or not jsonData.Type then
  85. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  86. local setChannelID = dropGroup and ChatProxy.CHANNEL.Drop
  87. local mdata = {
  88. Msg = jsonData.Msg,
  89. FColor = jsonData.FColor,
  90. BColor = jsonData.BColor,
  91. ChannelId = setChannelID or (jsonData.Type == 0 and ChatProxy.CHANNEL.World or ChatProxy.CHANNEL.System),
  92. SendName = jsonData.SendName,
  93. SendId = jsonData.SendId,
  94. mt = jsonData.mt and jsonData.mt or ChatProxy.MSG_TYPE.SRText,
  95. Prefix = jsonData.Prefix,
  96. dropType = dropGroup
  97. }
  98. global.Facade:sendNotification(global.NoticeTable.AddChatItem, mdata)
  99. elseif jsonData.Type == 12 then
  100. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  101. local setChannelID = dropGroup and ChatProxy.CHANNEL.Drop
  102. local mdata = {
  103. Msg = jsonData.Msg,
  104. FColor = jsonData.FColor,
  105. BColor = jsonData.BColor,
  106. ChannelId = setChannelID or ChatProxy.CHANNEL.System,
  107. mt = ChatProxy.MSG_TYPE.SystemTips,
  108. Prefix = jsonData.Prefix,
  109. dropType = dropGroup
  110. }
  111. global.Facade:sendNotification(global.NoticeTable.AddChatItem, mdata)
  112. elseif jsonData.Type == 2 then
  113. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  114. local mdata = {
  115. Msg = jsonData.Msg,
  116. FColor = jsonData.FColor,
  117. BColor = jsonData.BColor,
  118. ChannelId = ChatProxy.CHANNEL.Guild,
  119. mt = ChatProxy.MSG_TYPE.SystemTips,
  120. Prefix = jsonData.Prefix
  121. }
  122. global.Facade:sendNotification(global.NoticeTable.AddChatItem, mdata)
  123. elseif jsonData.Type == 3 then
  124. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  125. local mdata = {
  126. Msg = jsonData.Msg,
  127. FColor = jsonData.FColor,
  128. BColor = jsonData.BColor,
  129. ChannelId = ChatProxy.CHANNEL.Team,
  130. mt = ChatProxy.MSG_TYPE.SystemTips,
  131. Prefix = jsonData.Prefix
  132. }
  133. global.Facade:sendNotification(global.NoticeTable.AddChatItem, mdata)
  134. elseif jsonData.Type == 4 then
  135. local data = {
  136. Msg = jsonData.Msg,
  137. FColor = jsonData.FColor,
  138. BColor = jsonData.BColor,
  139. }
  140. global.Facade:sendNotification(global.NoticeTable.ShowServerNotice, data)
  141. elseif jsonData.Type == 5 then
  142. local data = {
  143. Msg = jsonData.Msg,
  144. FColor = jsonData.FColor,
  145. BColor = jsonData.BColor,
  146. Y = jsonData.Y,
  147. Count = jsonData.Count,
  148. }
  149. global.Facade:sendNotification(global.NoticeTable.ShowSystemNotice, data)
  150. elseif jsonData.Type == 6 then
  151. local data = {
  152. Msg = jsonData.Msg,
  153. FColor = jsonData.FColor,
  154. BColor = jsonData.BColor,
  155. Time = jsonData.Time,
  156. Label = jsonData.Label,
  157. X = jsonData.X,
  158. Y = jsonData.Y
  159. }
  160. global.Facade:sendNotification(global.NoticeTable.ShowTimerNotice, data)
  161. elseif jsonData.Type == 8 then
  162. local data = {
  163. Msg = jsonData.Msg,
  164. FColor = jsonData.FColor,
  165. BColor = jsonData.BColor,
  166. Time = jsonData.Time,
  167. Label = jsonData.Label,
  168. SendId = jsonData.SendId,
  169. SendName = jsonData.SendName,
  170. }
  171. global.Facade:sendNotification(global.NoticeTable.AddChatExItem, data)
  172. elseif jsonData.Type == 9 then
  173. ShowSystemTips(jsonData.Msg)
  174. elseif jsonData.Type == 10 then
  175. local data = {
  176. X = jsonData.X,
  177. Y = jsonData.Y,
  178. Msg = jsonData.Msg,
  179. FColor = jsonData.FColor,
  180. BColor = jsonData.BColor,
  181. }
  182. global.Facade:sendNotification(global.NoticeTable.ShowSystemNoticeXY, data)
  183. elseif jsonData.Type == 11 then
  184. local data = {
  185. Type = jsonData.Type,
  186. Msg = jsonData.Msg,
  187. FColor = jsonData.FColor,
  188. BColor = jsonData.BColor,
  189. }
  190. global.Facade:sendNotification(global.NoticeTable.ServerNoticeEvent, data)
  191. elseif jsonData.Type == 13 then
  192. local data = {
  193. Msg = jsonData.Msg,
  194. FColor = jsonData.FColor,
  195. BColor = jsonData.BColor,
  196. Y = jsonData.Y,
  197. Count = jsonData.Count,
  198. ShowTime = jsonData.time,
  199. }
  200. global.Facade:sendNotification(global.NoticeTable.ShowSystemNoticeScale, data)
  201. elseif jsonData.Type == 14 then
  202. local data = {
  203. Msg = jsonData.Msg,
  204. FColor = jsonData.FColor,
  205. BColor = jsonData.BColor,
  206. Time = jsonData.Time,
  207. Label = jsonData.Label,
  208. X = jsonData.X,
  209. isDelete = jsonData.isDelete,
  210. }
  211. self._isDelete = data.isDelete
  212. global.Facade:sendNotification(global.NoticeTable.ShowTimerNoticeXY, data)
  213. elseif jsonData.Type == 15 then
  214. local data = {
  215. Type = jsonData.Type,
  216. Msg = jsonData.Msg,
  217. FColor = jsonData.FColor,
  218. BColor = jsonData.BColor,
  219. }
  220. global.Facade:sendNotification(global.NoticeTable.ShowItemDropNotice, data)
  221. end
  222. end
  223. function NoticeProxy:getIsDeleteByType14()
  224. return self._isDelete
  225. end
  226. function NoticeProxy:handle_MSG_SC_PLAY_AUDIO(msg)
  227. local jsonData = ParseRawMsgToJson(msg)
  228. dump(jsonData)
  229. if not jsonData then
  230. return nil
  231. end
  232. if not jsonData.id or not jsonData.playcount then
  233. return nil
  234. end
  235. local audio_data = {}
  236. audio_data.id = jsonData.id
  237. audio_data.times = jsonData.playcount or 1
  238. audio_data.loop = false
  239. audio_data.type = global.MMO.SUD_TYPE_SERVER
  240. global.Facade:sendNotification(global.NoticeTable.Audio_Play_EffectId, audio_data)
  241. end
  242. function NoticeProxy:handle_MSG_SC_REMOVE_TIMER_NOTICE(msg)
  243. global.Facade:sendNotification(global.NoticeTable.DeleteTimerNotice)
  244. end
  245. function NoticeProxy:handle_MSG_SC_OPENUI(msg)
  246. local jsonData = ParseRawMsgToJson(msg)
  247. if not jsonData then
  248. return
  249. end
  250. dump(jsonData)
  251. local id = jsonData.id
  252. local param = jsonData.param
  253. local param2 = tonumber(jsonData.param2) or 0
  254. local JumpProxy = global.Facade:retrieveProxy(global.ProxyTable.JumpProxy)
  255. JumpProxy:JumpTo(id, param, param2)
  256. end
  257. function NoticeProxy:handle_MSG_SC_PLAY_DICE(msg)
  258. local jsonData = ParseRawMsgToJson(msg)
  259. if not jsonData then
  260. return
  261. end
  262. dump(jsonData)
  263. global.Facade:sendNotification(global.NoticeTable.Layer_PlayDice_Open, jsonData)
  264. end
  265. function NoticeProxy:handle_MSG_SC_CLIPBOARD_TEXT(msg)
  266. local msgLen = msg:GetDataLength()
  267. if msgLen > 0 then
  268. local dataString = msg:GetData():ReadString(msgLen)
  269. if global.isWindows then
  270. if Win32BridgeCtl then
  271. Win32BridgeCtl:Inst():copyToClipboard(dataString)
  272. end
  273. else
  274. global.L_NativeBridgeManager:GN_setClipboardText(dataString)
  275. end
  276. end
  277. end
  278. function NoticeProxy:handle_MSG_SC_REMOVE_TIMER_NOTICEXY(msg)
  279. local header = msg:GetHeader()
  280. -- dump(header.param1)
  281. if tonumber(header.param1) and tonumber(header.param1) == 14 then
  282. global.Facade:sendNotification(global.NoticeTable.DeleteTimerNoticeXY)
  283. end
  284. end
  285. function NoticeProxy:handle_MSG_SC_START_APP(msg)
  286. local header = msg:GetHeader()
  287. if header.recog == 1 then
  288. -- 拉起qq
  289. if global.L_NativeBridgeManager.GN_startQQ then
  290. global.L_NativeBridgeManager:GN_startQQ()
  291. end
  292. elseif header.recog == 2 then
  293. -- 加qq好友
  294. local jsonData = ParseRawMsgToJson(msg)
  295. if jsonData and jsonData.qqKey then
  296. if global.L_NativeBridgeManager.GN_joinQQ then
  297. global.L_NativeBridgeManager:GN_joinQQ({qqKey = jsonData.qqKey})
  298. end
  299. end
  300. elseif header.recog == 3 then
  301. -- 加qq群
  302. local jsonData = ParseRawMsgToJson(msg)
  303. if jsonData and jsonData.qqGroupUin and jsonData.qqGroupKey then
  304. if global.L_NativeBridgeManager.GN_joinQQGroup then
  305. global.L_NativeBridgeManager:GN_joinQQGroup({qqGroupUin = jsonData.qqGroupUin, qqGroupKey = jsonData.qqGroupKey})
  306. end
  307. end
  308. elseif header.recog == 4 then
  309. -- 拉微信
  310. if global.L_NativeBridgeManager.GN_startWX then
  311. global.L_NativeBridgeManager:GN_startWX()
  312. end
  313. elseif header.recog == 5 then
  314. -- todo
  315. -- 拉微信公众号
  316. end
  317. end
  318. function NoticeProxy:handle_MSG_SC_SERVER_GAME_ERROR(msg)
  319. -- 健康游戏提醒
  320. local function callback(bType, custom)
  321. -- PC上默认退出,方便获取新的登录信息以及更新exe
  322. if global.isWindows then
  323. global.Director:endToLua()
  324. else
  325. global.L_NativeBridgeManager:GN_accountLogout()
  326. global.Facade:sendNotification( global.NoticeTable.RestartGame )
  327. end
  328. end
  329. -- 提醒内容
  330. local msgLen = msg:GetDataLength()
  331. local dataString = msgLen > 0 and msg:GetData():ReadString(msgLen) or ""
  332. --退出倒计时
  333. local findS, findE = string.find(dataString, "%[restart:%d+%]")
  334. local restartDownTimes = nil
  335. if findS and findE and findE > findS then
  336. local restartStr = string.sub(dataString, findS+1, findE-1)
  337. local resartArray = string.split(restartStr, ":")
  338. restartDownTimes = resartArray[2] and tonumber(resartArray[2])
  339. dataString = string.gsub(dataString, "%["..restartStr.."%]", "")
  340. -- 退出
  341. if restartDownTimes then
  342. SL:ScheduleOnce(function()
  343. global.gameWorldController._restart = true
  344. end, restartDownTimes)
  345. end
  346. end
  347. -- 是否直接退出
  348. local checkWord = restartDownTimes and {} or {"crash"}
  349. local titleStr = string.lower(dataString)
  350. local isExitGame = false
  351. for i,v in ipairs(checkWord) do
  352. local findS,findE = string.find(titleStr, v)
  353. if findS and findE then
  354. isExitGame = true
  355. break
  356. end
  357. end
  358. if isExitGame then
  359. global.Director:endToLua()
  360. return
  361. end
  362. local data = {}
  363. data.str = dataString
  364. data.btnDesc = { GET_STRING(1001)}
  365. data.callback = callback
  366. data.hideCloseBtn = true
  367. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  368. -- 重连禁用
  369. global.Facade:sendNotification(global.NoticeTable.ReconnectForbidden)
  370. end
  371. function NoticeProxy:handle_MSG_SC_LIMIT_CHAT(msg)
  372. local header = msg:GetHeader()
  373. local forbidSay = header.recog
  374. local LoginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  375. LoginProxy:SetForbidChat(forbidSay == 1)
  376. end
  377. -- 自定义事件数据上报
  378. function NoticeProxy:handle_MSG_SC_CUSTOM_EVENT_REPORT(msg)
  379. local msgLen = msg:GetDataLength()
  380. if msgLen <= 0 then
  381. return
  382. end
  383. local dataString = msg:GetData():ReadString(msgLen)
  384. local NativeBridgeProxy = global.Facade:retrieveProxy(global.ProxyTable.NativeBridgeProxy)
  385. NativeBridgeProxy:GN_ReportCustomEvent(dataString)
  386. end
  387. function NoticeProxy:RegisterMsgHandlerAfterEnterWorld()
  388. local msgType = global.MsgType
  389. LuaRegisterMsgHandler(msgType.MSG_SC_SERVICE_TIPS, handler(self, self.handle_MSG_SC_SERVICE_TIPS))
  390. LuaRegisterMsgHandler(msgType.MSG_SC_SYSTEM_INFO, handler(self, self.handle_MSG_SC_SYSTEM_INFO)) -- 接收到的系统消息
  391. LuaRegisterMsgHandler(msgType.MSG_SC_PLAY_AUDIO, handler(self, self.handle_MSG_SC_PLAY_AUDIO)) -- 播放音乐
  392. LuaRegisterMsgHandler(msgType.MSG_SC_REMOVE_TIMER_NOTICE, handler(self, self.handle_MSG_SC_REMOVE_TIMER_NOTICE)) -- 删除定时系统消息
  393. LuaRegisterMsgHandler(msgType.MSG_SC_OPENUI, handler(self, self.handle_MSG_SC_OPENUI)) -- 打开界面
  394. LuaRegisterMsgHandler(msgType.MSG_SC_PLAY_DICE, handler(self, self.handle_MSG_SC_PLAY_DICE)) -- 播放骰子
  395. LuaRegisterMsgHandler(msgType.MSG_SC_CLIPBOARD_TEXT, handler(self, self.handle_MSG_SC_CLIPBOARD_TEXT)) -- 播放骰子
  396. LuaRegisterMsgHandler(msgType.MSG_SC_REMOVE_TIMER_NOTICEXY, handler(self, self.handle_MSG_SC_REMOVE_TIMER_NOTICEXY))
  397. LuaRegisterMsgHandler(msgType.MSG_SC_START_APP, handler(self, self.handle_MSG_SC_START_APP))
  398. LuaRegisterMsgHandler(msgType.MSG_SC_SERVER_GAME_ERROR, handler(self, self.handle_MSG_SC_SERVER_GAME_ERROR))
  399. LuaRegisterMsgHandler(msgType.MSG_SC_LIMIT_CHAT, handler(self, self.handle_MSG_SC_LIMIT_CHAT))
  400. LuaRegisterMsgHandler(msgType.MSG_SC_CUSTOM_EVENT_REPORT, handler(self, self.handle_MSG_SC_CUSTOM_EVENT_REPORT))
  401. end
  402. return NoticeProxy