Handler.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. local Log = require("common.Log")
  2. local Lang = require("common.Lang")
  3. local Json = require("common.Json")
  4. local Msg = require("core.Msg")
  5. local Timer = require("core.Timer")
  6. local Util = require("common.Util")
  7. local ChatBan = require("chat.ChatBan")
  8. local ChatRecord = require("chat.ChatRecord")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local ChatLogic = require("chat.ChatLogic")
  11. local CombatVideo = require("combat.CombatVideo")
  12. local Define = require("platform.Define")
  13. local HeroExcel = require("excel.hero")
  14. local RoleLogic = require("role.RoleLogic")
  15. local CharRecord = require("chat.ChatRecord")
  16. -- 聊天频道
  17. CHAT_TYPE_WORLD = 1 --世界
  18. CHAT_TYPE_SYSTEM = 2 --系统
  19. CHAT_TYPE_UNION = 3 --工会
  20. CHAT_TYPE_FRIEND = 4 --好友私聊
  21. CHAT_TYPE_MIDDLE = 5 --跨服
  22. CHAT_TYPE_CNT = 5 --聊天频道数
  23. -- isJson值
  24. CHAT_NORMAL = 0 -- 普通聊天
  25. CHAT_UNION_FIGHT = 1 -- 公会战
  26. CHAT_UNION_ECTYPE = 2 -- 公会副本
  27. CHAT_UNION_RED_BAG = 3 -- 公会红包
  28. CHAT_UNION_ZHAOMU = 4 -- 公会招募
  29. CHAT_HERO_SHARE = 5 -- 英雄聊天分享
  30. CHAT_FIGHT_SHARE = 6 -- 战斗记录聊天分享
  31. CHAT_ITEM_SHARE = 7 -- 道具聊天分享
  32. CHAT_SHARE_TYPE = 1 -- 战报分享
  33. CHAT_LV_NEED_WORLD = 20 -- 开放聊天等级
  34. CHAT_LV_NEED_MIDDLE = 50 -- 开放聊天等级
  35. CHAT_LV_NEED_FRIEND = 30 -- 开放聊天等级
  36. CHAT_CD = 10000 -- 聊天cd时间
  37. CHAT_MSG_LEN = 90
  38. function chatReport(human, content)
  39. s2aParam = {}
  40. s2aParam.role_name = human.db.name
  41. s2aParam.account_name = human.db.account
  42. s2aParam.content = content or ""
  43. s2aParam.ip = human.db.ip
  44. _G.thread_http.send(Define.CHAT_REPORT,Json.Encode(s2aParam))
  45. Log.write(Log.LOGID_DEBUG, "chatReportSuccrss"..Define.CHAT_REPORT)
  46. end
  47. function CG_CHAT_REPORT(human, msg)
  48. chatReport(human, msg.content)
  49. end
  50. function CG_CHAT(human, msg)
  51. local strLen = string.len(msg.msg)
  52. -- 普通聊天限制字数
  53. if CHAT_MSG_LEN < strLen and msg.isJson == CHAT_NORMAL then
  54. return Broadcast.sendErr(human, Lang.CHAT_MSG_LEN_ERR)
  55. end
  56. ChatLogic.chat(human, msg, msg.isJson)
  57. end
  58. function onLogin(human)
  59. ChatRecord.initHumanChatRead(human)
  60. ChatBan.sendBanList(human)
  61. end
  62. function CG_CHAT_BAN(human, msg)
  63. ChatBan.setBan(human, msg.uuid, msg.op)
  64. end
  65. function CG_CHAT_PLAYER_INFO(human, msg)
  66. local msgRet = Msg.gc.GC_CHAT_PLAYER_INFO
  67. if not RoleLogic.makePlayInfo(msgRet.data, msg.uuid) then
  68. return
  69. end
  70. Msg.send(msgRet, human.fd)
  71. end
  72. function CG_CHAT_HERO_SHARE(human,msg)
  73. local bagIndex = msg.bagIndex
  74. local heroGrid = human.db.heroBag[bagIndex]
  75. if not heroGrid then
  76. return
  77. end
  78. local heroConfig = HeroExcel.hero[heroGrid.id]
  79. if heroConfig == nil then
  80. return
  81. end
  82. msg.videoUuid = ""
  83. ChatLogic.chat(human, msg,CHAT_HERO_SHARE)
  84. end
  85. --战斗界面 战斗记录分享
  86. function CG_CHAT_COMBAT_SHARE(human, msg)
  87. if msg.msgType ~= CHAT_TYPE_WORLD and msg.msgType ~= CHAT_TYPE_UNION and msg.msgType ~= CHAT_TYPE_MIDDLE then
  88. return
  89. end
  90. -- 如果是分享在世界上检测是否在聊天CD 中
  91. if msg.msgType == CHAT_TYPE_WORLD and human.worldChatTime and human.worldChatTime + CHAT_CD > Timer.now then
  92. local cdLeftSec = math.ceil((CHAT_CD - (Timer.now - human.worldChatTime))/1000)
  93. Broadcast.sendDown(human, Util.format(Lang.CHAT_TIME_SHORT, cdLeftSec))
  94. return
  95. end
  96. if msg.msgType == CHAT_TYPE_UNION and human.db.unionUuid == nil then
  97. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  98. end
  99. local content = {}
  100. content.msg = msg.msg
  101. content.msgType = msg.msgType
  102. if msg.shareType ~= CHAT_SHARE_TYPE then
  103. local combatInfo = Util.copyTable(human.combat)
  104. if combatInfo == nil then
  105. return
  106. end
  107. local videoUuid = human.combat.videoUuid
  108. if not videoUuid then
  109. videoUuid = CombatVideo.saveCombatVideo(human, true)
  110. end
  111. if not videoUuid then
  112. return Broadcast.sendErr(human, Lang.SHARE_ERROR)
  113. end
  114. content.videoUuid = videoUuid
  115. end
  116. local flag = ChatLogic.chat(human,content,CHAT_FIGHT_SHARE)
  117. if flag == true then
  118. Broadcast.sendErr(human, Lang.SHARE_SUCCESS)
  119. else
  120. Broadcast.sendErr(human, Lang.SHARE_ERROR)
  121. end
  122. end
  123. function CG_CHAT_COMPLAIN_PLAYER(human,msg)
  124. ChatBan.jubaoChat(human,msg)
  125. end
  126. -- 获取聊天记录
  127. function CG_CHAT_RECORD_QUERY(human,msg)
  128. CharRecord.getChatRecord(human,msg.msgType)
  129. end
  130. -- 获取私聊列表
  131. function CG_CHAT_FRIEND_RECORD_QUERY(human)
  132. CharRecord.getChatFriendList(human)
  133. end
  134. --根据uuid获取私聊记录
  135. function CG_CHAT_FRIEND_RECORD_BY_FRIEND(human,msg)
  136. CharRecord.getChatFriendRecord(human,msg.uuid)
  137. end
  138. -- 新增私聊
  139. function CG_CHAT_FRIEND_RECORD_ADD(human,msg)
  140. CharRecord.addFriendChat(human,msg.uuid)
  141. end
  142. -- 删除玩家私聊数据
  143. function CG_CHAT_FRIEND_RECORD_DEL(human,msg)
  144. CharRecord.delFriendChatRecord(human,msg.uuid)
  145. end