ChatBan.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. local Lang = require("common.Lang")
  2. local Msg = require("core.Msg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local RoleDBLogic = require("role.RoleDBLogic")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local LuaMongo = _G.lua_mongo
  7. local DB = require("common.DB")
  8. BAN_LIST_MAX_CNT = 20 -- 最多屏蔽20人
  9. fields = {name = 1, lv = 1}
  10. function setBan(human, uuid, op)
  11. --自己返回掉
  12. if human.db._id == uuid then
  13. Broadcast.sendErr(human, Lang.CHAT_BAN_NOT_SET_SELF)
  14. return
  15. end
  16. human.db.chatBan = human.db.chatBan or {}
  17. --1屏蔽 0解除屏蔽
  18. if op == 1 then
  19. for i = 1, #human.db.chatBan do
  20. if human.db.chatBan[i].uuid == uuid then
  21. return
  22. end
  23. end
  24. local target = RoleDBLogic.getDb(uuid, fields)
  25. if target == nil then
  26. return
  27. end
  28. human.db.chatBan[#human.db.chatBan + 1] = uuid
  29. for i = 1, 100 do
  30. if #human.db.chatBan > BAN_LIST_MAX_CNT then
  31. table.remove(human.db.chatBan, 1)
  32. else
  33. break
  34. end
  35. end
  36. Broadcast.sendErr(human, Lang.CHAT_BAN_SET)
  37. elseif op == 0 then
  38. local index = nil
  39. for i = 1, #human.db.chatBan do
  40. if human.db.chatBan[i] == uuid then
  41. index = i
  42. break
  43. end
  44. end
  45. if index == nil then
  46. return
  47. end
  48. table.remove(human.db.chatBan, index)
  49. Broadcast.sendErr(human, Lang.CHAT_BAN_UNSET)
  50. else
  51. return
  52. end
  53. sendBanList(human)
  54. end
  55. function sendBanList(human)
  56. local msgRet = Msg.gc.GC_CHAT_BAN_LIST
  57. if human.db.chatBan == nil then
  58. msgRet.banList[0] = 0
  59. else
  60. msgRet.banList[0] = #human.db.chatBan
  61. for i = 1, #human.db.chatBan do
  62. local tempUuid = human.db.chatBan[i]
  63. msgRet.banList[i].uuid = tempUuid
  64. end
  65. end
  66. Msg.send(msgRet, human.fd)
  67. end
  68. function jubaoChat(human,msg)
  69. local fakeHuman = ObjHuman.onlineUuid[msg.uuid]
  70. local db = nil
  71. if fakeHuman ~= nil then
  72. db = fakeHuman.db
  73. else
  74. db = RoleDBLogic.getDb(msg.uuid,{banSay = 1,banSayTime = 1,banSayReason = 1})
  75. end
  76. if db == nil then
  77. return
  78. end
  79. if db.banSayTime and os.time() > db.banSayTime and db.banSayTime ~= -1 then
  80. db.banSay = nil
  81. db.banSayTime = nil
  82. end
  83. if db.banSay ~= nil and db.banSay.flag ~= nil and db.banSay.flag == 1 then
  84. return
  85. end
  86. db.banSay = db.banSay or {}
  87. db.banSay.array = db.banSay.array or {}
  88. local len = #db.banSay.array
  89. -- 处理一下老unionID
  90. for i = 1,len do
  91. if db.banSay.array[i].unionID ~= nil then
  92. db.banSay.array[i].unionID = nil
  93. db.banSay.array[i].unionUuid = ""
  94. end
  95. end
  96. for i = 1,len do
  97. if db.banSay.array[i].uuid == human.db._id then
  98. return
  99. end
  100. end
  101. local now = os.time()
  102. db.banSay.array[len + 1] = {}
  103. db.banSay.array[len + 1].uuid = human.db._id
  104. db.banSay.array[len + 1].unionUuid = human.db.unionUuid or ""
  105. db.banSay.array[len + 1].time = now
  106. db.banSay.flag = 0
  107. if len + 1 >= 5 then
  108. if db.banSay.array[len + 1 - 5 + 1].time >= now - 10*60 then
  109. db.banSay.flag = 1
  110. end
  111. else
  112. local unionCnt = {}
  113. local lenth = #unionCnt
  114. local isBreak = 0
  115. for i = 1, len + 1 do
  116. local config = db.banSay.array
  117. if i == 1 then
  118. if config[i].time >= now - 1*60 then
  119. lenth = lenth + 1
  120. unionCnt[lenth] = {}
  121. unionCnt[lenth].cnt = 1
  122. unionCnt[lenth].id = config[i].unionUuid
  123. end
  124. else
  125. for j = 1,lenth do
  126. if config[i].time >= now - 1*60 then
  127. if config[i].unionUuid == unionCnt[j].id then
  128. unionCnt[j].cnt = unionCnt[j].cnt + 1
  129. else
  130. lenth = lenth + 1
  131. unionCnt[lenth] = {}
  132. unionCnt[lenth].cnt = 1
  133. unionCnt[lenth].id = config[i].unionUuid
  134. if lenth >= 3 then
  135. db.banSay.flag = 1
  136. isBreak = 1
  137. break
  138. end
  139. end
  140. end
  141. end
  142. end
  143. if isBreak == 1 then
  144. break
  145. end
  146. end
  147. end
  148. local banTime = nil
  149. if db.banSay.flag == 1 then
  150. banTime = os.time() + 60*60
  151. db.banSayReason = Lang.CHAT_BAN_REASON_JUBAO
  152. end
  153. if db.banSayTime == nil or db.banSayTime == -1 then
  154. db.banSayTime = banTime
  155. end
  156. if fakeHuman == nil then
  157. local QueryCharByUuid = {}
  158. QueryCharByUuid._id = db._id
  159. local update = {}
  160. update.banSay = db.banSay
  161. update.banSayTime = db.banSayTime
  162. update.banSayReason = db.banSayReason
  163. local tbTemp = {}
  164. tbTemp["$set"] = update
  165. LuaMongo.update(DB.db_char,QueryCharByUuid,tbTemp)
  166. end
  167. Broadcast.sendErr(human, Lang.CHAT_BAN_JUBAO_SUCCESS)
  168. end
  169. function initAfterHot()
  170. local update = {}
  171. update.banSay = 1
  172. update.banSayTime = 1
  173. update.banSayReason = ""
  174. local tbTemp = {}
  175. tbTemp["$unset"] = update
  176. LuaMongo.update(DB.db_char,{},tbTemp,2)
  177. end