--[[ author:{zlf} time:2021-01-27 10:20:24 note: 依据玩家的账号, 查询玩家的角色数据 ]] --[[ 查询玩家指定的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 = { } function getgameinfo(redis)--得到所有玩家信息 local accounts = {} 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 return accounts end -- 记录账号验证时间 local account_record = { } -- example: --[[ args.account 账号 args.channel 渠道 args.token 验证 args.appid 包名 http://192.168.1.51:9001/query_facebook? ]] local account_key = "account:*:*:%s" local character_key = "character:%s" local function query_facebook(args, ipaddr, header) --[[ local facebook = require "service/loginserver/facebook" logger.trace(" 玩家facebook账号对于角色查询 %s", stringify(args)) local ret = facebook.login_player(args) if (not ret) or ret ~= 0 then return cjson.encode({errno = 1, note = "账号验证失败"}) end ]] if not whitelist[ipaddr] then return cjson.encode({errno = 3, host = header.host, note = "不信任ip"}) end if account_record[args.account] then if account_record[args.account] + 60 >= os.time() then return cjson.encode({errno = 2, note = "过于频繁的查询请求"}) end end -- 按照玩家账号查询 玩家所有的角色 local conf = assert(option.redis) local redis redis = redisdriver.connect(conf) redis:select(0) local ret = {} -- 数据库查询操作 logger.trace("######### string.format(account_key, args.account) %s", string.format(account_key, args.account)) local keys = redis:keys(string.format(account_key, args.account)) logger.trace("######### keys %s", stringify(keys)) -- account:android_hs:11:461049 for _, key in pairs(keys) do local uid = redis:GET(key) -- logger.trace("######### uid %s %s", uid,string.format(character_key, uid)) -- 加载玩家展示数据 local ret2 = redis:hmget(string.format(character_key, uid), "nickname", "uid", "level","vip", "sid") -- logger.trace("#### ret %s", stringify(ret2)) table.insert(ret, { nickname = ret2[1], uid = ret2[2], level = ret2[3] or 0, vip = ret2[4] or 0, sid = ret2[5], }) end redis:disconnect() -- 断开数据库连接 account_record[args.account] = os.time() return cjson.encode({errno = 0, showinfo = ret}) end return query_facebook