webplayer.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. --[[
  2. author:{zlf}
  3. time:2020-07-30 19:26:53
  4. zandao: CDPK3-037
  5. note: web充值用来查询玩家数据
  6. ]]
  7. local skynet = require "skynet"
  8. require "skynet.manager"
  9. local logger = require "logger"
  10. local queue = require "skynet.queue"
  11. local cjson = require "cjson"
  12. local stringify = require "stringify"
  13. local pipeline = require "pipeline"
  14. local loader = require "model.loader"
  15. local elf = require "model.elf"
  16. local equipment = require "model.equipment"
  17. local redisdriver = require "skynet.db.redis"
  18. local asset = require "model.asset"
  19. local md5 = require "md5"
  20. local namecenter
  21. local usercenter
  22. local synchronized = queue()
  23. local skynet_send = skynet.send
  24. local skynet_call = skynet.call
  25. local status = 0
  26. local pay_id_init = 0
  27. local db_character
  28. local FUND = 2 --基金
  29. local MONTH = 3 --月卡
  30. local LIFELONG = 4--终身卡
  31. local QUARTER = 5 --季卡
  32. local WEEK = 6 --周卡
  33. local SUPER_FUND = 8 --超级基金 -- PK3-1394 超级成长基金
  34. local authz = {
  35. acc="yytx",
  36. pwd="lee@YY-Games.520"
  37. }
  38. local pay_id = {
  39. }
  40. -- Generate request data
  41. local content = {
  42. acc = authz.acc,
  43. pwd = authz.pwd,
  44. sign = false
  45. }
  46. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd),9,24)
  47. local whitelist = {
  48. }
  49. local function init_payid()
  50. local cfg = assert(asset.recharge_proto)
  51. for key, value in pairs(cfg) do
  52. if value.type == FUND then--基金
  53. pay_id.fund = tonumber(key)
  54. elseif value.type == MONTH then --开启月卡
  55. pay_id.month_card = tonumber(key)
  56. elseif value.type == LIFELONG then--开启终身卡
  57. pay_id.longlife_card = tonumber(key)
  58. elseif value.type == QUARTER then -- 季卡
  59. pay_id.quarter_card = tonumber(key)
  60. elseif value.type == WEEK then -- 周卡
  61. pay_id.week_card = tonumber(key)
  62. elseif value.type == SUPER_FUND then -- PK3-1394 超级成长基金
  63. pay_id.super_fund = tonumber(key)
  64. end
  65. end
  66. pay_id_init = 1
  67. end
  68. --根据名字得到玩家uid
  69. local function get_id(name)
  70. return skynet.call(namecenter,"lua","findby", name)
  71. end
  72. local function initialize()
  73. status = 1
  74. namecenter = skynet.localname(".namecenter")
  75. usercenter = skynet.localname(".usercenter")
  76. local conf = assert(option.redis)
  77. db_character = redisdriver.connect(conf)
  78. db_character:select(0)
  79. end
  80. -- 周/月 礼包处理
  81. local function direct_recharge_gift(char2, grade_num)
  82. local ACTIV_ID = 63 -- 活动类型
  83. local activitytimemod_data = skynet.unpack(char2.activitytimemod)
  84. logger.trace(" #$### activitytimemod_data.activity_token[ACTIV_ID] %s", stringify(activitytimemod_data.activity_token[ACTIV_ID] or {}))
  85. if activitytimemod_data.activity_token[ACTIV_ID] then
  86. if activitytimemod_data.activity_token[ACTIV_ID].state ~= 0 then
  87. local TIME_SID = activitytimemod_data.activity_token[ACTIV_ID].sid
  88. local c_acti = assert(asset.activity_proto[TIME_SID], "activity_proto:" .. TIME_SID)
  89. local condition = c_acti.condition -- 挡位
  90. local parameter4 = c_acti.parameter4 -- 购买次数
  91. for k, v in ipairs(condition) do
  92. grade_num[v] = {sum = parameter4[k] or 0, yet=0}
  93. end
  94. -- 取出礼包数据
  95. local direct_recharge_gift_data = skynet.unpack(char2.direct_recharge_gift)
  96. logger.trace(" ####### direct_recharge_gift_data %s", stringify(direct_recharge_gift_data))
  97. for key, value in pairs(direct_recharge_gift_data.draw) do
  98. if condition[key] then
  99. grade_num[condition[key]].yet = value.can
  100. end
  101. end
  102. end
  103. end
  104. end
  105. -- 128基金
  106. local function senior_check_in(char2, grade_num)
  107. local WEL_KEY = 112 -- 活动对应的welfare表key值
  108. local order_id = assert(asset.welfare_proto[WEL_KEY].parameter2[3])
  109. local senior_check_in_data = skynet.unpack(char2.senior_check_in)
  110. local id = order_id
  111. grade_num[id] = {sum = 1, yet = 0}
  112. logger.trace(" ####### senior_check_in_data %s", stringify(senior_check_in_data))
  113. if senior_check_in_data.state > 0 then
  114. grade_num[id].yet = 1
  115. end
  116. end
  117. -- 328基金
  118. local function senior_check_in2(char2, grade_num)
  119. local WEL_KEY = 113 -- 活动对应的welfare表key值
  120. local order_id = assert(asset.welfare_proto[WEL_KEY].parameter2[3])
  121. local senior_check_in2_data = skynet.unpack(char2.senior_check_in2)
  122. local id = order_id
  123. grade_num[id] = {sum = 1, yet = 0}
  124. logger.trace(" ####### senior_check_in2_data %s", stringify(senior_check_in2_data))
  125. if senior_check_in2_data.state > 0 then
  126. grade_num[id].yet = 1
  127. end
  128. end
  129. -- 终生卡
  130. local function longlife_card(char2,grade_num)
  131. local appreciation_card = skynet.unpack(char2.appreciation_card)
  132. local id = pay_id.longlife_card
  133. grade_num[id] = {sum = 1, yet = 0}
  134. logger.trace(" ####### longlife_card %s", stringify(appreciation_card))
  135. appreciation_card.lifelongstate = appreciation_card.lifelongstate or 0
  136. if tonumber(appreciation_card.lifelongstate) == 1 then
  137. grade_num[id].yet = 1
  138. end
  139. end
  140. -- 周卡
  141. local function week_card(char2,grade_num)
  142. local appreciation_card = skynet.unpack(char2.appreciation_card)
  143. local id = pay_id.week_card
  144. grade_num[id] = {sum = 1, yet = 0}
  145. logger.trace(" ####### week_card %s", stringify(appreciation_card))
  146. appreciation_card.weektime = appreciation_card.weektime or 0
  147. local now = os.time()
  148. if appreciation_card.weektime > now then
  149. grade_num[id].yet = 1
  150. end
  151. end
  152. -- 月卡
  153. local function month_card(char2,grade_num)
  154. local appreciation_card = skynet.unpack(char2.appreciation_card)
  155. local id = pay_id.month_card
  156. grade_num[id] = {sum = 1, yet = 0}
  157. logger.trace(" ####### month_card %s", stringify(appreciation_card))
  158. local now = os.time()
  159. appreciation_card.monthtime = appreciation_card.monthtime or 0
  160. if appreciation_card.monthtime > now then
  161. grade_num[id].yet = 1
  162. end
  163. end
  164. -- 季卡
  165. local function quarter_card(char2,grade_num)
  166. local appreciation_card = skynet.unpack(char2.appreciation_card)
  167. local id = pay_id.quarter_card
  168. if not id then
  169. return
  170. end
  171. grade_num[id] = {sum = 1, yet = 0}
  172. logger.trace(" ####### quarter_card %s", stringify(appreciation_card))
  173. appreciation_card.quartertime = appreciation_card.quartertime or 0
  174. local now = os.time()
  175. if appreciation_card.quartertime > now then
  176. grade_num[id].yet = 1
  177. end
  178. end
  179. -- 成长基金
  180. local function fund(char2,grade_num)
  181. local fund_data = skynet.unpack(char2.fund)
  182. local id = pay_id.fund
  183. grade_num[id] = {sum = 1, yet = 0}
  184. logger.trace(" ####### fund_data %s", stringify(fund_data))
  185. if fund_data.state and fund_data.state > 0 then
  186. grade_num[id].yet = 1
  187. end
  188. end
  189. -- 成长基金2.0
  190. local function super_fund(char2, grade_num)
  191. local super_fund_data = skynet.unpack(char2.super_fund)
  192. local id = pay_id.super_fund
  193. grade_num[id] = {sum = 1, yet = 0}
  194. logger.trace(" ####### super_fund_data %s", stringify(super_fund_data))
  195. super_fund_data.isbuy_state = super_fund_data.isbuy_state or 0
  196. if super_fund_data.isbuy_state > 0 then
  197. grade_num[id].yet = 1
  198. end
  199. end
  200. --解锁秘境宝藏
  201. local function secret_manual(char2, grade_num)
  202. local ACTIV_ID = 96 -- 活动类型
  203. local cfid = -1
  204. local secret_manual_data = skynet.unpack(char2.secret_manual)
  205. if not secret_manual_data then
  206. return
  207. end
  208. logger.trace(" ####### super_fund_data %s", stringify(secret_manual_data))
  209. if secret_manual_data.state > 0 then
  210. local activitytimemod = skynet.unpack(char2.activitytimemod)
  211. if activitytimemod.activity_token[ACTIV_ID] then
  212. local sid = activitytimemod.activity_token[ACTIV_ID].sid
  213. local c_acti = assert(asset.activity_proto[sid],"activity_proto:" .. sid)
  214. cfid = c_acti.condition[1]
  215. end
  216. end
  217. if cfid == -1 then
  218. return
  219. end
  220. local id = cfid
  221. grade_num[id] = {sum = 1, yet = 0}
  222. secret_manual_data.levelup = secret_manual_data.levelup or 0
  223. if secret_manual_data.levelup > 0 then
  224. grade_num[id].yet = 1
  225. end
  226. end
  227. -- 特惠礼包 CDPK3-102
  228. local function special_gift(char2,grade_num)
  229. local special_gift = skynet.unpack(char2.special_gift)
  230. if special_gift.state > 0 then
  231. local activitytimemod = skynet.unpack(char2.activitytimemod)
  232. if activitytimemod.activity_token[38] then
  233. local sid = activitytimemod.activity_token[38].sid
  234. local c_acti = assert(asset.activity_proto[sid],"activity_proto:" .. sid)
  235. for k, cfid in ipairs(c_acti.condition) do
  236. local cnum = c_acti.parameter1[k]
  237. grade_num[cfid] = {sum = cnum, yet = 0}
  238. end
  239. for cfid, value in pairs(special_gift.yet_recharge) do
  240. grade_num[cfid].yet = value.rnum
  241. end
  242. end
  243. end
  244. end
  245. --请求方式1: http://服务器ip地址:端口号/webplayer?code=xxx&玩家uid
  246. --示例: http://192.168.1.102:8002/webplayer?code=xxx&uid=00-6477912978149613568
  247. --http://192.168.108.4:9002/webplayer?code=a7fd102b76268069hughskhfdksjhkaugjsdfdksjkjdfbuis1557041324&name==庞德的小煜
  248. local webplayer = function(args, ipaddr,header)
  249. return synchronized(function()
  250. logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
  251. if status == 0 then
  252. initialize()
  253. end
  254. if pay_id_init == 0 then
  255. init_payid()
  256. end
  257. if not whitelist[ipaddr] then
  258. -- return cjson.encode({state = 403, host = header.host, info = "不信任ip"})
  259. end
  260. -- 验证gm账号
  261. local code=string.sub(args.code,1,16)
  262. logger.trace(" ### code %s", args.code)
  263. if code ~= content.sign then
  264. return cjson.encode({state = 403,msg= "账号或密码错误"})
  265. end
  266. local uid
  267. if args.name then
  268. uid =get_id(args.name)
  269. elseif args.uid then
  270. uid= args.uid
  271. elseif (not args.uid) and (not args.name) then
  272. return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
  273. end
  274. local k = string.format("character:%s", uid)
  275. local info
  276. if true == db_character:exists(k) then
  277. info = loader(uid)
  278. else
  279. return cjson.encode({state = 400,msg = "加载玩家数据失败", content= uid})
  280. end
  281. if next(info) then
  282. local player = {}
  283. player.level = info.level --玩家等级
  284. player.vip = info.vip --玩家的vip等级
  285. player.nickname = info.nickname --玩家名字
  286. player.uid = info.uid --玩家的uid
  287. local grade_num = {}
  288. -- 处理玩家充值数据
  289. direct_recharge_gift(info, grade_num)
  290. senior_check_in(info, grade_num)
  291. super_fund(info, grade_num)
  292. senior_check_in2(info, grade_num)
  293. secret_manual(info,grade_num)
  294. fund(info,grade_num)
  295. special_gift(info,grade_num) -- CDPK3-102
  296. longlife_card(info,grade_num)
  297. week_card(info,grade_num)
  298. month_card(info,grade_num)
  299. quarter_card(info,grade_num)
  300. player.grade_num = grade_num
  301. return cjson.encode({state=0,msg="success",content=player})
  302. else
  303. return cjson.encode({state = 400, msg = "未找到该玩家"})
  304. end
  305. end)
  306. end
  307. return webplayer