RoleDel.lua 8.1 KB

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