query_facebook.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --[[
  2. author:{zlf}
  3. time:2021-01-27 10:20:24
  4. note: 依据玩家的账号, 查询玩家的角色数据
  5. ]]
  6. --[[
  7. 查询玩家指定的key值数据
  8. ]] local skynet = require "skynet"
  9. require "skynet.manager"
  10. local logger = require "logger"
  11. local stringify = require "stringify"
  12. local usercenter = skynet.localname(".usercenter")
  13. local logind = skynet.localname(".loginserver")
  14. local redisdriver = require "skynet.db.redis"
  15. local namecenter = skynet.localname(".namecenter")
  16. local cjson = require "cjson"
  17. local md5 = require "md5"
  18. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  19. -- Generate request data
  20. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  21. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  22. local whitelist = {
  23. }
  24. function getgameinfo(redis)--得到所有玩家信息
  25. local accounts = {}
  26. local keys = redis:keys("character:*")
  27. -- if #keys > 0 then
  28. -- for _, k in ipairs(keys) do
  29. -- block.add("hmget", k, "nickname", "uid", "level","sex","vip", "mission", "dress","title","forbidden","silent" ,"power")
  30. -- end
  31. -- end
  32. return accounts
  33. end
  34. -- 记录账号验证时间
  35. local account_record = {
  36. }
  37. -- example:
  38. --[[
  39. args.account 账号
  40. args.channel 渠道
  41. args.token 验证
  42. args.appid 包名
  43. http://192.168.1.51:9001/query_facebook?
  44. ]]
  45. local account_key = "account:*:*:%s"
  46. local character_key = "character:%s"
  47. local function query_facebook(args, ipaddr, header)
  48. --[[
  49. local facebook = require "service/loginserver/facebook"
  50. logger.trace(" 玩家facebook账号对于角色查询 %s", stringify(args))
  51. local ret = facebook.login_player(args)
  52. if (not ret) or ret ~= 0 then
  53. return cjson.encode({errno = 1, note = "账号验证失败"})
  54. end
  55. ]]
  56. if not whitelist[ipaddr] then
  57. return cjson.encode({errno = 3, host = header.host, note = "不信任ip"})
  58. end
  59. if account_record[args.account] then
  60. if account_record[args.account] + 60 >= os.time() then
  61. return cjson.encode({errno = 2, note = "过于频繁的查询请求"})
  62. end
  63. end
  64. -- 按照玩家账号查询 玩家所有的角色
  65. local conf = assert(option.redis)
  66. local redis
  67. redis = redisdriver.connect(conf)
  68. redis:select(0)
  69. local ret = {}
  70. -- 数据库查询操作
  71. logger.trace("######### string.format(account_key, args.account) %s", string.format(account_key, args.account))
  72. local keys = redis:keys(string.format(account_key, args.account))
  73. logger.trace("######### keys %s", stringify(keys))
  74. -- account:android_hs:11:461049
  75. for _, key in pairs(keys) do
  76. local uid = redis:GET(key)
  77. -- logger.trace("######### uid %s %s", uid,string.format(character_key, uid))
  78. -- 加载玩家展示数据
  79. local ret2 = redis:hmget(string.format(character_key, uid), "nickname", "uid", "level","vip", "sid")
  80. -- logger.trace("#### ret %s", stringify(ret2))
  81. table.insert(ret, {
  82. nickname = ret2[1],
  83. uid = ret2[2],
  84. level = ret2[3] or 0,
  85. vip = ret2[4] or 0,
  86. sid = ret2[5],
  87. })
  88. end
  89. redis:disconnect() -- 断开数据库连接
  90. account_record[args.account] = os.time()
  91. return cjson.encode({errno = 0, showinfo = ret})
  92. end
  93. return query_facebook