RoleDel.lua 8.5 KB

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