--[[ 查询玩家指定的key值数据 ]] local skynet = require "skynet" require "skynet.manager" local logger = require "logger" local stringify = require "stringify" local usercenter = skynet.localname(".usercenter") local logind = skynet.localname(".loginserver") local redisdriver = require "skynet.db.redis" local namecenter = skynet.localname(".namecenter") local cjson = require "cjson" local md5 = require "md5" local authz = {acc = "yytx", pwd = "lee@YY-Games.520"} -- Generate request data local content = {acc = authz.acc, pwd = authz.pwd, sign = false} content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24) local whitelist = { ["192.168.1.23"] = true, ["192.168.1.127"] = true, ["192.168.1.41"] = true, ["222.212.88.4"] = true, } --[[ byname = zlf -- 玩家的名字 ]] local function get_id(name) return skynet.call(namecenter, "lua", "findby", name) end local function get_data(redis, uid, key) local ret = redis:HMGET(string.format("character:%s", uid), key) if ret[1] then if key == "coins" -- 金币 or key == "exp" -- 角色经验 or key == "pkpoint" -- 竞技积分 or key == "diamonds" -- 钻石 or key == "friendship" -- 友情点 or key == "contribute" -- 公会贡献 or key == "advintegral" -- 公会冒险积分 or key == "recharge_point" -- 充值积分 or key == "research_note" -- 研究笔记 --PK3-1148 or key == "megacoin" -- mege点 or key == "bind_diamonds" -- 绑定钻石 or key == "budo_point" -- 道馆积分 or key == "manual_exp" -- 训练师手册积分 --PK3-1077 or key == "explore" -- 探险值 or key == "explore_exp" -- 探险经验 or key == "gashapon_num" -- 扭蛋积分 or key == "smeltpoint" -- 熔炼点 or key =="mission" --当前关卡 or key =="sex" --性别 or key =="power" or key =="account" or key =="sid" or key =="lastlogout" or key =="lastlogin" or key =="level" or key =="channel" or key =="forbidden" or key =="createtime" --创号时间 or key =="appid" or key =="platform" or key == "span_elf_king_point" -- 跨服至尊天王积分 -- CDPK3-86 or key == "ruins_point" -- 古代金币 -- CDPK3-276 宝可梦遗迹 or key == "tourist" or key == "google" or key == "facebook" or key == "uid" or key == "nickname" then return ret[1] else return skynet.unpack(ret[1]) end else return nil end end -- example: --[[ http://192.168.1.51:9001/field_inquire?code=xxx&uid=00-6395766577223962624&key=elfdata ]] local function field_inquire(args, ipaddr, header) logger.trace("处理来自主机 %s 的 获取 玩家指定key--%s的数据", ipaddr,args.key) if not whitelist[ipaddr] then -- return { "403 - Forbidden" } -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"}) end -- 验证gm账号 local code = string.sub(args.code, 1, 16) if code ~= content.sign then return cjson.encode({state = 403, msg = "账号或密码错误"}) end local conf = assert(option.redis) local redis redis = redisdriver.connect(conf) redis:select(0) local uid if args.name then uid = get_id(args.name) elseif args.uid then uid = args.uid elseif (not args.uid) and (not args.name) then return cjson.encode({state = 403,msg = "请输入玩家uid或者玩家name"}) end local key = args.key or nil if not key then return cjson.encode({state = 403, msg = "请输入key值"}) end local ret_info = {} ret_info[key] = get_data(redis, uid, key) if not ret_info[key] then return cjson.encode({state = 403, msg = "错误的key值"}) end redis:disconnect() return cjson.encode({state = 0, msg = "success", data = ret_info}) end return field_inquire