RoleDel.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. local DB = require("common.DB")
  2. local LuaMongo = _G.lua_mongo
  3. local Lang = require("common.Lang")
  4. local Util = require("common.Util")
  5. local RoleDBLogic = require("role.RoleDBLogic")
  6. local Log = require("common.Log")
  7. local LogDefine = require("common.LogDefine")
  8. local RoleList = {}
  9. local function delRoles()
  10. _G.collectgarbage("step", 1000000)
  11. LuaMongo.find(DB.db_char, nil, {lastLoginTime = 1, lastLogoutTime = 1, lv = 1, zuanshi = 1, buy = 1, account = 1})
  12. local list = {}
  13. RoleList = {}
  14. local allCnt = 0
  15. local delCnt = 0
  16. local nowTime = _G.real_os_time()
  17. while true do
  18. local data = {}
  19. if not LuaMongo.next(data) then
  20. break
  21. end
  22. allCnt = allCnt + 1
  23. -- 离线时间
  24. local lastLoginTime = data.lastLoginTime or 0
  25. local logoutTime = 0
  26. if data.lastLogoutTime then
  27. logoutTime = nowTime - math.max(data.lastLogoutTime, data.lastLoginTime)
  28. else
  29. logoutTime = nowTime - lastLoginTime
  30. end
  31. RoleList[data._id] = data.account
  32. -- 1级1天无登录 2级2天无登录 3-15级 20天无登录 16-30 30天无登录 无充值
  33. local maxLogoutTime = nil
  34. if data.lv == 1 then
  35. maxLogoutTime = 86400
  36. elseif data.lv == 2 then
  37. maxLogoutTime = 2 * 86400
  38. elseif data.lv <= 15 then
  39. maxLogoutTime = 20 * 86400
  40. elseif data.lv <= 30 then
  41. maxLogoutTime = 30 * 86400
  42. end
  43. if maxLogoutTime
  44. and (not data.buy or Util.getTableCount(data.buy) == 0)
  45. and maxLogoutTime < logoutTime
  46. then
  47. list[delCnt + 1] = data._id
  48. RoleList[data._id] = nil
  49. delCnt = delCnt + 1
  50. end
  51. end
  52. _G.collectgarbage("step", 1000000)
  53. print("delRole", delCnt, "/", allCnt)
  54. local query = {}
  55. for _, v in ipairs(list) do
  56. query._id = v
  57. LuaMongo.remove(DB.db_char, query)
  58. end
  59. _G.collectgarbage("step", 1000000)
  60. end
  61. local function handleFriend()
  62. -- 好友
  63. local delList = {}
  64. LuaMongo.find(DB.db_friend, nil)
  65. while true do
  66. local data = {}
  67. if not LuaMongo.next(data) then
  68. break
  69. end
  70. if RoleList[data.uuid1] == nil then
  71. delList[#delList+1] = data._id
  72. elseif RoleList[data.uuid2] == nil then
  73. delList[#delList+1] = data._id
  74. end
  75. end
  76. local query = {}
  77. for k,v in ipairs(delList) do
  78. query._id = v
  79. LuaMongo.remove(DB.db_friend, query)
  80. end
  81. end
  82. function handleMail()
  83. local delList = {}
  84. local allCnt = 0
  85. LuaMongo.find(DB.db_mail)
  86. local compareTime = os.time() - 7 * 24 * 3600 --删除7天以上的邮件
  87. while true do
  88. local mail = {}
  89. if not LuaMongo.next(mail) then
  90. break
  91. end
  92. if mail.expireTime then -- 有指定过期时间
  93. if mail.time < os.time() - mail.expireTime then
  94. delList[#delList+1] = mail._id
  95. elseif mail.receiverUuid and RoleList[mail.receiverUuid] == nil then
  96. delList[#delList+1] = mail._id
  97. end
  98. elseif mail.time < compareTime then
  99. delList[#delList+1] = mail._id
  100. elseif mail.receiverUuid and RoleList[mail.receiverUuid] == nil then
  101. delList[#delList+1] = mail._id
  102. end
  103. allCnt = allCnt + 1
  104. end
  105. print("delmail:",#delList.."/"..allCnt)
  106. local query = {}
  107. for k,v in ipairs(delList) do
  108. query._id = v
  109. LuaMongo.remove(DB.db_mail, query)
  110. end
  111. end
  112. local function delUnionMember(union,uuid)
  113. union.member[uuid] = nil
  114. union.curCnt = union.curCnt - 1
  115. if union.presidentUuid == uuid then
  116. union.presidentUuid = nil
  117. end
  118. end
  119. local function checkLeader(union)
  120. if union.presidentUuid == nil then
  121. local uuid
  122. for k,v in pairs(union.member) do
  123. if uuid == nil then
  124. uuid = k
  125. end
  126. if v.post == 2 then
  127. uuid = k
  128. break
  129. end
  130. end
  131. if uuid then
  132. union.member[uuid].post = 1
  133. union.presidentUuid = uuid
  134. end
  135. end
  136. end
  137. function handleUnion()
  138. local delList = {}
  139. LuaMongo.find(DB.db_union)
  140. local query = {}
  141. while true do
  142. local union = {}
  143. if not LuaMongo.next(union) then
  144. break
  145. end
  146. local isChange = false
  147. local delMembers = {}
  148. for uuid in pairs(union.member) do
  149. if not RoleList[uuid] then
  150. delMembers[uuid] = 1
  151. end
  152. end
  153. for uuid in pairs(delMembers) do
  154. isChange = true
  155. delUnionMember(union,uuid)
  156. end
  157. local delApplys = {}
  158. if union.apply then
  159. for uuid in pairs(union.apply) do
  160. if not RoleList[uuid] then
  161. delApplys[uuid] = 1
  162. end
  163. end
  164. end
  165. for uuid in pairs(delApplys) do
  166. isChange = true
  167. union.apply[uuid] = nil
  168. end
  169. checkLeader(union)
  170. if union.presidentUuid == nil then
  171. delList[#delList+1] = union._id
  172. elseif isChange then
  173. query._id = union._id
  174. LuaMongo.update(DB.db_union, query, union)
  175. end
  176. end
  177. for _,v in ipairs(delList) do
  178. query._id = v
  179. LuaMongo.remove(DB.db_union, query)
  180. end
  181. end
  182. local function handleStar()
  183. -- 星空争霸
  184. local query = {}
  185. local updateSet = {}
  186. local updateUnset = {}
  187. local tempTb = {}
  188. LuaMongo.find(DB.db_the_stars)
  189. while true do
  190. local data = {}
  191. if not LuaMongo.next(data) then
  192. break
  193. end
  194. if data.uuid and not RoleList[data.uuid] then
  195. data.uuid = nil
  196. data.body = nil
  197. query._id = data._id
  198. LuaMongo.update(DB.db_the_stars, query, data)
  199. end
  200. end
  201. end
  202. local function handleJJC()
  203. LuaMongo.find(DB.db_jjc)
  204. local delList = nil
  205. while true do
  206. local jjcData = {}
  207. if not LuaMongo.next(jjcData) then
  208. break
  209. end
  210. if not jjcData.monsterOutID and not RoleList[jjcData._id] then
  211. delList = delList or {}
  212. delList[#delList + 1] = jjcData._id
  213. end
  214. end
  215. if not delList then return end
  216. local query = {}
  217. for _, uuid in ipairs(delList) do
  218. query._id = uuid
  219. LuaMongo.remove(DB.db_jjc, query)
  220. end
  221. end
  222. local function handleVideo()
  223. LuaMongo.find(DB.db_combat_video, {["combatInfo.attacker"] = 1})
  224. local delList = nil
  225. while true do
  226. local combatVideo = {}
  227. if not LuaMongo.next(combatVideo) then
  228. break
  229. end
  230. local uuid = combatVideo.combatInfo.attacker.uuid
  231. if not RoleList[uuid] then
  232. delList = delList or {}
  233. delList[#delList + 1] = uuid
  234. end
  235. end
  236. if not delList then return end
  237. local query = {}
  238. for _, uuid in ipairs(delList) do
  239. query._id = uuid
  240. LuaMongo.remove(DB.db_combat_video, query)
  241. end
  242. end
  243. function roleDel()
  244. if _G.is_middle == true then return end
  245. delRoles() -- 删角色
  246. -- 删号后其它相关的数据处理
  247. handleFriend() -- 处理好友表
  248. handleMail() -- 处理邮件表
  249. handleUnion() -- 处理公会表 会长如果被删号 会长转移给官员 没官员则转移给随机一个人/如果公会所有人都被删号 删除这个公会
  250. handleStar() -- 处理星空争霸
  251. handleJJC() -- 处理单人竞技场
  252. handleVideo() -- 处理战斗记录
  253. end
  254. local QueryCreateRoleLog = {changeNameCnt=0}
  255. local function handleCreateRoleLog()
  256. _G.collectgarbage("step", 1000000)
  257. LuaMongo.find(DB.db_char, QueryCreateRoleLog, {_id="1", account=1, name=1, lv = 1, ip=1})
  258. local list = {}
  259. RoleList = {}
  260. local allCnt = 0
  261. local delCnt = 0
  262. local nowTime = _G.real_os_time()
  263. while true do
  264. local data = {}
  265. if not LuaMongo.next(data) then
  266. break
  267. end
  268. Log.write(Log.LOGID_OSS_REGISTER, data._id, data.account, data.name, data.ip,"","")
  269. Log.write(Log.LOGID_OSS_CREATELOSS,data.account, data.name, LogDefine.HUMAN_LOST.CREATE_NAME_FINISH, data.ip, data.pf or "", data.appid or "", data.phpChanelID or 0)
  270. end
  271. _G.collectgarbage("step", 1000000)
  272. end
  273. local delQuery = {videoType=2}
  274. local function handleCleanVideoLog()
  275. -- 清除个人录像记录
  276. LuaMongo.remove(DB.db_combat_video, delQuery)
  277. end
  278. function initAfterHot()
  279. if _G.is_middle == true then return end
  280. --handleCreateRoleLog()
  281. end