--[[ author:{zlf} time:2020-06-30 15:56:21 note: 玩家道具/精灵 等 删除,查询数据 1. 精灵数据: 分析记录数据, 并按权重排序推荐删除。 2. 符文: 返回指定类型符文唯一id 3. 装备:返回指定类型装备唯一id 3. 其他类型: 返回数据 ]] 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 THIS = {} local ITEM_TYPE_DIS = {} 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, } function THIS.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 == "span_elf_king_point" -- 跨服至尊天王积分 -- CDPK3-86 or key == "ruins_point" -- 古代金币 -- CDPK3-276 宝可梦遗迹 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" -- 熔炼点 then return ret[1] else return skynet.unpack(ret[1]) end else return nil end end ITEM_TYPE_DIS[GOODS_EQUIP] = function(redis,uid,itemid) -- 1 装备 itemid = tonumber(itemid) local bagdata = THIS.get_data(redis, uid, "bagdata") if not bagdata then return 409 end -- 数据加载失败 local ret_sid = {} -- 返回数据 for sid, info in pairs(bagdata.equip) do if itemid == info.sid then table.insert(ret_sid, sid) end end -- 返回查询到的数据 return 0,ret_sid end ITEM_TYPE_DIS[GOODS_ITEM] = function(redis,uid,itemid) -- 2 道具 itemid = tonumber(itemid) local bagdata = THIS.get_data(redis, uid, "bagdata") if not bagdata then return 409 end -- 数据加载失败 local ret_num = 0 -- 指定类型道具的数量 if bagdata.item[itemid] then ret_num = bagdata.item[itemid].num end return 0,ret_num end ITEM_TYPE_DIS[TYPE_ELF] = function(redis,uid,itemid) -- 3 精灵 itemid = tonumber(itemid) local elfdata = THIS.get_data(redis, uid, "elfdata") if not elfdata then return 409 end -- 数据加载失败 local ret_elf = {} -- 返回数据 -- logger.trace(" elfdata.elflist %s", stringify(elfdata.elflist)) for _, info in pairs(elfdata.elflist) do if info.sid == itemid then table.insert(ret_elf, info) end end -- 对筛选出来的数据进行排序 -- logger.trace( "### ret_elf %s", stringify(ret_elf)) table.sort(ret_elf, function(a,b) local a_lv = a.level or 0 local b_lv = b.level or 0 -- 比较等级 if a_lv < b_lv then return true elseif a_lv == b_lv then -- 亲密度等级 local a_lo = a.love or 0 local b_lo = b.love or 0 if a_lo < b_lo then return true end end end) return 0, ret_elf end ITEM_TYPE_DIS[TYPE_FASHION] = function(redis,uid,itemid) -- 4 时装 itemid = tonumber(itemid) local dressdata = THIS.get_data(redis, uid, "dress") if not dressdata then return 409 end -- 数据加载失败 return 0,dressdata.owned[itemid] or {0,0} end ITEM_TYPE_DIS[TYPE_DEBRIS] = function(redis,uid,itemid) -- 5 精灵碎片 itemid = tonumber(itemid) local oncedata = THIS.get_data(redis, uid, "oncedata") if not oncedata then return 409 end -- 数据加载失败 local ret_num = 0 if oncedata.debris[itemid] then ret_num = oncedata.debris[itemid].num end return 0, ret_num end ITEM_TYPE_DIS[TYPE_RUNE] = function(redis,uid,itemid) -- 6 精灵符文 itemid = tonumber(itemid) local elf_runedata = THIS.get_data(redis, uid, "elf_rune") if not elf_runedata then return 409 end -- 数据加载失败 local ret = {} for _, info in pairs(elf_runedata.rune_bag or {}) do if info.sid == itemid then table.insert(ret, info.id) end end return 0, ret end ITEM_TYPE_DIS[GOODS_MONEY] = function(redis,uid,itemid) -- 8 货币 itemid = tonumber(itemid) local key = MONEY_TYPE[itemid] if not key then return 409 -- 数据加载失败 end local data = THIS.get_data(redis, uid, key) return 0, data or 0 end ITEM_TYPE_DIS[TYPE_RUNEDEBRIS] = function(redis,uid,itemid) -- 9 符文碎片 itemid = tonumber(itemid) local oncedata = THIS.get_data(redis, uid, "oncedata") if not oncedata then return 409 end -- 数据加载失败 local ret_num = 0 if oncedata.rune[itemid] then ret_num = oncedata.rune[itemid].num end return 0,0 end ITEM_TYPE_DIS[TYPE_TITLE] = function(redis,uid,itemid) -- 10 称号 itemid = tonumber(itemid) local titledata = THIS.get_data(redis, uid, "title") if not titledata then return 409 end -- 数据加载失败 local ret_num = 0 if titledata.titlelist[itemid] then ret_num = 1 end return 0,ret_num end --CDPK3-271 ITEM_TYPE_DIS[TYPE_CARRY] = function(redis,uid,itemid) -- 12 精灵携带品 itemid = tonumber(itemid) local elf_carry_items = THIS.get_data(redis, uid, "elf_carry_items") if not elf_carry_items then return 409 end -- 数据加载失败 local ret = {} for _, info in pairs(elf_carry_items.carry_items_bag or {}) do if info.sid == itemid then table.insert(ret, info.id) end end ITEM_TYPE_DIS[TYPE_CARRYDEBRIS] = function(redis,uid,itemid) -- 13 携带品碎片 itemid = tonumber(itemid) local oncedata = THIS.get_data(redis, uid, "oncedata") if not oncedata then return 409 end -- 数据加载失败 local ret_num = 0 if oncedata.carry[itemid] then ret_num = oncedata.carry[itemid].num end return 0,0 end return 0, ret end -- CDPK3-1002 代金券 ITEM_TYPE_DIS[TYPE_COUPON] = function(redis,uid,cid) -- 12 精灵携带品 cid = tonumber(cid) local coupon = THIS.get_data(redis, uid, "coupon") local ret = {} for _, info in pairs(coupon.bag) do if info.cid == cid then table.insert(ret, info.id) end end return 0, ret end --[[ 返回数据结构: 类型1-装备:{装备唯一id, ...} 类型2-道具:数量 类型3-精灵(已经完成排序,展示返回数据):{ [1] = { sid = 精灵模板id, id = 精灵唯一id, ...(其他数据) }, } 类型4-时装: {时装数量, 时装进阶等级(时装进阶后,时装必须留一件)} 类型5-精灵碎片: 碎片数量 类型6-精灵符文: {符文唯一id, ...} 类型8-货币: 货币数量 类型9-符文碎片: 碎片数量 类型10-称号: 称号数量(默认为1) ]] -- example: --[[ http://192.168.108.19:9002/inquire_deltime?code=xxx&uid=00-6395766577223962624 &itemtype=主类型 &itemid=子id ]] local function inquire_deltime(args, ipaddr, header) logger.trace("处理来自主机 %s 的 获取 查询删除的数据 %s", ipaddr, stringify(args)) 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) logger.trace(" ### %s",content.sign) 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) -- 获取玩家uid local uid if args.uid then uid = args.uid else return cjson.encode({state = 403,msg = "请输入玩家uid或者玩家name"}) end local itemtype = tonumber(args.itemtype) -- 物品主类型 local itemid = tonumber(args.itemid) -- 物品子类型 logger.trace(" ### args %s", stringify(args)) local errno, info = ITEM_TYPE_DIS[itemtype](redis,uid,itemid) if errno ~= 0 then return cjson.encode({state = 409,msg = "数据加载失败"}) end logger.trace(" info %s", stringify({info})) redis:disconnect() return cjson.encode({state = 0, msg = "success", data = info}) end return inquire_deltime