--[[ 查询玩家指定的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, } local pipeline = require "pipeline" function getgameinfo(redis)--得到所有玩家信息 local accounts = {} local block = pipeline(1024) local keys = redis:keys("character:*") if #keys > 0 then for _, k in ipairs(keys) do block.add("hmget", k, "nickname", "uid", "level","sex","vip", "mission", "dress","title","forbidden","silent" ,"power") end end local resp = block.execute(redis, {}) for i, v in ipairs(resp) do assert(v.ok) local rs = v.out if rs[2] then local namecgf = {name = rs[1], uid = rs[2],level = tonumber(rs[3]),sex = tonumber(rs[4]),vip = tonumber(rs[5])} if rs[6] then namecgf.mission = tonumber(rs[6]) end if rs[7] then local dress = unpack(rs[7]) namecgf.dress = dress.carry or nil--玩家身上的时装 end if rs[8] then local title = unpack(rs[8]) namecgf.title = title.settitle or nil--玩家的称号 end if rs[9] then namecgf.forbidden =rs[9] end if rs[10] then namecgf.silent=rs[10] end if rs[11] then namecgf.power = tonumber(rs[11]) end accounts[namecgf.uid] = namecgf end end return accounts end -- example: --[[ http://192.168.1.51:9001/field_inquire?code=xxx&uid=00-6395766577223962624&key=elfdata ]] local function query_forbit(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 myacc=getgameinfo(redis) redis:disconnect() -- 断开数据库连接 logger.trace("===================myacc=%s",stringify(myacc)) local list_all={} local list_forbidden={} local list_silent={} for k,v in pairs(myacc) do if v.forbidden or v.silent then table.insert( list_all,v) end if v.forbidden then table.insert( list_forbidden,v) end if v.silent then table.insert( list_silent,v) end end if args.cmd=="*" then return cjson.encode({state = 0, msg = "成功",list=list_all}) elseif args.cmd=="forbidden" then return cjson.encode({state = 0, msg = "成功",list=list_forbidden}) elseif args.cmd=="silent" then return cjson.encode({state = 0, msg = "成功",list=list_silent}) else return cjson.encode({state = 400, msg = "错误的cmd参数"}) end end return query_forbit