RoleDel.lua 8.0 KB

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