RoleDel.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. local mail = {}
  93. local pret,perr = pcall(LuaMongo.next,mail)
  94. if not pret then
  95. print(perr)
  96. break
  97. end
  98. if not next(mail) then
  99. break
  100. end
  101. if mail.expireTime then -- 有指定过期时间
  102. if mail.time < os.time() - mail.expireTime then
  103. delList[#delList+1] = mail._id
  104. elseif mail.receiverUuid and RoleList[mail.receiverUuid] == nil then
  105. delList[#delList+1] = mail._id
  106. end
  107. elseif mail.time < compareTime 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. allCnt = allCnt + 1
  113. end
  114. print("delmail:",#delList.."/"..allCnt)
  115. local query = {}
  116. for k,v in ipairs(delList) do
  117. query._id = v
  118. LuaMongo.remove(DB.db_mail, query)
  119. end
  120. end
  121. local function delUnionMember(union,uuid)
  122. union.member[uuid] = nil
  123. union.curCnt = union.curCnt - 1
  124. if union.presidentUuid == uuid then
  125. union.presidentUuid = nil
  126. end
  127. end
  128. local function checkLeader(union)
  129. if union.presidentUuid == nil then
  130. local uuid
  131. for k,v in pairs(union.member) do
  132. if uuid == nil then
  133. uuid = k
  134. end
  135. if v.post == 2 then
  136. uuid = k
  137. break
  138. end
  139. end
  140. if uuid then
  141. union.member[uuid].post = 1
  142. union.presidentUuid = uuid
  143. end
  144. end
  145. end
  146. function handleUnion()
  147. local delList = {}
  148. LuaMongo.find(DB.db_union)
  149. local query = {}
  150. while true do
  151. local union = {}
  152. if not LuaMongo.next(union) then
  153. break
  154. end
  155. local isChange = false
  156. local delMembers = {}
  157. for uuid in pairs(union.member) do
  158. if not RoleList[uuid] then
  159. delMembers[uuid] = 1
  160. end
  161. end
  162. for uuid in pairs(delMembers) do
  163. isChange = true
  164. delUnionMember(union,uuid)
  165. end
  166. local delApplys = {}
  167. if union.apply then
  168. for uuid in pairs(union.apply) do
  169. if not RoleList[uuid] then
  170. delApplys[uuid] = 1
  171. end
  172. end
  173. end
  174. for uuid in pairs(delApplys) do
  175. isChange = true
  176. union.apply[uuid] = nil
  177. end
  178. checkLeader(union)
  179. if union.presidentUuid == nil then
  180. delList[#delList+1] = union._id
  181. elseif isChange then
  182. query._id = union._id
  183. LuaMongo.update(DB.db_union, query, union)
  184. end
  185. end
  186. for _,v in ipairs(delList) do
  187. query._id = v
  188. LuaMongo.remove(DB.db_union, query)
  189. end
  190. end
  191. local function handleStar()
  192. -- 星空争霸
  193. local query = {}
  194. local updateSet = {}
  195. local updateUnset = {}
  196. local tempTb = {}
  197. LuaMongo.find(DB.db_the_stars)
  198. while true do
  199. local data = {}
  200. if not LuaMongo.next(data) then
  201. break
  202. end
  203. if data.uuid and not RoleList[data.uuid] then
  204. data.uuid = nil
  205. data.body = nil
  206. query._id = data._id
  207. LuaMongo.update(DB.db_the_stars, query, data)
  208. end
  209. end
  210. end
  211. local function handleJJC()
  212. LuaMongo.find(DB.db_jjc)
  213. local delList = nil
  214. while true do
  215. local jjcData = {}
  216. if not LuaMongo.next(jjcData) then
  217. break
  218. end
  219. if not jjcData.monsterOutID and not RoleList[jjcData._id] then
  220. delList = delList or {}
  221. delList[#delList + 1] = jjcData._id
  222. end
  223. end
  224. if not delList then return end
  225. local query = {}
  226. for _, uuid in ipairs(delList) do
  227. query._id = uuid
  228. LuaMongo.remove(DB.db_jjc, query)
  229. end
  230. end
  231. local function handleVideo()
  232. LuaMongo.find(DB.db_combat_video, {["combatInfo.attacker"] = 1})
  233. local delList = nil
  234. while true do
  235. local combatVideo = {}
  236. if not LuaMongo.next(combatVideo) then
  237. break
  238. end
  239. local uuid = combatVideo.combatInfo.attacker.uuid
  240. if not RoleList[uuid] then
  241. delList = delList or {}
  242. delList[#delList + 1] = uuid
  243. end
  244. end
  245. if not delList then return end
  246. local query = {}
  247. for _, uuid in ipairs(delList) do
  248. query._id = uuid
  249. LuaMongo.remove(DB.db_combat_video, query)
  250. end
  251. end
  252. function roleDel()
  253. if _G.is_middle == true then return end
  254. delRoles() -- 删角色
  255. -- 删号后其它相关的数据处理
  256. handleFriend() -- 处理好友表
  257. handleMail() -- 处理邮件表
  258. handleUnion() -- 处理公会表 会长如果被删号 会长转移给官员 没官员则转移给随机一个人/如果公会所有人都被删号 删除这个公会
  259. handleStar() -- 处理星空争霸
  260. handleJJC() -- 处理单人竞技场
  261. handleVideo() -- 处理战斗记录
  262. end
  263. local QueryCreateRoleLog = {changeNameCnt=0}
  264. local function handleCreateRoleLog()
  265. _G.collectgarbage("step", 1000000)
  266. LuaMongo.find(DB.db_char, QueryCreateRoleLog, {_id="1", account=1, name=1, lv = 1, ip=1})
  267. local list = {}
  268. RoleList = {}
  269. local allCnt = 0
  270. local delCnt = 0
  271. local nowTime = _G.real_os_time()
  272. while true do
  273. local data = {}
  274. if not LuaMongo.next(data) then
  275. break
  276. end
  277. Log.write(Log.LOGID_OSS_REGISTER, data._id, data.account, data.name, data.ip,"","")
  278. 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)
  279. end
  280. _G.collectgarbage("step", 1000000)
  281. end
  282. local delQuery = {videoType=2}
  283. local function handleCleanVideoLog()
  284. -- 清除个人录像记录
  285. LuaMongo.remove(DB.db_combat_video, delQuery)
  286. end
  287. function initAfterHot()
  288. if _G.is_middle == true then return end
  289. --handleCreateRoleLog()
  290. end