util_online.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --[[
  2. Descripttion:玩家信息
  3. version:
  4. Author: Neo,Huang
  5. Date: 2022-05-26 19:45:58
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2022-05-26 19:46:41
  8. --]]
  9. local moduleData = require("data.module")
  10. local lib_game_redis = require("lib_game_redis")
  11. local root = {}
  12. -- 新增在线人数
  13. function root:add_online_count(uid)
  14. if is_empty(uid) or is_robot(uid) then
  15. return false
  16. end
  17. local channel = moduleData:get_channel(uid)
  18. local bandShareCode = moduleData:hget(uid, "user", "bandShareCode")
  19. local key = "online:count"
  20. -- 全服人数
  21. lib_game_redis:hincrby(key, "all", 1)
  22. -- 渠道
  23. if not is_empty(channel) then
  24. lib_game_redis:hincrby(key, string.format("channel:%s", tostring(channel)), 1)
  25. end
  26. -- 主播
  27. if not is_empty(bandShareCode) then
  28. lib_game_redis:hincrby(key, string.format("bandShareCode:%s", tostring(bandShareCode)), 1)
  29. end
  30. end
  31. -- 减少在线人数
  32. function root:sub_online_count(uid)
  33. if is_empty(uid) or is_robot(uid) then
  34. return false
  35. end
  36. local channel = moduleData:get_channel(uid)
  37. local bandShareCode = moduleData:hget(uid, "user", "bandShareCode")
  38. local key = "online:count"
  39. -- 全服人数
  40. lib_game_redis:hincrby(key, "all", -1)
  41. -- 渠道
  42. if not is_empty(channel) then
  43. lib_game_redis:hincrby(key, string.format("channel:%s", tostring(channel)), -1)
  44. end
  45. -- 主播
  46. if not is_empty(bandShareCode) then
  47. lib_game_redis:hincrby(key, string.format("bandShareCode:%s", tostring(bandShareCode)), -1)
  48. end
  49. end
  50. return root