field_inquire.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. --[[
  2. 查询玩家指定的key值数据
  3. ]] local skynet = require "skynet"
  4. require "skynet.manager"
  5. local logger = require "logger"
  6. local stringify = require "stringify"
  7. local usercenter = skynet.localname(".usercenter")
  8. local logind = skynet.localname(".loginserver")
  9. local redisdriver = require "skynet.db.redis"
  10. local namecenter = skynet.localname(".namecenter")
  11. local cjson = require "cjson"
  12. local md5 = require "md5"
  13. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  14. -- Generate request data
  15. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  16. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  17. local whitelist = {
  18. ["192.168.1.23"] = true,
  19. ["192.168.1.127"] = true,
  20. ["192.168.1.41"] = true,
  21. ["222.212.88.4"] = true,
  22. }
  23. --[[
  24. byname = zlf -- 玩家的名字
  25. ]]
  26. local function get_id(name) return
  27. skynet.call(namecenter, "lua", "findby", name) end
  28. local function get_data(redis, uid, key)
  29. local ret = redis:HMGET(string.format("character:%s", uid), key)
  30. if ret[1] then
  31. if key == "coins" -- 金币
  32. or key == "exp" -- 角色经验
  33. or key == "pkpoint" -- 竞技积分
  34. or key == "diamonds" -- 钻石
  35. or key == "friendship" -- 友情点
  36. or key == "contribute" -- 公会贡献
  37. or key == "advintegral" -- 公会冒险积分
  38. or key == "recharge_point" -- 充值积分
  39. or key == "research_note" -- 研究笔记 --PK3-1148
  40. or key == "megacoin" -- mege点
  41. or key == "bind_diamonds" -- 绑定钻石
  42. or key == "budo_point" -- 道馆积分
  43. or key == "manual_exp" -- 训练师手册积分 --PK3-1077
  44. or key == "explore" -- 探险值
  45. or key == "explore_exp" -- 探险经验
  46. or key == "gashapon_num" -- 扭蛋积分
  47. or key == "smeltpoint" -- 熔炼点
  48. or key =="mission" --当前关卡
  49. or key =="sex" --性别
  50. or key =="power"
  51. or key =="account"
  52. or key =="sid"
  53. or key =="lastlogout"
  54. or key =="lastlogin"
  55. or key =="level"
  56. or key =="channel"
  57. or key =="forbidden"
  58. or key =="createtime" --创号时间
  59. or key =="appid"
  60. or key =="platform"
  61. or key == "span_elf_king_point" -- 跨服至尊天王积分 -- CDPK3-86
  62. or key == "ruins_point" -- 古代金币 -- CDPK3-276 宝可梦遗迹
  63. or key == "tourist"
  64. or key == "google"
  65. or key == "facebook"
  66. or key == "uid" or key == "nickname" then
  67. return ret[1]
  68. else
  69. return skynet.unpack(ret[1])
  70. end
  71. else
  72. return nil
  73. end
  74. end
  75. -- example:
  76. --[[
  77. http://192.168.1.51:9001/field_inquire?code=xxx&uid=00-6395766577223962624&key=elfdata
  78. ]]
  79. local function field_inquire(args, ipaddr, header)
  80. logger.trace("处理来自主机 %s 的 获取 玩家指定key--%s的数据", ipaddr,args.key)
  81. if not whitelist[ipaddr] then
  82. -- return { "403 - Forbidden" }
  83. -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
  84. end
  85. -- 验证gm账号
  86. local code = string.sub(args.code, 1, 16)
  87. if code ~= content.sign then
  88. return cjson.encode({state = 403, msg = "账号或密码错误"})
  89. end
  90. local conf = assert(option.redis)
  91. local redis
  92. redis = redisdriver.connect(conf)
  93. redis:select(0)
  94. local uid
  95. if args.name then
  96. uid = get_id(args.name)
  97. elseif args.uid then
  98. uid = args.uid
  99. elseif (not args.uid) and (not args.name) then
  100. return cjson.encode({state = 403,msg = "请输入玩家uid或者玩家name"})
  101. end
  102. local key = args.key or nil
  103. if not key then
  104. return cjson.encode({state = 403, msg = "请输入key值"})
  105. end
  106. local ret_info = {}
  107. ret_info[key] = get_data(redis, uid, key)
  108. if not ret_info[key] then
  109. return cjson.encode({state = 403, msg = "错误的key值"})
  110. end
  111. redis:disconnect()
  112. return cjson.encode({state = 0, msg = "success", data = ret_info})
  113. end
  114. return field_inquire