RoleDel.lua 8.7 KB

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