ChatProxy.lua 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local ChatProxy = class("ChatProxy", RemoteProxy)
  3. ChatProxy.NAME = global.ProxyTable.Chat
  4. local cjson = require("cjson")
  5. local strformat = string.format
  6. -- 表情表的replace字段字符串值必须以 #开头,不然解析的时候会获取不到
  7. local FACE_CONFIG = {
  8. [1] = {
  9. ID = 1,
  10. replace = "#嘿嘿",
  11. sfxid = 7000,
  12. },
  13. [2] = {
  14. ID = 2,
  15. replace = "#惊叹",
  16. sfxid = 7001,
  17. },
  18. [3] = {
  19. ID = 3,
  20. replace = "#暴笑",
  21. sfxid = 7002,
  22. },
  23. [4] = {
  24. ID = 4,
  25. replace = "#暴走",
  26. sfxid = 7003,
  27. },
  28. [5] = {
  29. ID = 5,
  30. replace = "#爱你",
  31. sfxid = 7004,
  32. },
  33. [6] = {
  34. ID = 6,
  35. replace = "#不满",
  36. sfxid = 7005,
  37. },
  38. [7] = {
  39. ID = 7,
  40. replace = "#冷汗",
  41. sfxid = 7006,
  42. },
  43. [8] = {
  44. ID = 8,
  45. replace = "#哈欠",
  46. sfxid = 7007,
  47. },
  48. [9] = {
  49. ID = 9,
  50. replace = "#好险",
  51. sfxid = 7008,
  52. },
  53. [10] = {
  54. ID = 10,
  55. replace = "#嘘",
  56. sfxid = 7009,
  57. },
  58. [11] = {
  59. ID = 11,
  60. replace = "#折磨",
  61. sfxid = 7010,
  62. },
  63. [12] = {
  64. ID = 12,
  65. replace = "#生气",
  66. sfxid = 7011,
  67. },
  68. [13] = {
  69. ID = 13,
  70. replace = "#喜欢",
  71. sfxid = 7012,
  72. },
  73. [14] = {
  74. ID = 14,
  75. replace = "#困",
  76. sfxid = 7013,
  77. },
  78. [15] = {
  79. ID = 15,
  80. replace = "#呲牙",
  81. sfxid = 7014,
  82. },
  83. [16] = {
  84. ID = 16,
  85. replace = "#懵",
  86. sfxid = 7015,
  87. },
  88. [17] = {
  89. ID = 17,
  90. replace = "#怒",
  91. sfxid = 7016,
  92. },
  93. [18] = {
  94. ID = 18,
  95. replace = "#互粉",
  96. sfxid = 7017,
  97. },
  98. [19] = {
  99. ID = 19,
  100. replace = "#思考",
  101. sfxid = 7018,
  102. },
  103. [20] = {
  104. ID = 20,
  105. replace = "#生病",
  106. sfxid = 7019,
  107. },
  108. [21] = {
  109. ID = 21,
  110. replace = "#掌嘴",
  111. sfxid = 7020,
  112. },
  113. [22] = {
  114. ID = 22,
  115. replace = "#可爱",
  116. sfxid = 7021,
  117. },
  118. [23] = {
  119. ID = 23,
  120. replace = "#阴险",
  121. sfxid = 7022,
  122. },
  123. [24] = {
  124. ID = 24,
  125. replace = "#恶心",
  126. sfxid = 7023,
  127. },
  128. [25] = {
  129. ID = 25,
  130. replace = "#修修",
  131. sfxid = 7024,
  132. },
  133. [26] = {
  134. ID = 26,
  135. replace = "#可怜",
  136. sfxid = 7025,
  137. },
  138. [27] = {
  139. ID = 27,
  140. replace = "#调皮",
  141. sfxid = 7026,
  142. },
  143. [28] = {
  144. ID = 28,
  145. replace = "#哭",
  146. sfxid = 7027,
  147. },
  148. [29] = {
  149. ID = 29,
  150. replace = "#睡觉",
  151. sfxid = 7028,
  152. },
  153. [30] = {
  154. ID = 30,
  155. replace = "#笑哭",
  156. sfxid = 7029,
  157. },
  158. [31] = {
  159. ID = 31,
  160. replace = "#无语",
  161. sfxid = 7030,
  162. },
  163. [32] = {
  164. ID = 32,
  165. replace = "#疑问",
  166. sfxid = 7031,
  167. },
  168. [33] = {
  169. ID = 33,
  170. replace = "#委屈",
  171. sfxid = 7032,
  172. },
  173. [34] = {
  174. ID = 34,
  175. replace = "#大佬",
  176. sfxid = 7033,
  177. },
  178. [35] = {
  179. ID = 35,
  180. replace = "#不屑",
  181. sfxid = 7034,
  182. },
  183. [36] = {
  184. ID = 36,
  185. replace = "#晕",
  186. sfxid = 7035,
  187. },
  188. [37] = {
  189. ID = 37,
  190. replace = "#敲你",
  191. sfxid = 7036,
  192. },
  193. [38] = {
  194. ID = 38,
  195. replace = "#大骂",
  196. sfxid = 7037,
  197. },
  198. [39] = {
  199. ID = 39,
  200. replace = "#右哼哼",
  201. sfxid = 7038,
  202. },
  203. [40] = {
  204. ID = 40,
  205. replace = "#抠鼻",
  206. sfxid = 7039,
  207. },
  208. [41] = {
  209. ID = 41,
  210. replace = "#财迷",
  211. sfxid = 7040,
  212. },
  213. [42] = {
  214. ID = 42,
  215. replace = "#左哼哼",
  216. sfxid = 7041,
  217. },
  218. [43] = {
  219. ID = 43,
  220. replace = "#衰",
  221. sfxid = 7042,
  222. },
  223. [44] = {
  224. ID = 44,
  225. replace = "#鄙视",
  226. sfxid = 7043,
  227. },
  228. [45] = {
  229. ID = 45,
  230. replace = "#偷笑",
  231. sfxid = 7044,
  232. },
  233. [46] = {
  234. ID = 46,
  235. replace = "#闭嘴",
  236. sfxid = 7045,
  237. },
  238. [47] = {
  239. ID = 47,
  240. replace = "#馋",
  241. sfxid = 7046,
  242. },
  243. [48] = {
  244. ID = 48,
  245. replace = "#甜笑",
  246. sfxid = 7047,
  247. },
  248. [49] = {
  249. ID = 49,
  250. replace = "#亲亲",
  251. sfxid = 7048,
  252. },
  253. [50] = {
  254. ID = 50,
  255. replace = "#鼓掌",
  256. sfxid = 7049,
  257. },
  258. [51] = {
  259. ID = 51,
  260. replace = "#耶",
  261. sfxid = 7050,
  262. },
  263. [52] = {
  264. ID = 52,
  265. replace = "#握手",
  266. sfxid = 7051,
  267. },
  268. [53] = {
  269. ID = 53,
  270. replace = "#厉害",
  271. sfxid = 7052,
  272. },
  273. [54] = {
  274. ID = 54,
  275. replace = "#爱啊",
  276. sfxid = 7053,
  277. },
  278. [55] = {
  279. ID = 55,
  280. replace = "#不行",
  281. sfxid = 7054,
  282. },
  283. [56] = {
  284. ID = 56,
  285. replace = "#好的",
  286. sfxid = 7055,
  287. },
  288. [57] = {
  289. ID = 57,
  290. replace = "#吸引",
  291. sfxid = 7056,
  292. },
  293. [58] = {
  294. ID = 58,
  295. replace = "#抱拳",
  296. sfxid = 7057,
  297. },
  298. [59] = {
  299. ID = 59,
  300. replace = "#公主",
  301. sfxid = 7058,
  302. },
  303. [60] = {
  304. ID = 60,
  305. replace = "#熊猫",
  306. sfxid = 7059,
  307. },
  308. [61] = {
  309. ID = 61,
  310. replace = "#汪星人",
  311. sfxid = 7060,
  312. },
  313. [62] = {
  314. ID = 62,
  315. replace = "#猪头",
  316. sfxid = 7061,
  317. },
  318. [63] = {
  319. ID = 63,
  320. replace = "#羊驼",
  321. sfxid = 7062,
  322. },
  323. [64] = {
  324. ID = 64,
  325. replace = "#粉兔",
  326. sfxid = 7063,
  327. },
  328. [65] = {
  329. ID = 65,
  330. replace = "#喵星人",
  331. sfxid = 7064,
  332. },
  333. [66] = {
  334. ID = 66,
  335. replace = "#凹凸曼",
  336. sfxid = 7065,
  337. },
  338. [67] = {
  339. ID = 67,
  340. replace = "#太阳",
  341. sfxid = 7066,
  342. },
  343. [68] = {
  344. ID = 68,
  345. replace = "#月亮",
  346. sfxid = 7067,
  347. },
  348. [69] = {
  349. ID = 69,
  350. replace = "#肥皂",
  351. sfxid = 7068,
  352. },
  353. [70] = {
  354. ID = 70,
  355. replace = "#玫瑰",
  356. sfxid = 7069,
  357. },
  358. [71] = {
  359. ID = 71,
  360. replace = "#神马",
  361. sfxid = 7070,
  362. },
  363. [72] = {
  364. ID = 72,
  365. replace = "#双喜",
  366. sfxid = 7071,
  367. },
  368. [73] = {
  369. ID = 73,
  370. replace = "#蛋糕",
  371. sfxid = 7072,
  372. },
  373. [74] = {
  374. ID = 74,
  375. replace = "#爱心",
  376. sfxid = 7073,
  377. },
  378. [75] = {
  379. ID = 75,
  380. replace = "#强壮",
  381. sfxid = 7074,
  382. },
  383. [76] = {
  384. ID = 76,
  385. replace = "#拍照",
  386. sfxid = 7075,
  387. },
  388. [77] = {
  389. ID = 77,
  390. replace = "#闹钟",
  391. sfxid = 7076,
  392. },
  393. [78] = {
  394. ID = 78,
  395. replace = "#萌萌哒",
  396. sfxid = 7077,
  397. },
  398. [79] = {
  399. ID = 79,
  400. replace = "#蜡烛",
  401. sfxid = 7078,
  402. },
  403. [80] = {
  404. ID = 80,
  405. replace = "#心碎",
  406. sfxid = 7079,
  407. },
  408. [81] = {
  409. ID = 81,
  410. replace = "#给力",
  411. sfxid = 7080,
  412. },
  413. [82] = {
  414. ID = 82,
  415. replace = "#碰杯",
  416. sfxid = 7081,
  417. },
  418. [83] = {
  419. ID = 83,
  420. replace = "#赖皮",
  421. sfxid = 7082,
  422. },
  423. [84] = {
  424. ID = 84,
  425. replace = "#打我呀",
  426. sfxid = 7083,
  427. },
  428. [85] = {
  429. ID = 85,
  430. replace = "#皱眉",
  431. sfxid = 7084,
  432. },
  433. [86] = {
  434. ID = 86,
  435. replace = "#郁闷",
  436. sfxid = 7085,
  437. },
  438. [87] = {
  439. ID = 87,
  440. replace = "#大笑",
  441. sfxid = 7086,
  442. },
  443. [88] = {
  444. ID = 88,
  445. replace = "#再见",
  446. sfxid = 7087,
  447. },
  448. [89] = {
  449. ID = 89,
  450. replace = "#难受",
  451. sfxid = 7088,
  452. },
  453. [90] = {
  454. ID = 90,
  455. replace = "#哈哈",
  456. sfxid = 7089,
  457. },
  458. [91] = {
  459. ID = 91,
  460. replace = "#伤心",
  461. sfxid = 7090,
  462. },
  463. }
  464. local DROP_TOTAL_TYPE_ID = 99 -- 掉落总分类ID
  465. local FAKE_DROP_TYPE = 77 -- 假掉落分类ID
  466. ChatProxy.CHANNEL = {
  467. Common = 0, -- 综合
  468. System = 1, -- 系统
  469. Shout = 2, -- 喊话
  470. Private = 3, -- 私聊
  471. Guild = 4, -- 行会
  472. Team = 5, -- 组队
  473. Near = 6, -- 附近
  474. World = 7, -- 传音?世界
  475. Nation = 8, -- 国家
  476. Union = 9, -- 联盟
  477. Cross = 10, -- 跨服
  478. GuildTips = 40, -- 行会通知
  479. Drop = 100,-- 掉落
  480. }
  481. ChatProxy.CONFIG = {
  482. LimitCount = 50, -- 聊天限制条数
  483. LimitCountWin = 200, -- 聊天限制条数 PC
  484. InputLength = 20, -- 输入限制长度
  485. InputCacheCount = 10, -- 输入历史保存条数
  486. TargetCount = 10, -- 私聊列表
  487. }
  488. ChatProxy.MSG_TYPE = {
  489. Normal = 1, -- 普通消息
  490. Position = 2, -- 坐标
  491. Equip = 3, -- 装备
  492. SystemTips = 5, -- 系统通知消息,需使用特定的富文本解析
  493. FColorText = 6, -- 系统通知消息,需使用FColor富文本解析
  494. SRText = 7, -- 系统通知消息,需使用SRText富文本解析
  495. Dice = 8, -- 猜拳
  496. }
  497. ChatProxy.CDTIME = {
  498. }
  499. ChatProxy.CHANNEL_PREFIX = {
  500. { channel = ChatProxy.CHANNEL.Guild, prefix = "!~" },
  501. { channel = ChatProxy.CHANNEL.Team, prefix = "!!" },
  502. { channel = ChatProxy.CHANNEL.Nation, prefix = "!#" },
  503. { channel = ChatProxy.CHANNEL.Cross, prefix = "!$" },
  504. { channel = ChatProxy.CHANNEL.Shout, prefix = "!" },
  505. { channel = ChatProxy.CHANNEL.Private, prefix = "/.+ ", pattern = "^/(.+) (.+)" },
  506. { channel = ChatProxy.CHANNEL.World, prefix = "@传 "},
  507. }
  508. ChatProxy.SAY_MAPPING = {
  509. ["/who"] = "/who ",
  510. ["/who "] = "/who ",
  511. ["/Total"] = "/Total ",
  512. ["/Total "] = "/Total ",
  513. }
  514. function ChatProxy:ctor()
  515. ChatProxy.super.ctor(self)
  516. self:Init()
  517. end
  518. function ChatProxy:onRegister()
  519. ChatProxy.super.onRegister(self)
  520. end
  521. function ChatProxy:Init()
  522. self._isChatting = false -- 聊天中...
  523. self._inputCache = {} -- 输入历史
  524. self._inputDraft = "" -- 输入草稿
  525. self._receiveCache = {} -- 聊天接收缓存
  526. self._receivePCCache= {}
  527. self._channel = self.CHANNEL.Near -- 当前频道
  528. self._receiveChannel= self.CHANNEL.Common -- 当前聊天记录频道
  529. self._emoji = {} -- 表情包
  530. self._targets = {} -- 私聊列表
  531. self._guildPercent = 50 -- 行会tips
  532. self._TargetName = "" -- 私聊名字
  533. self._local_chat = { -- 本地缓存数据
  534. autoShout = { -- 本地开关
  535. [tostring(self.CHANNEL.Shout)] = 0 -- 喊话
  536. },
  537. data = {
  538. [tostring(self.CHANNEL.Shout)] = "", -- 本地保存的喊话内容
  539. [tostring(self.CHANNEL.Private)] = "", -- 本地保存的私聊自动回复内容
  540. },
  541. autoRely = {
  542. [tostring(self.CHANNEL.Private)] = 0 -- 自动回复开关
  543. },
  544. channelSwitch = { -- 聊天接收开关
  545. },
  546. dropSwitch = {
  547. ["total"] = 1, -- 掉落总开关
  548. },
  549. }
  550. -- 聊天记录缓存
  551. for _, v in pairs(self.CHANNEL) do
  552. self._receiveCache[v] = {}
  553. self._receivePCCache[v] = {}
  554. end
  555. -- cd
  556. self._cdTime = {}
  557. for _, v in pairs(self.CHANNEL) do
  558. self._cdTime[v] = 0
  559. end
  560. local localChatData = self:getLocalChatData()
  561. -- 是否接收
  562. if not self._local_chat.channelSwitch then
  563. self._local_chat.channelSwitch = {}
  564. end
  565. self._receiving = {}
  566. for _, v in pairs(self.CHANNEL) do
  567. if v == self.CHANNEL.Drop then -- 仅掉落读取本地数据
  568. local data = localChatData and localChatData.channelSwitch
  569. self._local_chat.channelSwitch[v .. ""] = data and data[v ..""]
  570. end
  571. if self._local_chat.channelSwitch[v..""] == nil then
  572. self._receiving[v] = true
  573. else
  574. self._receiving[v] = self._local_chat.channelSwitch[v..""] == 1
  575. end
  576. end
  577. -- 掉落分类开关读本地数据
  578. if localChatData and localChatData.dropSwitch then
  579. self._local_chat.dropSwitch = localChatData.dropSwitch or {}
  580. end
  581. -- 自动喊话清理本地缓存数据
  582. self._local_chat.autoShout[tostring(self.CHANNEL.Shout)] = 0
  583. self._local_chat.data[tostring(self.CHANNEL.Shout)] = ""
  584. self:setLocalChatData()
  585. self._autoRelyList = {}
  586. self._autoRelyEnable = true
  587. -- PC私聊记录缓存 [聊天item]
  588. self._PCPrivateCache = {}
  589. -- 表情包配置
  590. self._emoji = FACE_CONFIG
  591. -- 固定聊天
  592. self._chatExItems = {}
  593. self._chatExId = 0
  594. -- 自动喊话间隔时间(s)
  595. self._autoShoutDelay = 20
  596. -- 是否关闭假掉落消息
  597. self._closeFakeDrop = false
  598. -- 私聊消息内容记录(最近十条)
  599. self._privateMsgCache = {}
  600. -- 自动喊话敏感词定时检测
  601. self._autoShoutSensitiveCheckScheduleID = nil
  602. end
  603. function ChatProxy:LoadConfig()
  604. -- 假掉落配置
  605. self._fakeDropMsgTable = {}
  606. local fileName = "cfg_chat_drop.lua"
  607. if global.FileUtilCtl:isFileExist("scripts/game_config/" .. fileName) then
  608. local config = requireGameConfig(fileName)
  609. if self._fakeDropMsgF then
  610. for _, v in ipairs(config) do
  611. local str = self._fakeDropMsgF
  612. -- 参数服务端转大写传
  613. if v.playerName then
  614. str = string.gsub(str, "%%CREATNAME", v.playerName)
  615. end
  616. if v.monsterName then
  617. str = string.gsub(str, "%%NAME", v.monsterName)
  618. end
  619. if v.mapName then
  620. str = string.gsub(str, "%%MAP", v.mapName)
  621. end
  622. if v.itemID then
  623. str = string.gsub(str, "%%ITEMID", v.itemID)
  624. end
  625. if v.itemName then
  626. str = string.gsub(str, "%%ITEM", v.itemName)
  627. end
  628. if v.g_itemName then
  629. str = string.gsub(str, "%%G_ITEM", v.g_itemName)
  630. end
  631. if v.mapX then
  632. str = string.gsub(str, "%%X", v.mapX)
  633. end
  634. if v.mapY then
  635. str = string.gsub(str, "%%Y", v.mapY)
  636. end
  637. table.insert(self._fakeDropMsgTable, str)
  638. end
  639. end
  640. end
  641. end
  642. function ChatProxy:SetFakeDropParam(param)
  643. self._fakeDropParam = param
  644. if param and param.Msg then
  645. -- 掉落格式配置
  646. self._fakeDropMsgF = param.Msg
  647. print(self._fakeDropMsgF)
  648. end
  649. end
  650. function ChatProxy:GetRandFakeDropParam()
  651. if self._fakeDropParam and next(self._fakeDropParam) and next(self._fakeDropMsgTable) then
  652. local idx = math.random(1, #self._fakeDropMsgTable)
  653. self._fakeDropParam.Msg = self._fakeDropMsgTable[idx]
  654. return self._fakeDropParam
  655. end
  656. return nil
  657. end
  658. function ChatProxy:OpenFakeDropTimerID()
  659. if not self._fakeDropMsgF then
  660. return
  661. end
  662. if not self:GetFakeDropShow() then
  663. return
  664. end
  665. if not self:GetDropTypeSwitch(FAKE_DROP_TYPE) then
  666. return
  667. end
  668. if not self._fakeDropTimerID then
  669. local function callback()
  670. local data = self:GetRandFakeDropParam()
  671. if data and next(data) then
  672. data.ChannelId = self.CHANNEL.Drop
  673. data.mt = self.MSG_TYPE.SRText
  674. data.dropType = FAKE_DROP_TYPE
  675. global.Facade:sendNotification(global.NoticeTable.AddChatItem, data)
  676. end
  677. end
  678. if self._needRandTime and self._fakeDropTimeLow and self._fakeDropTimeHigh then
  679. local time = math.random(self._fakeDropTimeLow, self._fakeDropTimeHigh)
  680. local function event()
  681. self._fakeDropTimerID = nil
  682. callback()
  683. local timeT = math.random(self._fakeDropTimeLow, self._fakeDropTimeHigh)
  684. self._fakeDropTimerID = PerformWithDelayGlobal(event, timeT / 1000)
  685. end
  686. self._fakeDropTimerID = PerformWithDelayGlobal(event, time / 1000)
  687. else
  688. self._fakeDropTimerID = Schedule(callback, self._fakeDropTime or 0.2)
  689. end
  690. end
  691. end
  692. function ChatProxy:CloseFakeDropTimerID()
  693. if self._fakeDropTimerID then
  694. UnSchedule(self._fakeDropTimerID)
  695. self._fakeDropTimerID = nil
  696. end
  697. end
  698. function ChatProxy:ChangeFakeDropTimerID(limitLowTimes, limitHighTimes)
  699. local isNeedOpen = false
  700. if self._fakeDropTimerID then
  701. isNeedOpen = true
  702. self:CloseFakeDropTimerID()
  703. end
  704. self._fakeDropTime = nil
  705. self._needRandTime = false
  706. if limitHighTimes == limitLowTimes then
  707. self._fakeDropTime = limitLowTimes / 1000
  708. else
  709. self._needRandTime = true
  710. self._fakeDropTimeLow = limitLowTimes
  711. self._fakeDropTimeHigh = limitHighTimes
  712. end
  713. if isNeedOpen then
  714. self:OpenFakeDropTimerID()
  715. end
  716. end
  717. function ChatProxy:IsCloseFakeDrop()
  718. return self._closeFakeDrop
  719. end
  720. --- 添加固定聊天数据
  721. ---@param data table 服务端下发的固定聊天数据
  722. function ChatProxy:AddChatExItemsData(data)
  723. table.insert(self._chatExItems, data)
  724. self._chatExId = self._chatExId + 1
  725. data.chatExId = self._chatExId
  726. end
  727. --- 移除固定聊天数据
  728. ---@param data table 固定聊天数据
  729. function ChatProxy:RemoveChatExItemsData(data, index)
  730. if not data then
  731. return
  732. end
  733. local chatExId = data.chatExId
  734. for i=1, index do
  735. if chatExId == (self._chatExItems[i] and self._chatExItems[i].chatExId) then
  736. table.remove(self._chatExItems, i)
  737. break
  738. end
  739. end
  740. end
  741. --- 同步固定聊天倒计时
  742. ---@param chatExId integer 自定义的唯一id
  743. ---@param value integer 倒计时
  744. function ChatProxy:SyncChatExItemsTime(index, chatExId, value )
  745. for i = 1, index do
  746. if chatExId == (self._chatExItems[i] and self._chatExItems[i].chatExId) then
  747. self._chatExItems[i].Time = value
  748. break
  749. end
  750. end
  751. end
  752. --- 获取固定聊天数据
  753. function ChatProxy:GetChatExItemsData()
  754. return self._chatExItems
  755. end
  756. function ChatProxy:ClearChatExItemsData()
  757. self._chatExItems = {}
  758. end
  759. -- 获取自动喊话时间间隔
  760. function ChatProxy:GetAutoShoutDelay()
  761. return self._autoShoutDelay or 20
  762. end
  763. -- 设置自动喊话时间间隔
  764. function ChatProxy:SetAutoShoutDelay(value)
  765. self._autoShoutDelay = value or 20
  766. end
  767. -- 启动自动喊话敏感词定时检测(每20分钟检测一次)
  768. function ChatProxy:StartAutoShoutSensitiveCheck()
  769. self:StopAutoShoutSensitiveCheck()
  770. local checkInterval = 1200
  771. self._autoShoutSensitiveCheckScheduleID = Schedule(function()
  772. self:CheckAutoShoutSensitiveWord()
  773. end, checkInterval)
  774. end
  775. -- 停止自动喊话敏感词定时检测
  776. function ChatProxy:StopAutoShoutSensitiveCheck()
  777. if self._autoShoutSensitiveCheckScheduleID then
  778. UnSchedule(self._autoShoutSensitiveCheckScheduleID)
  779. self._autoShoutSensitiveCheckScheduleID = nil
  780. end
  781. end
  782. -- 检测自动喊话内容是否包含敏感词
  783. function ChatProxy:CheckAutoShoutSensitiveWord()
  784. if not self:GetAutoShoutSwitch() then
  785. return
  786. end
  787. local channel = tostring(self.CHANNEL.Shout)
  788. local shoutContent = self:getLocalChatDataData(self.CHANNEL.Shout)
  789. if not shoutContent or shoutContent == "" then
  790. return
  791. end
  792. local SensitiveWordProxy = global.Facade:retrieveProxy(global.ProxyTable.SensitiveWordProxy)
  793. SensitiveWordProxy:IsHaveSensitiveTalkAddFilter(shoutContent, function(state, str, risk_param, ex_param)
  794. if not state then
  795. self:HandleAutoShoutSensitiveFound(channel)
  796. return
  797. end
  798. if risk_param and risk_param ~= 0 then
  799. self:HandleAutoShoutSensitiveFound(channel)
  800. return
  801. end
  802. if ex_param then
  803. if ex_param.status and ex_param.status ~= 0 then
  804. self:HandleAutoShoutSensitiveFound(channel)
  805. return
  806. end
  807. end
  808. end)
  809. end
  810. -- 处理检测到敏感词后的逻辑
  811. function ChatProxy:HandleAutoShoutSensitiveFound(channel)
  812. channel = channel or self.CHANNEL.Shout
  813. channel = tostring(channel)
  814. self._local_chat.data[channel] = ""
  815. self._local_chat.autoShout[channel] = 0
  816. self:setLocalChatData()
  817. self:StopAutoShoutSensitiveCheck()
  818. if global.isWinPlayMode then
  819. global.Facade:sendNotification(global.NoticeTable.Chat_Refresh_PC_AutoShout)
  820. else
  821. global.Facade:sendNotification(global.NoticeTable.Chat_Refresh_Mobile_AutoShout)
  822. end
  823. local data = {}
  824. data.str = GET_STRING(30001077)
  825. data.btnDesc = {GET_STRING(1001)}
  826. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  827. end
  828. function ChatProxy:GetChatParam()
  829. if not self._listInterval then
  830. local set = SL:GetMetaValue("GAME_DATA", "ChatShowInterval")
  831. local idx = global.isWinPlayMode and 2 or 1
  832. if set and string.len(set) > 0 then
  833. local setList = string.split(set, "|")
  834. local param = setList[idx] and string.split(setList[idx], "#")
  835. if param and next(param) then
  836. self._listInterval = tonumber(param[1])
  837. self._richVspace = tonumber(param[2])
  838. end
  839. end
  840. end
  841. return self._listInterval, self._richVspace
  842. end
  843. function ChatProxy:OnPlayerPropertyInited()
  844. -- cd, config by gamedata
  845. local chatCDS = SL:GetMetaValue("GAME_DATA","CHATCDS")
  846. if chatCDS and chatCDS ~= "" then
  847. local cdvec = string.split(chatCDS,"|")
  848. self.CDTIME = {
  849. [self.CHANNEL.System] = tonumber(cdvec[self.CHANNEL.System]) or 0, -- 系统
  850. [self.CHANNEL.Shout] = tonumber(cdvec[self.CHANNEL.Shout]), -- 世界
  851. [self.CHANNEL.Private] = tonumber(cdvec[self.CHANNEL.Private]), -- 私聊
  852. [self.CHANNEL.Guild] = tonumber(cdvec[self.CHANNEL.Guild]), -- 行会
  853. [self.CHANNEL.Team] = tonumber(cdvec[self.CHANNEL.Team]), -- 组队
  854. [self.CHANNEL.Near] = tonumber(cdvec[self.CHANNEL.Near]), -- 附近
  855. [self.CHANNEL.World] = tonumber(cdvec[self.CHANNEL.World]), -- 传音
  856. [self.CHANNEL.Nation] = tonumber(cdvec[self.CHANNEL.Nation]), -- 国家
  857. [self.CHANNEL.Union] = tonumber(cdvec[self.CHANNEL.Union]), -- 联盟
  858. [self.CHANNEL.Cross] = tonumber(cdvec[self.CHANNEL.Cross]), -- 跨服
  859. }
  860. end
  861. self:OpenFakeDropTimerID()
  862. end
  863. function ChatProxy:isCommand(msg)
  864. return self.SAY_MAPPING[msg] ~= nil
  865. end
  866. function ChatProxy:fixSay(msg)
  867. if not string.find(msg, "/") then
  868. return msg
  869. end
  870. return self.SAY_MAPPING[msg] or msg
  871. end
  872. -- 修复私聊名字后面有输入空格时 名字获取不正确问题
  873. function ChatProxy:fixPrivateChatMsg(findInfo)
  874. local name = string.trim(findInfo[3]) or ""
  875. local fStar, fEnd = string.find(name, " ")
  876. local content = ""
  877. if fStar and fEnd then
  878. content = string.sub(name, fEnd + 1, -1)
  879. name = string.sub(name, 1, fStar - 1)
  880. end
  881. content = content .. (findInfo[4] or "")
  882. return name, content
  883. end
  884. function ChatProxy:getChannelByMsg(msg)
  885. local channel = nil
  886. local content = msg
  887. for _, v in ipairs(self.CHANNEL_PREFIX) do
  888. local pattern = v.pattern or "^" .. v.prefix .. "(.+)"
  889. local find_info = { string.find(msg, pattern) }
  890. if find_info[1] and find_info[2] then
  891. channel = v.channel
  892. local rContent = find_info[3]
  893. if channel == ChatProxy.CHANNEL.Private then
  894. local frName, frContent = self:fixPrivateChatMsg(find_info)
  895. rContent = frContent
  896. end
  897. content = rContent
  898. break
  899. end
  900. end
  901. if not channel then -- 新增 /名字 直接私聊
  902. local find_info = { string.find(msg, "^/.+") }
  903. if find_info[1] and find_info[2] then
  904. channel = ChatProxy.CHANNEL.Private
  905. content = " "
  906. end
  907. end
  908. return channel, content
  909. end
  910. function ChatProxy:findTargetByMsg(msg)
  911. local pattern = nil
  912. local res = nil
  913. for _, value in pairs(self.CHANNEL_PREFIX) do
  914. if value.channel == self.CHANNEL.Private then
  915. pattern = value.pattern
  916. break
  917. end
  918. end
  919. if not pattern then
  920. res = nil
  921. else
  922. local find_info = { string.find(msg, pattern) }
  923. if find_info[1] and find_info[2] then
  924. local rName, rContent = self:fixPrivateChatMsg(find_info)
  925. res = rName
  926. end
  927. if not res then
  928. find_info = { string.find(msg, "^/(.+)") }
  929. if find_info[1] and find_info[2] then
  930. res = string.gsub(find_info[3], " ", "")
  931. end
  932. end
  933. end
  934. return res
  935. end
  936. function ChatProxy:getTargetName(data)
  937. return self._TargetName
  938. end
  939. function ChatProxy:setTargetName(name)
  940. self._TargetName = name
  941. end
  942. function ChatProxy:CheckAbleToSay(channel)
  943. if self.CHANNEL.Private == channel then
  944. -- 私聊
  945. if (not self:getTarget()) then
  946. ShowSystemTips(GET_STRING(30001024))
  947. return false
  948. end
  949. elseif self.CHANNEL.System == channel then
  950. -- 系统
  951. ShowSystemTips(GET_STRING(30001040))
  952. return false
  953. end
  954. -- cding
  955. if self:GetCDTime(channel) > 0 then
  956. ShowSystemTips(string.format(GET_STRING(30001023), self:GetCDTime(channel)))
  957. return false
  958. end
  959. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  960. local ret, buffid = BuffProxy:CheckChatEnable()
  961. if not ret then
  962. if buffid then
  963. local config = BuffProxy:GetConfigByID(buffid) or {}
  964. if config.bufftitle then
  965. ShowSystemTips(config.bufftitle)
  966. end
  967. end
  968. return false
  969. end
  970. return true
  971. end
  972. function ChatProxy:SetCDTime(channel, cd)
  973. self._cdTime[channel] = GetServerTime() + cd
  974. end
  975. function ChatProxy:GetCDTime(channel)
  976. return self._cdTime[channel] - GetServerTime()
  977. end
  978. function ChatProxy:GetCurrCDTime()
  979. local channel = self:getChannel()
  980. return self:GetCDTime(channel)
  981. end
  982. function ChatProxy:EnterCD(channel)
  983. local cdtime = self.CDTIME[channel] or 1
  984. self:SetCDTime(channel, cdtime)
  985. global.Facade:sendNotification(global.NoticeTable.Layer_Chat_EnterCD)
  986. end
  987. function ChatProxy:GetEmoji()
  988. return self._emoji
  989. end
  990. function ChatProxy:setChannel(channel)
  991. if channel == self.CHANNEL.Drop then
  992. channel = self.CHANNEL.Private
  993. end
  994. self._channel = channel
  995. end
  996. function ChatProxy:getChannel()
  997. return self._channel
  998. end
  999. function ChatProxy:setReceiveChannel(channel)
  1000. self._receiveChannel = channel
  1001. end
  1002. function ChatProxy:getReceiveChannel()
  1003. return self._receiveChannel
  1004. end
  1005. function ChatProxy:setIsChatting(status)
  1006. self._isChatting = status
  1007. end
  1008. function ChatProxy:isChatting()
  1009. return self._isChatting
  1010. end
  1011. function ChatProxy:setInputDraft(draft)
  1012. self._inputDraft = draft
  1013. end
  1014. function ChatProxy:getInputDraft(draft)
  1015. return self._inputDraft
  1016. end
  1017. function ChatProxy:addInputCache(input)
  1018. table.insert(self._inputCache, input)
  1019. if #self._inputCache > self.CONFIG.InputCacheCount then
  1020. table.remove(self._inputCache, 1)
  1021. end
  1022. end
  1023. function ChatProxy:getInputCache()
  1024. return self._inputCache
  1025. end
  1026. function ChatProxy:setReceiving(channel, status)
  1027. self._receiving[channel] = status
  1028. self._local_chat.channelSwitch[channel..""] = status and 1 or 0
  1029. self:setLocalChatData()
  1030. -- system tips
  1031. local receiveTips = {
  1032. [self.CHANNEL.System] = GET_STRING(30001063),
  1033. [self.CHANNEL.Shout] = GET_STRING(30001064),
  1034. [self.CHANNEL.Private] = GET_STRING(30001053),
  1035. [self.CHANNEL.Guild] = GET_STRING(30001055),
  1036. [self.CHANNEL.Team] = GET_STRING(30001057),
  1037. [self.CHANNEL.Near] = GET_STRING(30001059),
  1038. [self.CHANNEL.World] = GET_STRING(30001067),
  1039. }
  1040. local unreceiveTips = {
  1041. [self.CHANNEL.System] = GET_STRING(30001065),
  1042. [self.CHANNEL.Shout] = GET_STRING(30001066),
  1043. [self.CHANNEL.Private] = GET_STRING(30001054),
  1044. [self.CHANNEL.Guild] = GET_STRING(30001056),
  1045. [self.CHANNEL.Team] = GET_STRING(30001058),
  1046. [self.CHANNEL.Near] = GET_STRING(30001060),
  1047. [self.CHANNEL.World] = GET_STRING(30001068),
  1048. }
  1049. local tips = (status and receiveTips[channel] or unreceiveTips[channel])
  1050. if tips then
  1051. ShowSystemTips(tips)
  1052. end
  1053. end
  1054. function ChatProxy:isReceiving(channel)
  1055. if channel == self.CHANNEL.Common then
  1056. for k, v in pairs(self._receiving) do
  1057. if k ~= self.CHANNEL.Common and v then
  1058. return true
  1059. end
  1060. end
  1061. return false
  1062. end
  1063. return self._receiving[channel]
  1064. end
  1065. function ChatProxy:addTarget(target)
  1066. for k, v in pairs(self._targets) do
  1067. if v.uid == target.uid then
  1068. table.remove(self._targets, k)
  1069. break
  1070. end
  1071. end
  1072. table.insert(self._targets, 1, target)
  1073. if #self._targets > self.CONFIG.TargetCount then
  1074. table.remove(self._targets, #self._targets)
  1075. end
  1076. end
  1077. function ChatProxy:getTargets()
  1078. return self._targets
  1079. end
  1080. function ChatProxy:getTarget()
  1081. return self._targets[1]
  1082. end
  1083. function ChatProxy:getGuildPercent()
  1084. return self._guildPercent
  1085. end
  1086. function ChatProxy:setGuildPercent(percent)
  1087. self._guildPercent = percent
  1088. end
  1089. function ChatProxy:setLocalChatDataData(channel, data)
  1090. channel = tostring(channel)
  1091. if self._local_chat.data[channel] then
  1092. self._local_chat.data[channel] = data
  1093. self:setLocalChatData()
  1094. end
  1095. end
  1096. function ChatProxy:getLocalChatDataData(channel)
  1097. channel = tostring(channel)
  1098. if self._local_chat.data[channel] then
  1099. return self._local_chat.data[channel]
  1100. end
  1101. return nil
  1102. end
  1103. -- 获取聊天相关的本地缓存
  1104. function ChatProxy:getLocalChatData()
  1105. local localChatData = UserData:new("chat_local_cache")
  1106. local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  1107. local flag = proxy:GetSelectedRoleID() or "errorName"
  1108. local jsonData = localChatData:getStringForKey("chat" .. flag)
  1109. if not jsonData or jsonData == "" then
  1110. return nil
  1111. end
  1112. local lastJsonData = cjson.decode(jsonData)
  1113. return lastJsonData
  1114. end
  1115. -- 设置聊天相关的本地缓存
  1116. function ChatProxy:setLocalChatData()
  1117. local localChatData = UserData:new("chat_local_cache")
  1118. local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  1119. local flag = proxy:GetSelectedRoleID() or "errorName"
  1120. local jsonStr = cjson.encode(self._local_chat)
  1121. local clientData = localChatData:setStringForKey("chat" .. flag, jsonStr)
  1122. end
  1123. function ChatProxy:SetAutoReplySwitch(channel, value)
  1124. channel = channel or self.CHANNEL.Private
  1125. channel = tostring(channel)
  1126. self._local_chat.autoRely[channel] = value
  1127. self:setLocalChatData()
  1128. end
  1129. function ChatProxy:GetAutoReplySwitch(channel)
  1130. channel = channel or self.CHANNEL.Private
  1131. channel = tostring(channel)
  1132. if self._local_chat.autoRely[channel] then
  1133. return self._local_chat.autoRely[channel] == 1
  1134. end
  1135. return false
  1136. end
  1137. function ChatProxy:SetAutoShoutSwitch(channel, value)
  1138. channel = channel or self.CHANNEL.Shout
  1139. channel = tostring(channel)
  1140. self._local_chat.autoShout[channel] = value and 1 or 0
  1141. self:setLocalChatData()
  1142. -- 开启时启动敏感词定时检测,关闭时停止
  1143. if value then
  1144. self:StartAutoShoutSensitiveCheck()
  1145. else
  1146. self:StopAutoShoutSensitiveCheck()
  1147. end
  1148. end
  1149. function ChatProxy:GetAutoShoutSwitch(channel)
  1150. channel = channel or self.CHANNEL.Shout
  1151. channel = tostring(channel)
  1152. if self._local_chat.autoShout[channel] then
  1153. return self._local_chat.autoShout[channel] == 1
  1154. end
  1155. return false
  1156. end
  1157. function ChatProxy:GetFakeDropShow()
  1158. local fakeDrop = SL:GetMetaValue("GAME_DATA", "ShowFakeDropType")
  1159. if fakeDrop and string.len(fakeDrop) > 0 then
  1160. local param = string.split(fakeDrop, "#")
  1161. if param[2] and tonumber(param[2]) == 1 then
  1162. return true
  1163. end
  1164. end
  1165. return false
  1166. end
  1167. function ChatProxy:SetDropTypeSwitch(type, value)
  1168. local key = type ~= DROP_TOTAL_TYPE_ID and ("type" .. type) or "total"
  1169. self._local_chat.dropSwitch[key] = value and 1 or 0
  1170. if type ~= DROP_TOTAL_TYPE_ID then
  1171. local enable = false
  1172. local list = self:GetDropTypeShowList()
  1173. if self:GetFakeDropShow() then
  1174. list[FAKE_DROP_TYPE] = true
  1175. end
  1176. for i, show in pairs(list) do
  1177. if show then
  1178. if not self._local_chat.dropSwitch["type" .. i] then
  1179. self._local_chat.dropSwitch["type" .. i] = 1
  1180. end
  1181. if self._local_chat.dropSwitch["type" .. i] == 1 then
  1182. enable = true
  1183. break
  1184. end
  1185. end
  1186. end
  1187. self._local_chat.dropSwitch["total"] = enable and 1 or 0
  1188. end
  1189. self:setLocalChatData()
  1190. local GameSettingProxy = global.Facade:retrieveProxy(global.ProxyTable.GameSettingProxy)
  1191. GameSettingProxy:SyncDataToServer()
  1192. if type == FAKE_DROP_TYPE then
  1193. if self._local_chat.dropSwitch[key] == 1 then
  1194. self:OpenFakeDropTimerID()
  1195. else
  1196. self:CloseFakeDropTimerID()
  1197. end
  1198. end
  1199. end
  1200. function ChatProxy:GetDropTypeSwitch(type)
  1201. local key = type ~= DROP_TOTAL_TYPE_ID and ("type" .. type) or "total"
  1202. if self._local_chat.dropSwitch[key] then
  1203. return self._local_chat.dropSwitch[key] == 1
  1204. end
  1205. return true
  1206. end
  1207. function ChatProxy:GetDropTypeShowList()
  1208. if not self._showDropType then
  1209. local data = SL:GetMetaValue("GAME_DATA", "DropTypeShow")
  1210. self._showDropType = {}
  1211. if data and string.len(data) > 0 then
  1212. local tList = string.split(data, "|")
  1213. for i, v in ipairs(tList) do
  1214. local param1 = string.split(v, "#")
  1215. if tonumber(param1[2]) then
  1216. self._showDropType[tonumber(param1[2])] = param1[1] and tonumber(param1[1]) == 1
  1217. end
  1218. end
  1219. end
  1220. end
  1221. return self._showDropType
  1222. end
  1223. function ChatProxy:GetDropTypeShield()
  1224. local showList = self:GetDropTypeShowList()
  1225. local list = {}
  1226. local totalSwitch = self:GetDropTypeSwitch(DROP_TOTAL_TYPE_ID) --self:isReceiving(self.CHANNEL.Drop)
  1227. for i = 1, 10 do
  1228. local isOpen = self:GetDropTypeSwitch(i)
  1229. -- 类型1时代理未配置DropTypeShow 不屏蔽 [服务端处理bug需要特殊处理]
  1230. local showData = SL:GetMetaValue("GAME_DATA", "DropTypeShow")
  1231. if i == 1 and (not showData or showData == "") then
  1232. releasePrint("未配置掉落分类, 不屏蔽分类1.")
  1233. elseif not isOpen or not totalSwitch or not showList[i] then
  1234. table.insert(list, i)
  1235. end
  1236. end
  1237. return list
  1238. end
  1239. ---------------------------------- cache begin----------------------------------
  1240. function ChatProxy:getCache()
  1241. local channel = self:getReceiveChannel()
  1242. local banUIDs = self._needCheckUID and self._needCheckUID[channel]
  1243. if banUIDs and next(banUIDs) then
  1244. if next(self._receiveCache[channel]) then
  1245. for key = #self._receiveCache[channel], 1, -1 do
  1246. local v = self._receiveCache[channel][key]
  1247. for i = 1, #banUIDs do
  1248. local uid = banUIDs[i]
  1249. if uid and v and v.tag == uid then
  1250. local item = table.remove(self._receiveCache[channel], key)
  1251. item:autorelease()
  1252. end
  1253. end
  1254. end
  1255. end
  1256. self._needCheckUID[channel] = {}
  1257. end
  1258. return self._receiveCache[channel]
  1259. end
  1260. function ChatProxy:getDropCacheByType(type)
  1261. if not type or type == DROP_TOTAL_TYPE_ID then
  1262. return self._receiveCache[self.CHANNEL.Drop]
  1263. end
  1264. return self._receiveDropCache[type] or {}
  1265. end
  1266. function ChatProxy:storageItem(item, channel, dropType)
  1267. -- 保存至对应频道
  1268. local receiveCache = self._receiveCache[channel]
  1269. table.insert(receiveCache, item)
  1270. item:retain()
  1271. while #receiveCache > self.CONFIG.LimitCount do
  1272. local item = table.remove(receiveCache, 1)
  1273. item:autorelease()
  1274. end
  1275. -- 保存至公共频道
  1276. local receiveCache = self._receiveCache[self.CHANNEL.Common]
  1277. table.insert(receiveCache, item)
  1278. item:retain()
  1279. while #receiveCache > self.CONFIG.LimitCount do
  1280. local item = table.remove(receiveCache, 1)
  1281. item:autorelease()
  1282. end
  1283. end
  1284. function ChatProxy:releaseCache()
  1285. for _, cache in pairs(self._receiveCache) do
  1286. for _, v in pairs(cache) do
  1287. v:autorelease()
  1288. end
  1289. end
  1290. self._receiveCache = {}
  1291. for _, cache in pairs(self._receivePCCache) do
  1292. for _, v in pairs(cache) do
  1293. v:autorelease()
  1294. end
  1295. end
  1296. self._receivePCCache = {}
  1297. for _, v in pairs(self._PCPrivateCache) do
  1298. v:autorelease()
  1299. end
  1300. self._PCPrivateCache = {}
  1301. end
  1302. -- 私聊记录
  1303. function ChatProxy:storagePCPrivateItem(item, channel)
  1304. -- 保存
  1305. if not global.isWinPlayMode then return end
  1306. local cache = self._PCPrivateCache
  1307. table.insert(cache, item)
  1308. item:retain()
  1309. while #cache > self.CONFIG.LimitCountWin do
  1310. local item = table.remove(cache, 1)
  1311. item:autorelease()
  1312. end
  1313. end
  1314. function ChatProxy:getPCPrivateCache(...)
  1315. local banUIDs = self._pcPrivateCheckUID
  1316. if banUIDs and next(banUIDs) then
  1317. if next(self._PCPrivateCache) then
  1318. for key = #self._PCPrivateCache, 1, -1 do
  1319. local v = self._PCPrivateCache[key]
  1320. for i = 1, #banUIDs do
  1321. local uid = banUIDs[i]
  1322. if uid and v and v.tag == uid then
  1323. local item = table.remove(self._PCPrivateCache, key)
  1324. item:autorelease()
  1325. end
  1326. end
  1327. end
  1328. end
  1329. self._pcPrivateCheckUID = {}
  1330. end
  1331. return self._PCPrivateCache
  1332. end
  1333. -- PC Mini
  1334. function ChatProxy:getPCCache()
  1335. local channel = self:getReceiveChannel()
  1336. local banUIDs = self._needCheckUID and self._needCheckUID[channel]
  1337. if banUIDs and next(banUIDs) then
  1338. if next(self._receivePCCache[channel]) then
  1339. for key = #self._receivePCCache[channel], 1, -1 do
  1340. local v = self._receivePCCache[channel][key]
  1341. for i = 1, #banUIDs do
  1342. local uid = banUIDs[i]
  1343. if uid and v and v.tag == uid then
  1344. local item = table.remove(self._receivePCCache[channel], key)
  1345. item:autorelease()
  1346. end
  1347. end
  1348. end
  1349. end
  1350. self._needCheckUID[channel] = {}
  1351. end
  1352. return self._receivePCCache[channel]
  1353. end
  1354. function ChatProxy:storagePCItem(item, channel, dropType)
  1355. -- 保存至对应频道
  1356. local receiveCache = self._receivePCCache[channel]
  1357. table.insert(receiveCache, item)
  1358. item:retain()
  1359. while #receiveCache > self.CONFIG.LimitCount do
  1360. local item = table.remove(receiveCache, 1)
  1361. item:autorelease()
  1362. end
  1363. -- 保存至公共频道
  1364. local receiveCache = self._receivePCCache[self.CHANNEL.Common]
  1365. table.insert(receiveCache, item)
  1366. item:retain()
  1367. while #receiveCache > self.CONFIG.LimitCountWin do
  1368. local item = table.remove(receiveCache, 1)
  1369. item:autorelease()
  1370. end
  1371. end
  1372. -- 私聊消息内容记录(最近十条)
  1373. function ChatProxy:GetPrivateMsgCache()
  1374. return self._privateMsgCache
  1375. end
  1376. function ChatProxy:OnPushPrivateMsg(data)
  1377. data.FColor = data.FColor or 0
  1378. data.BColor = data.BColor or 255
  1379. -- receiving
  1380. if not self:isReceiving(data.ChannelId) then
  1381. return false
  1382. end
  1383. -- 黑名单
  1384. local FriendProxy = global.Facade:retrieveProxy(global.ProxyTable.FriendProxy)
  1385. if data.SendId and data.SendName and FriendProxy:isInBlacklist(data.SendId) then
  1386. return false
  1387. end
  1388. local limitCount = 10
  1389. if data.ChannelId == self.CHANNEL.Private then
  1390. table.insert(self._privateMsgCache, data)
  1391. while #self._privateMsgCache > limitCount do
  1392. table.remove(self._privateMsgCache, 1)
  1393. end
  1394. end
  1395. end
  1396. ---------------------------------- cache end----------------------------------
  1397. function ChatProxy:handle_MSG_SC_CHAT_SEND_RESULT(msg)
  1398. --[[参数1:
  1399. 1:发言时间未到(参数2:剩余秒数)
  1400. 2:发言等级不够(参数2:需要多少级)
  1401. 3: 没有行会
  1402. 4:没有队伍
  1403. 5:私聊对方不在线
  1404. 6:没有同盟
  1405. 7: 私聊限制(双方互为好友才可以发起私聊)
  1406. 8: 会员权限不够
  1407. ]]
  1408. local header = msg:GetHeader()
  1409. if header.recog == 1 then
  1410. global.Facade:sendNotification(global.NoticeTable.SystemTips, string.format(GET_STRING(30001023), header.param1))
  1411. elseif header.recog == 2 then
  1412. global.Facade:sendNotification(global.NoticeTable.SystemTips, string.format(GET_STRING(30001025), header.param1))
  1413. elseif header.recog == 3 then
  1414. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(30001022))
  1415. elseif header.recog == 4 then
  1416. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(30001021))
  1417. elseif header.recog == 5 then
  1418. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1016))
  1419. elseif header.recog == 6 then
  1420. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(30001032))
  1421. elseif header.recog == 7 then
  1422. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(30001037))
  1423. end
  1424. end
  1425. function ChatProxy:SendMsg(data)
  1426. dump(data, "SendMsg_____")
  1427. if data and data.sensitiveWords and not next(data.sensitiveWords) then
  1428. data.sensitiveWords = nil
  1429. end
  1430. data = self:fixLimitChatMsg(data)
  1431. local jsonStr = cjson.encode(data)
  1432. local contentType = 1
  1433. local content = jsonStr
  1434. local autoTips = true
  1435. local callbackCB = function(res)
  1436. if res and global.MMO.GAME_STATE_WORLD == GET_GAME_STATE() then
  1437. local sendStr, sendLen = Encode6BitBuf(jsonStr, string.len(jsonStr))
  1438. LuaSendMsg(global.MsgType.MSG_CS_PLAYER_SAY, 0, 0, 0, 0, sendStr, sendLen)
  1439. end
  1440. -- dump(res)
  1441. -- dump(jsonStr)
  1442. end
  1443. if data and data.mt == 1 then
  1444. REQUEST_TEXT_REVIEW(contentType, data and data.Msg or "", autoTips, callbackCB)
  1445. else
  1446. callbackCB(true) -- 装备 坐标不过滤
  1447. end
  1448. end
  1449. -- 设置chat的长度显示, 最大5000字
  1450. function ChatProxy:fixLimitChatMsg(data)
  1451. local MSG_MAX_LENGTH = 5000
  1452. if data and type(data.Msg) == "string" then
  1453. if data and string.utf8len(data.Msg or "") > MSG_MAX_LENGTH then
  1454. data.Msg = stringUTF8Sub(data.Msg, 1, MSG_MAX_LENGTH)
  1455. end
  1456. end
  1457. if data and type(data.oriMsg) == "string" then
  1458. if data and string.utf8len(data.oriMsg or "") > MSG_MAX_LENGTH then
  1459. data.oriMsg = stringUTF8Sub(data.oriMsg, 1, MSG_MAX_LENGTH)
  1460. end
  1461. end
  1462. return data
  1463. end
  1464. function ChatProxy:handle_MSG_SC_CHAT_MESSAGE(msg)
  1465. local jsonData = ParseRawMsgToJson(msg)
  1466. -- dump(jsonData,"handle_MSG_SC_CHAT_MESSAGE__")
  1467. if (not jsonData) then
  1468. return
  1469. end
  1470. jsonData.mt = tonumber(jsonData.mt) or self.MSG_TYPE.Normal
  1471. global.Facade:sendNotification(global.NoticeTable.AddChatItem, jsonData)
  1472. self:OnPushPrivateMsg(jsonData)
  1473. -- 附近聊天同步到玩家说话 --头顶的字除了正常字都不显示
  1474. if (jsonData.ChannelId == self.CHANNEL.Near or jsonData.ChannelId == self.CHANNEL.Shout)
  1475. and jsonData.SendId and (tonumber(jsonData.mt) == nil or tonumber(jsonData.mt) == self.MSG_TYPE.Normal) then
  1476. if self:isReceiving(jsonData.ChannelId) then
  1477. global.Facade:sendNotification(global.NoticeTable.ActorSay, jsonData)
  1478. end
  1479. end
  1480. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  1481. if global.isWinPlayMode and jsonData.ChannelId == self.CHANNEL.Private and jsonData.SendId and jsonData.SendId ~= mainPlayerID then
  1482. -- 是否自动回复
  1483. local autoContent = self:getLocalChatDataData(self.CHANNEL.Private)
  1484. if self:GetAutoReplySwitch(self.CHANNEL.Private) and autoContent and string.len(autoContent) > 0 then
  1485. table.insert(self._autoRelyList, { SendId = jsonData.SendId, SendName = jsonData.SendName, content = autoContent })
  1486. if self._autoRelyEnable then
  1487. self:CheckAutoReply()
  1488. end
  1489. end
  1490. end
  1491. if jsonData.ChannelId == self.CHANNEL.Private and jsonData.SendId and jsonData.SendId ~= mainPlayerID then
  1492. if global.isWinPlayMode then
  1493. local PrivateChatMediator = global.Facade:retrieveMediator("PrivateChatMediator")
  1494. if PrivateChatMediator and PrivateChatMediator._layer then
  1495. return
  1496. end
  1497. else
  1498. local ChatMediator = global.Facade:retrieveMediator("ChatMediator")
  1499. if ChatMediator and ChatMediator._layer and self._receiveChannel == self.CHANNEL.Private then
  1500. return
  1501. end
  1502. end
  1503. local FriendProxy = global.Facade:retrieveProxy(global.ProxyTable.FriendProxy)
  1504. if FriendProxy:isInBlacklist(jsonData.SendId) then
  1505. return
  1506. end
  1507. if not self:isReceiving(jsonData.ChannelId) then
  1508. return
  1509. end
  1510. local function callback()
  1511. if global.isWinPlayMode then
  1512. global.Facade:sendNotification(global.NoticeTable.Layer_Private_Chat_Open)
  1513. else
  1514. global.Facade:sendNotification(global.NoticeTable.Layer_Chat_Open, 3)
  1515. end
  1516. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, { id = 14, status = false })
  1517. end
  1518. local data = {}
  1519. data.id = 14
  1520. data.status = true
  1521. data.callback = callback
  1522. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  1523. end
  1524. end
  1525. function ChatProxy:CheckAutoReply()
  1526. if self._autoRelyEnable and next(self._autoRelyList) then
  1527. self._autoRelyEnable = false
  1528. local function autoReplyCB()
  1529. local item = table.remove(self._autoRelyList, 1)
  1530. if item and item.content and item.SendId and item.SendName then
  1531. local autoContent = item.content
  1532. local target = { uid = item.SendId, name = item.SendName }
  1533. self:addTarget(target)
  1534. local function toSendMsg(input, risk_param, ext_param)
  1535. local oriMsg = ext_param and ext_param.originStr
  1536. local sensitiveWords = ext_param and ext_param.replacedWords
  1537. local status = ext_param and ext_param.status
  1538. local sendData = {mt = self.MSG_TYPE.Normal, msg = input, channel = self.CHANNEL.Private, risk = risk_param, oriMsg = oriMsg, sensitiveWords = sensitiveWords, status = status}
  1539. global.Facade:sendNotification(global.NoticeTable.SendChatMsg, sendData)
  1540. self._autoRelyEnable = true
  1541. self:CheckAutoReply()
  1542. end
  1543. -- 敏感词
  1544. if not string.find(autoContent, "^@.-") then
  1545. local SensitiveWordProxy = global.Facade:retrieveProxy(global.ProxyTable.SensitiveWordProxy)
  1546. local function handle_Func(state, str, risk_param, ext_param)
  1547. if not str then
  1548. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1006))
  1549. self._autoRelyEnable = true
  1550. return
  1551. end
  1552. toSendMsg(str, risk_param, ext_param)
  1553. end
  1554. local data = {}
  1555. data.channel_id = self.CHANNEL.Private
  1556. if target then
  1557. local targetActor = global.actorManager:GetActor(target.uid)
  1558. data.to_role_level = targetActor and targetActor:GetLevel()
  1559. data.to_role_id = target.uid
  1560. data.to_role_name = target.name
  1561. end
  1562. SensitiveWordProxy:fixSensitiveTalkAddFilter(autoContent, handle_Func, nil, data)
  1563. end
  1564. end
  1565. end
  1566. if self:GetCDTime(self.CHANNEL.Private) > 0 then
  1567. PerformWithDelayGlobal(autoReplyCB, self:GetCDTime(self.CHANNEL.Private))
  1568. else
  1569. autoReplyCB()
  1570. end
  1571. end
  1572. end
  1573. --自动喊话时间
  1574. function ChatProxy:handle_SC_CHAT_AUTO_DELAY(msg)
  1575. local jsonData = ParseRawMsgToJson(msg)
  1576. if (not jsonData) then
  1577. return
  1578. end
  1579. local sayMsgCD = tonumber(jsonData.SayMsgCD)
  1580. if sayMsgCD and sayMsgCD > 0 then
  1581. sayMsgCD = sayMsgCD / 1000
  1582. end
  1583. self:SetAutoShoutDelay(sayMsgCD)
  1584. end
  1585. -- 通知开关假掉落
  1586. function ChatProxy:handle_MSG_SC_STOP_FAKE_DROP(msg)
  1587. local msgHdr = msg:GetHeader()
  1588. if msgHdr.recog == 0 then
  1589. self:CloseFakeDropTimerID()
  1590. self._closeFakeDrop = true
  1591. elseif msgHdr.recog == 1 then
  1592. if self:GetFakeDropShow() then
  1593. self:SetDropTypeSwitch(FAKE_DROP_TYPE, true)
  1594. local isReceiving = self:GetDropTypeSwitch(DROP_TOTAL_TYPE_ID)
  1595. self:setReceiving(self.CHANNEL.Drop, isReceiving)
  1596. end
  1597. self:OpenFakeDropTimerID()
  1598. self._closeFakeDrop = false
  1599. end
  1600. global.Facade:sendNotification(global.NoticeTable.ChatFakeDropChange)
  1601. end
  1602. -- 掉落消息参数
  1603. function ChatProxy:handle_MSG_SC_ITEM_DROP_MSG_NEW(msg)
  1604. local msgHdr = msg:GetHeader()
  1605. local jsonData = ParseRawMsgToJson(msg)
  1606. if (not jsonData) then
  1607. return
  1608. end
  1609. if not self._fakeDropMsgF then
  1610. releasePrint("error: server not send drop_msg_format!")
  1611. return
  1612. end
  1613. local mapX = msgHdr.recog
  1614. local mapY = msgHdr.param1
  1615. local itemID = msgHdr.param2
  1616. local dropType = msgHdr.param3
  1617. if dropType == 0 then
  1618. return
  1619. end
  1620. local param = jsonData.Params
  1621. local playerName = param[1] or ""
  1622. local monsterName = param[2] or ""
  1623. local mapName = param[3] or ""
  1624. local g_itemName = param[4] or ""
  1625. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  1626. local itemName = ItemConfigProxy:GetItemNameByIndex(itemID) or ""
  1627. local str = self._fakeDropMsgF
  1628. str = string.gsub(str, "%%CREATNAME", playerName)
  1629. str = string.gsub(str, "%%NAME", monsterName)
  1630. str = string.gsub(str, "%%MAP", mapName)
  1631. str = string.gsub(str, "%%ITEMID", itemID)
  1632. str = string.gsub(str, "%%ITEM", itemName)
  1633. str = string.gsub(str, "%%G_ITEM", g_itemName)
  1634. str = string.gsub(str, "%%X", mapX)
  1635. str = string.gsub(str, "%%Y", mapY)
  1636. local data = {
  1637. BColor = jsonData.BColor,
  1638. FColor = jsonData.FColor,
  1639. Msg = str,
  1640. ChannelId = self.CHANNEL.Drop,
  1641. mt = self.MSG_TYPE.SRText,
  1642. dropType = dropType
  1643. }
  1644. global.Facade:sendNotification(global.NoticeTable.AddChatItem, data)
  1645. end
  1646. function ChatProxy:handle_MSG_SC_FAKE_DROP_SPEED_UP(msg)
  1647. local msgHdr = msg:GetHeader()
  1648. dump(msgHdr)
  1649. local limitLowTimes = msgHdr.recog
  1650. local limitHighTimes = msgHdr.param1
  1651. self:ChangeFakeDropTimerID(limitLowTimes, limitHighTimes)
  1652. end
  1653. function ChatProxy:handle_MSG_SC_BAN_PLAYER_CHAT_RECORDS(msg)
  1654. local msgLen = msg:GetDataLength()
  1655. if msgLen <= 0 then
  1656. return
  1657. end
  1658. local uid = msg:GetData():ReadString(msgLen)
  1659. releasePrint(uid, "_ban_player_id")
  1660. self._needCheckUID = {}
  1661. for _, channel in pairs(self.CHANNEL) do
  1662. if not self._needCheckUID[channel] then
  1663. self._needCheckUID[channel] = {}
  1664. end
  1665. table.insert(self._needCheckUID[channel], uid)
  1666. end
  1667. if global.isWinPlayMode then
  1668. if not self._pcPrivateCheckUID then
  1669. self._pcPrivateCheckUID = {}
  1670. end
  1671. table.insert(self._pcPrivateCheckUID, uid)
  1672. end
  1673. if global.isWinPlayMode then
  1674. global.Facade:sendNotification(global.NoticeTable.Layer_Private_Chat_RemoveItem, uid)
  1675. else
  1676. global.Facade:sendNotification(global.NoticeTable.Layer_Chat_RemoveItem, uid)
  1677. end
  1678. global.Facade:sendNotification(global.NoticeTable.Layer_ChatMini_RemoveItem, uid)
  1679. end
  1680. function ChatProxy:RegisterMsgHandler()
  1681. end
  1682. --改为进入游戏世界之后再注册 有时候没进入世界就收到消息了
  1683. function ChatProxy:RegisterMsgHandlerAfterEnterWorld()
  1684. local msgType = global.MsgType
  1685. -- 收到消息
  1686. LuaRegisterMsgHandler(msgType.MSG_SC_CHAT_MESSAGE, handler(self, self.handle_MSG_SC_CHAT_MESSAGE))
  1687. -- 发送失败结果
  1688. LuaRegisterMsgHandler(msgType.MSG_SC_CHAT_SEND_RESULT, handler(self, self.handle_MSG_SC_CHAT_SEND_RESULT))
  1689. --自动喊话时间
  1690. LuaRegisterMsgHandler(msgType.MSG_SC_CHAT_AUTO_DELAY, handler(self, self.handle_SC_CHAT_AUTO_DELAY))
  1691. -- 移除假掉落
  1692. LuaRegisterMsgHandler(msgType.MSG_SC_STOP_FAKE_DROP, handler(self, self.handle_MSG_SC_STOP_FAKE_DROP))
  1693. -- 物品掉落消息
  1694. LuaRegisterMsgHandler(msgType.MSG_SC_ITEM_DROP_MSG_NEW, handler(self, self.handle_MSG_SC_ITEM_DROP_MSG_NEW))
  1695. -- 假掉落速度改变
  1696. LuaRegisterMsgHandler(msgType.MSG_SC_FAKE_DROP_SPEED_UP, handler(self, self.handle_MSG_SC_FAKE_DROP_SPEED_UP))
  1697. -- 封禁玩家消息
  1698. LuaRegisterMsgHandler(msgType.MSG_SC_BAN_PLAYER_CHAT_RECORDS, handler(self, self.handle_MSG_SC_BAN_PLAYER_CHAT_RECORDS))
  1699. end
  1700. return ChatProxy