inquire_deltime.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. --[[
  2. author:{zlf}
  3. time:2020-06-30 15:56:21
  4. note:
  5. 玩家道具/精灵 等 删除,查询数据
  6. 1. 精灵数据: 分析记录数据, 并按权重排序推荐删除。
  7. 2. 符文: 返回指定类型符文唯一id
  8. 3. 装备:返回指定类型装备唯一id
  9. 3. 其他类型: 返回数据
  10. ]]
  11. local skynet = require "skynet"
  12. require "skynet.manager"
  13. local logger = require "logger"
  14. local stringify = require "stringify"
  15. local usercenter = skynet.localname(".usercenter")
  16. local logind = skynet.localname(".loginserver")
  17. local redisdriver = require "skynet.db.redis"
  18. local namecenter = skynet.localname(".namecenter")
  19. local cjson = require "cjson"
  20. local md5 = require "md5"
  21. local THIS = {}
  22. local ITEM_TYPE_DIS = {}
  23. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  24. -- Generate request data
  25. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  26. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  27. local whitelist = {
  28. ["192.168.1.23"] = true,
  29. ["192.168.1.127"] = true,
  30. ["192.168.1.41"] = true,
  31. ["222.212.88.4"] = true,
  32. }
  33. function THIS.get_data(redis, uid, key)
  34. local ret = redis:HMGET(string.format("character:%s", uid), key)
  35. if ret[1] then
  36. if key == "coins" -- 金币
  37. or key == "exp" -- 角色经验
  38. or key == "pkpoint" -- 竞技积分
  39. or key == "diamonds" -- 钻石
  40. or key == "friendship" -- 友情点
  41. or key == "contribute" -- 公会贡献
  42. or key == "advintegral" -- 公会冒险积分
  43. or key == "recharge_point" -- 充值积分
  44. or key == "span_elf_king_point" -- 跨服至尊天王积分 -- CDPK3-86
  45. or key == "ruins_point" -- 古代金币 -- CDPK3-276 宝可梦遗迹
  46. or key == "research_note" -- 研究笔记 --PK3-1148
  47. or key == "megacoin" -- mege点
  48. or key == "bind_diamonds" -- 绑定钻石
  49. or key == "budo_point" -- 道馆积分
  50. or key == "manual_exp" -- 训练师手册积分 --PK3-1077
  51. or key == "explore" -- 探险值
  52. or key == "explore_exp" -- 探险经验
  53. or key == "gashapon_num" -- 扭蛋积分
  54. or key == "smeltpoint" -- 熔炼点
  55. then
  56. return ret[1]
  57. else
  58. return skynet.unpack(ret[1])
  59. end
  60. else
  61. return nil
  62. end
  63. end
  64. ITEM_TYPE_DIS[GOODS_EQUIP] = function(redis,uid,itemid) -- 1 装备
  65. itemid = tonumber(itemid)
  66. local bagdata = THIS.get_data(redis, uid, "bagdata")
  67. if not bagdata then return 409 end -- 数据加载失败
  68. local ret_sid = {} -- 返回数据
  69. for sid, info in pairs(bagdata.equip) do
  70. if itemid == info.sid then
  71. table.insert(ret_sid, sid)
  72. end
  73. end
  74. -- 返回查询到的数据
  75. return 0,ret_sid
  76. end
  77. ITEM_TYPE_DIS[GOODS_ITEM] = function(redis,uid,itemid) -- 2 道具
  78. itemid = tonumber(itemid)
  79. local bagdata = THIS.get_data(redis, uid, "bagdata")
  80. if not bagdata then return 409 end -- 数据加载失败
  81. local ret_num = 0 -- 指定类型道具的数量
  82. if bagdata.item[itemid] then
  83. ret_num = bagdata.item[itemid].num
  84. end
  85. return 0,ret_num
  86. end
  87. ITEM_TYPE_DIS[TYPE_ELF] = function(redis,uid,itemid) -- 3 精灵
  88. itemid = tonumber(itemid)
  89. local elfdata = THIS.get_data(redis, uid, "elfdata")
  90. if not elfdata then return 409 end -- 数据加载失败
  91. local ret_elf = {} -- 返回数据
  92. -- logger.trace(" elfdata.elflist %s", stringify(elfdata.elflist))
  93. for _, info in pairs(elfdata.elflist) do
  94. if info.sid == itemid then
  95. table.insert(ret_elf, info)
  96. end
  97. end
  98. -- 对筛选出来的数据进行排序
  99. -- logger.trace( "### ret_elf %s", stringify(ret_elf))
  100. table.sort(ret_elf, function(a,b)
  101. local a_lv = a.level or 0
  102. local b_lv = b.level or 0
  103. -- 比较等级
  104. if a_lv < b_lv then
  105. return true
  106. elseif a_lv == b_lv then
  107. -- 亲密度等级
  108. local a_lo = a.love or 0
  109. local b_lo = b.love or 0
  110. if a_lo < b_lo then
  111. return true
  112. end
  113. end
  114. end)
  115. return 0, ret_elf
  116. end
  117. ITEM_TYPE_DIS[TYPE_FASHION] = function(redis,uid,itemid) -- 4 时装
  118. itemid = tonumber(itemid)
  119. local dressdata = THIS.get_data(redis, uid, "dress")
  120. if not dressdata then return 409 end -- 数据加载失败
  121. return 0,dressdata.owned[itemid] or {0,0}
  122. end
  123. ITEM_TYPE_DIS[TYPE_DEBRIS] = function(redis,uid,itemid) -- 5 精灵碎片
  124. itemid = tonumber(itemid)
  125. local oncedata = THIS.get_data(redis, uid, "oncedata")
  126. if not oncedata then return 409 end -- 数据加载失败
  127. local ret_num = 0
  128. if oncedata.debris[itemid] then
  129. ret_num = oncedata.debris[itemid].num
  130. end
  131. return 0, ret_num
  132. end
  133. ITEM_TYPE_DIS[TYPE_RUNE] = function(redis,uid,itemid) -- 6 精灵符文
  134. itemid = tonumber(itemid)
  135. local elf_runedata = THIS.get_data(redis, uid, "elf_rune")
  136. if not elf_runedata then return 409 end -- 数据加载失败
  137. local ret = {}
  138. for _, info in pairs(elf_runedata.rune_bag or {}) do
  139. if info.sid == itemid then
  140. table.insert(ret, info.id)
  141. end
  142. end
  143. return 0, ret
  144. end
  145. ITEM_TYPE_DIS[GOODS_MONEY] = function(redis,uid,itemid) -- 8 货币
  146. itemid = tonumber(itemid)
  147. local key = MONEY_TYPE[itemid]
  148. if not key then
  149. return 409 -- 数据加载失败
  150. end
  151. local data = THIS.get_data(redis, uid, key)
  152. return 0, data or 0
  153. end
  154. ITEM_TYPE_DIS[TYPE_RUNEDEBRIS] = function(redis,uid,itemid) -- 9 符文碎片
  155. itemid = tonumber(itemid)
  156. local oncedata = THIS.get_data(redis, uid, "oncedata")
  157. if not oncedata then return 409 end -- 数据加载失败
  158. local ret_num = 0
  159. if oncedata.rune[itemid] then
  160. ret_num = oncedata.rune[itemid].num
  161. end
  162. return 0,0
  163. end
  164. ITEM_TYPE_DIS[TYPE_TITLE] = function(redis,uid,itemid) -- 10 称号
  165. itemid = tonumber(itemid)
  166. local titledata = THIS.get_data(redis, uid, "title")
  167. if not titledata then return 409 end -- 数据加载失败
  168. local ret_num = 0
  169. if titledata.titlelist[itemid] then
  170. ret_num = 1
  171. end
  172. return 0,ret_num
  173. end
  174. --CDPK3-271
  175. ITEM_TYPE_DIS[TYPE_CARRY] = function(redis,uid,itemid) -- 12 精灵携带品
  176. itemid = tonumber(itemid)
  177. local elf_carry_items = THIS.get_data(redis, uid, "elf_carry_items")
  178. if not elf_carry_items then return 409 end -- 数据加载失败
  179. local ret = {}
  180. for _, info in pairs(elf_carry_items.carry_items_bag or {}) do
  181. if info.sid == itemid then
  182. table.insert(ret, info.id)
  183. end
  184. end
  185. ITEM_TYPE_DIS[TYPE_CARRYDEBRIS] = function(redis,uid,itemid) -- 13 携带品碎片
  186. itemid = tonumber(itemid)
  187. local oncedata = THIS.get_data(redis, uid, "oncedata")
  188. if not oncedata then return 409 end -- 数据加载失败
  189. local ret_num = 0
  190. if oncedata.carry[itemid] then
  191. ret_num = oncedata.carry[itemid].num
  192. end
  193. return 0,0
  194. end
  195. return 0, ret
  196. end
  197. -- CDPK3-1002 代金券
  198. ITEM_TYPE_DIS[TYPE_COUPON] = function(redis,uid,cid) -- 12 精灵携带品
  199. cid = tonumber(cid)
  200. local coupon = THIS.get_data(redis, uid, "coupon")
  201. local ret = {}
  202. for _, info in pairs(coupon.bag) do
  203. if info.cid == cid then
  204. table.insert(ret, info.id)
  205. end
  206. end
  207. return 0, ret
  208. end
  209. --[[
  210. 返回数据结构:
  211. 类型1-装备:{装备唯一id, ...}
  212. 类型2-道具:数量
  213. 类型3-精灵(已经完成排序,展示返回数据):{
  214. [1] = {
  215. sid = 精灵模板id,
  216. id = 精灵唯一id,
  217. ...(其他数据)
  218. },
  219. }
  220. 类型4-时装: {时装数量, 时装进阶等级(时装进阶后,时装必须留一件)}
  221. 类型5-精灵碎片: 碎片数量
  222. 类型6-精灵符文: {符文唯一id, ...}
  223. 类型8-货币: 货币数量
  224. 类型9-符文碎片: 碎片数量
  225. 类型10-称号: 称号数量(默认为1)
  226. ]]
  227. -- example:
  228. --[[
  229. http://192.168.108.19:9002/inquire_deltime?code=xxx&uid=00-6395766577223962624
  230. &itemtype=主类型
  231. &itemid=子id
  232. ]]
  233. local function inquire_deltime(args, ipaddr, header)
  234. logger.trace("处理来自主机 %s 的 获取 查询删除的数据 %s", ipaddr, stringify(args))
  235. if not whitelist[ipaddr] then
  236. -- return { "403 - Forbidden" }
  237. -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
  238. end
  239. -- 验证gm账号
  240. local code = string.sub(args.code, 1, 16)
  241. logger.trace(" ### %s",content.sign)
  242. if code ~= content.sign then
  243. return cjson.encode({state = 403, msg = "账号或密码错误"})
  244. end
  245. local conf = assert(option.redis)
  246. local redis
  247. redis = redisdriver.connect(conf)
  248. redis:select(0)
  249. -- 获取玩家uid
  250. local uid
  251. if args.uid then
  252. uid = args.uid
  253. else
  254. return cjson.encode({state = 403,msg = "请输入玩家uid或者玩家name"})
  255. end
  256. local itemtype = tonumber(args.itemtype) -- 物品主类型
  257. local itemid = tonumber(args.itemid) -- 物品子类型
  258. logger.trace(" ### args %s", stringify(args))
  259. local errno, info = ITEM_TYPE_DIS[itemtype](redis,uid,itemid)
  260. if errno ~= 0 then
  261. return cjson.encode({state = 409,msg = "数据加载失败"})
  262. end
  263. logger.trace(" info %s", stringify({info}))
  264. redis:disconnect()
  265. return cjson.encode({state = 0, msg = "success", data = info})
  266. end
  267. return inquire_deltime