ChatLogic.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. local Msg = require("core.Msg")
  2. local ChatHandler = require("chat.Handler")
  3. local VipLogic = require("vip.VipLogic")
  4. local Log = require("common.Log")
  5. local FilterUtil = require("common.FilterUtil")
  6. local Gm = require("chat.Gm")
  7. local ChatRecord = require("chat.ChatRecord")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local UnionDBLogic = require("union.UnionDBLogic")
  10. local UnionLogic = require("union.UnionLogic")
  11. local Timer = require("core.Timer")
  12. local Lang = require("common.Lang")
  13. local Util = require("common.Util")
  14. local RoleLogic = require("role.RoleLogic")
  15. local FriendDBLogic = require("friend.FriendDBLogic")
  16. local Config = require("Config")
  17. local RoleDBLogic = require("role.RoleDBLogic")
  18. local SettingLogic = require("setting.SettingLogic")
  19. local ObjHuman = require("core.ObjHuman")
  20. local InnerMsg = require("core.InnerMsg")
  21. function chat(human, recvMsg, isJson)
  22. if Gm.checkGm(human, recvMsg.msg) then
  23. return
  24. end
  25. --累充金额判断
  26. local topupAcount = human.db.topupAcount or 0
  27. if topupAcount < ChatHandler.CHATLIMITMONEY then
  28. local str = Util.format(Lang.CHAT_NEED_TOTAL_MONEY, ChatHandler.CHATLIMITMONEY, topupAcount)
  29. Broadcast.sendErr(human, str)
  30. return
  31. end
  32. isJson = isJson or ChatHandler.CHAT_NORMAL
  33. --世界聊天限制等级
  34. if recvMsg.msgType == ChatHandler.CHAT_TYPE_WORLD then
  35. if human.db.lv < ChatHandler.CHAT_LV_NEED_WORLD and VipLogic.getVipLv(human) == 0 then
  36. local str = Util.format(Lang.CHAT_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_WORLD)
  37. Broadcast.sendDown(human, str)
  38. return
  39. end
  40. end
  41. -- 跨服聊天限制等级
  42. if recvMsg.msgType == ChatHandler.CHAT_TYPE_MIDDLE then
  43. if human.db.lv < ChatHandler.CHAT_LV_NEED_MIDDLE and VipLogic.getVipLv(human) == 0 then
  44. local str = Util.format(Lang.CHAT_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_MIDDLE)
  45. Broadcast.sendDown(human, str)
  46. return
  47. end
  48. end
  49. -- 好友私聊
  50. if recvMsg.msgType == ChatHandler.CHAT_TYPE_FRIEND then
  51. -- 聊天权限判断
  52. if human.db.lv < ChatHandler.CHAT_LV_NEED_FRIEND and VipLogic.getVipLv(human) == 0 then
  53. local str = Util.format(Lang.CHAT_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_FRIEND)
  54. Broadcast.sendDown(human, str)
  55. return
  56. end
  57. -- 是否互为好友
  58. local isFriend = FriendDBLogic.isFriend(human.db._id, recvMsg.fUuid)
  59. if isFriend ~= true then
  60. return Broadcast.sendDown(human, Lang.CHAT_ERR_NOT_FIREND)
  61. end
  62. local db = RoleDBLogic.getDb(recvMsg.fUuid, fields)
  63. local tempHuman = {}
  64. tempHuman.db = db
  65. local cantPrivate = SettingLogic.isNoPrivateChat(tempHuman)
  66. if cantPrivate == true then
  67. return Broadcast.sendDown(human, Lang.CHAT_ERR_CNT_FIREND)
  68. end
  69. end
  70. --判定是否被禁言
  71. if human.db.banSayTime and (os.time() < human.db.banSayTime or human.db.banSayTime == -1) then
  72. local leftMin = math.ceil((human.db.banSayTime - os.time())/60)
  73. local content = Util.format(human.db.banSayReason,leftMin)
  74. Broadcast.sendErr(human, content)
  75. return
  76. end
  77. human.db.banSay = nil
  78. human.db.banSayTime = nil
  79. Log.write(Log.LOGID_OSS_CHAT, human.db._id, human.db.account, human.db.name, human.db.ip, recvMsg.msgType, recvMsg.msg)
  80. -- 发送聊天数据
  81. local msgRet = Msg.gc.GC_CHAT
  82. if SettingLogic.isNoShowVip(human) == true then
  83. msgRet.item.vipLv = VipLogic.getVipLv(human)
  84. if msgRet.item.vipLv > 0 and msgRet.item.vipLv < 14 then
  85. msgRet.item.vipLv = -1
  86. end
  87. else
  88. msgRet.item.vipLv = VipLogic.getVipLv(human)
  89. end
  90. -- 获取服务器名
  91. msgRet.item.svrName = Config.SVR_NAME
  92. -- 角色信息
  93. RoleLogic.getRoleBase(human,msgRet.item.roleBase)
  94. -- 称号
  95. msgRet.item.label = human.db.chenghao or 0
  96. -- 聊天内容
  97. if isJson > ChatHandler.CHAT_NORMAL then
  98. msgRet.item.msg = recvMsg.msg
  99. else
  100. msgRet.item.msg = FilterUtil.filter(recvMsg.msg)
  101. end
  102. msgRet.item.msgType = recvMsg.msgType
  103. msgRet.item.isJson = isJson
  104. msgRet.item.sendTime = os.time()
  105. msgRet.item.videoUuid = recvMsg.videoUuid or ""
  106. -- 频道上次发言时间
  107. human.chatTime = human.chatTime or {}
  108. local chatTime = human.chatTime[recvMsg.msgType] or 0
  109. if recvMsg.msgType == ChatHandler.CHAT_TYPE_WORLD or
  110. recvMsg.msgType == ChatHandler.CHAT_TYPE_MIDDLE then --世界聊天
  111. --世界聊天
  112. -- 判断上次发言时间
  113. if chatTime and chatTime + ChatHandler.CHAT_CD > Timer.now then
  114. local cdLeftSec = math.ceil((ChatHandler.CHAT_CD - (Timer.now - chatTime))/1000)
  115. Broadcast.sendDown(human, Util.format(Lang.CHAT_TIME_SHORT, cdLeftSec))
  116. return
  117. end
  118. -- 不是战斗记录的情况下,判断是否重复发消息
  119. if (recvMsg.videoUuid == nil or
  120. recvMsg.videoUuid == "") and
  121. human.worldChatLast and
  122. human.worldChatLast[recvMsg.msgType] and
  123. human.worldChatLast[recvMsg.msgType] == msgRet.item.msg then
  124. Broadcast.sendDown(human, Lang.CHAT_TIME_DUPLICATE)
  125. return
  126. end
  127. human.worldChatLast = human.worldChatLast or {}
  128. human.worldChatLast[recvMsg.msgType] = msgRet.item.msg
  129. human.chatTime[recvMsg.msgType] = Timer.now
  130. -- 跨服
  131. if recvMsg.msgType == ChatHandler.CHAT_TYPE_MIDDLE then
  132. -- 发送数据到中心服
  133. local lwMsgRet = InnerMsg.lw.LW_MIDDLE_CHAT
  134. lwMsgRet.msg = msgRet
  135. InnerMsg.sendMsg(0, lwMsgRet)
  136. else
  137. Msg.sendWorld(msgRet)
  138. ChatRecord.addRecord(human,msgRet.item, recvMsg.msgType)
  139. end
  140. elseif recvMsg.msgType == ChatHandler.CHAT_TYPE_UNION then
  141. --公会聊天
  142. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  143. if not union then
  144. Broadcast.sendDown(human, Lang.CHAT_NEED_JOIN_UNION)
  145. return
  146. end
  147. -- if msgRet.item.isJson > ChatHandler.CHAT_NORMAL then
  148. -- Broadcast.sendDown(human, Lang.SHARE_SUCCESS)
  149. -- end
  150. UnionLogic.send2Union(msgRet, union)
  151. --ChatRecord.addUnionRecord(msgRet.item, human.db.unionUuid)
  152. ChatRecord.addRecord(human,msgRet.item, recvMsg.msgType)
  153. else
  154. -- 其他聊天
  155. if chatTime and chatTime + ChatHandler.CHAT_CD > Timer.now then
  156. local cdLeftSec = math.ceil((ChatHandler.CHAT_CD - (Timer.now - chatTime))/1000)
  157. Broadcast.sendDown(human, Util.format(Lang.CHAT_TIME_SHORT, cdLeftSec))
  158. return
  159. end
  160. human.chatTime[recvMsg.msgType] = Timer.now
  161. -- 好友特殊发送
  162. if recvMsg.msgType == ChatHandler.CHAT_TYPE_FRIEND then
  163. local fHuman = ObjHuman.onlineUuid[recvMsg.fUuid]
  164. if fHuman and fHuman.fd then
  165. Msg.send(msgRet, fHuman.fd)
  166. end
  167. Msg.send(msgRet, human.fd)
  168. ChatRecord.addRecord(human,msgRet.item, recvMsg.msgType,recvMsg.fUuid)
  169. else
  170. Msg.sendWorld(msgRet)
  171. ChatRecord.addRecord(human,msgRet.item, recvMsg.msgType)
  172. end
  173. end
  174. -- 上报消息到后台
  175. ChatHandler.chatReport(human,recvMsg.msg)
  176. return true
  177. end
  178. function sendChatByTestGm(human)
  179. local str = "test chat okokok"
  180. chat(human, {msgType = ChatHandler.CHAT_TYPE_WORLD,msg = str},false, false)
  181. end
  182. function getCombatName(combatType, name)
  183. return Util.format(Lang.COMBAT_CHAT_MSG, name)
  184. end
  185. function isDot(human)
  186. if ChatRecord.CHAT_RECORD_FRIEND[human.db._id] and ChatRecord.CHAT_RECORD_FRIEND[human.db._id].count ~= 0 then
  187. return true
  188. end
  189. end