ReportOnline.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ------------------------------------------------------
  2. -- 在线时长上报
  3. ------------------------------------------------------
  4. local Util = require("common.Util")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local REPORT_PER_TIME = 1800
  8. -- 本日在线时间
  9. -- 每1800秒上报1次
  10. function checkReportOnline(human)
  11. if not human.db then return end
  12. local nowTime = os.time()
  13. local time = nowTime - math.max(human.db.lastLoginTime, Util.getDayStartTime(nowTime))
  14. local oltime = (human.db.onlineTimeDay or 0) + time
  15. local oltimecnt = math.floor(oltime / REPORT_PER_TIME)
  16. local reportTime = oltimecnt * REPORT_PER_TIME
  17. if reportTime <= (human.db.onlineTimeDayReport or 0) then
  18. return
  19. end
  20. human.db.onlineTimeDayReport = reportTime
  21. local msgRet = Msg.gc.GC_ONLINETIME_REPORT
  22. msgRet.time = reportTime
  23. Msg.send(msgRet, human.fd)
  24. end
  25. function onTimer()
  26. for _, human in pairs(ObjHuman.onlineUuid) do
  27. checkReportOnline(human)
  28. end
  29. end
  30. function onLogin(human)
  31. checkReportOnline(human)
  32. end