player.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. -- --GM管理对得到玩家的基本信息
  2. local skynet = require "skynet"
  3. require "skynet.manager"
  4. local logger = require "logger"
  5. local queue = require "skynet.queue"
  6. local cjson = require "cjson"
  7. local stringify = require "stringify"
  8. local pipeline = require "pipeline"
  9. local loader = require "model.loader"
  10. local elf = require "model.elf"
  11. local equipment = require "model.equipment"
  12. local redisdriver = require "skynet.db.redis"
  13. local asset = require "model.asset"
  14. local md5 = require "md5"
  15. local ti=require "model.title"
  16. local s_public = skynet.localname(".public")
  17. local namecenter
  18. local usercenter
  19. local synchronized = queue()
  20. local skynet_send = skynet.send
  21. local skynet_call = skynet.call
  22. local status = 0
  23. local db_character
  24. local authz = {
  25. acc="yytx",
  26. pwd="lee@YY-Games.520"
  27. }
  28. -- Generate request data
  29. local content = {
  30. acc = authz.acc,
  31. pwd = authz.pwd,
  32. sign = false
  33. }
  34. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd),9,24)
  35. local whitelist = {
  36. ["192.168.1.23"] = true,
  37. ["192.168.1.127"] = true,
  38. ["192.168.1.50"] = true,
  39. ["14.29.136.211"] = true,
  40. ["192.168.1.41"] = true,
  41. ["222.212.88.4"] = true,
  42. }
  43. --根据名字得到玩家uid
  44. local function get_id(name)
  45. return skynet.call(namecenter,"lua","findby", name)
  46. end
  47. local function initialize()
  48. status = 1
  49. namecenter = skynet.localname(".namecenter")
  50. usercenter = skynet.localname(".usercenter")
  51. local conf = assert(option.redis)
  52. db_character = redisdriver.connect(conf)
  53. db_character:select(0)
  54. end
  55. -- 获取玩家的充值信息
  56. local function recharge(uid)
  57. local suminfo = skynet.call(s_public, "lua","sum_money", "statistics_money",uid) -- PK3-1383 玩家金额统计
  58. return suminfo
  59. end
  60. -- 获取玩家公会信息
  61. local function guild_basic(data)
  62. data = skynet.unpack(data)
  63. local info = {}
  64. if data.guild then
  65. db_character:select(9)
  66. local ret = db_character:HMGET(string.format("guild:%s", data.guild), "g_name", "sid")
  67. if ret then
  68. info.guild_name = cjson.decode(ret[1])
  69. info.guild_sid = cjson.decode(ret[2])
  70. end
  71. db_character:select(0)
  72. end
  73. return info
  74. end
  75. --请求方式1: http://服务器ip地址:端口号/player?code=xxx&玩家uid
  76. --示例: http://192.168.1.102:8002/player?code=xxx&uid=00-6477912978149613568
  77. --http://192.168.108.4:9002/player?code=a7fd102b76268069hughskhfdksjhkaugjsdfdksjkjdfbuis1557041324&name==庞德的小煜
  78. local player = function(args, ipaddr,header)
  79. return synchronized(function()
  80. logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
  81. if status == 0 then
  82. initialize()
  83. end
  84. if not whitelist[ipaddr] then
  85. -- return cjson.encode({state = 403, host = header.host, info = "不信任ip"})
  86. end
  87. -- 验证gm账号
  88. local code=string.sub(args.code,1,16)
  89. if code ~= content.sign then
  90. return cjson.encode({state = 403,msg= "账号或密码错误"})
  91. end
  92. local uid
  93. if args.name then
  94. uid =get_id(args.name)
  95. elseif args.uid then
  96. uid=args.uid
  97. elseif (not args.uid) and (not args.name) then
  98. return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
  99. end
  100. local k = string.format("character:%s", uid)
  101. local info
  102. if true == db_character:exists(k) then
  103. info = loader(uid)
  104. else
  105. return cjson.encode({state = 400,msg = "加载玩家数据失败", content= uid})
  106. end
  107. if next(info) then
  108. local player = {}
  109. player.exp = info.exp --玩家的当前经验值
  110. player.coins = info.coins --玩家的金币数量
  111. player.lastlogin = info.lastlogin --玩家上次登陆的时间戳
  112. player.lv = info.level --玩家等级
  113. player.lastlogout = info.lastlogout --玩家上次下线的时间戳
  114. player.vip = info.vip --玩家的vip等级
  115. player.nickname = info.nickname --玩家名字
  116. player.uid = info.uid --玩家的uid
  117. player.platform=info.platform --玩家使用的操作系统
  118. player.createtime = info.createtime --玩家创建账号的时间戳
  119. player.channel = info.channel --玩家所属的渠道唯一标识
  120. player.diamonds = info.diamonds --玩家的钻石数量
  121. player.title=ti.gettitle(info) --玩家的称号编号
  122. player.appid = info.appid --玩家的App唯一标识
  123. player.sex = info.sex --玩家的性别
  124. player.power=info.power --玩家的当前战力
  125. player.bind_diamonds=info.bind_diamonds --玩家的神石数量
  126. player.account = info.account -- 玩家账号
  127. -- 6.27 增加
  128. player.recharge = recharge(uid) -- 玩家充值金额
  129. if info.guild_basic then
  130. player.guild_info = guild_basic(info.guild_basic) -- 公会数据
  131. end
  132. player.forbidden = info.forbidden-- 封号标志0是正常,非0解封号时间
  133. player.silent = info.silent -- 禁言标志0是正常,非0解禁言时间
  134. logger.trace(" player.recharge = %s", stringify(player))
  135. return cjson.encode({state=0,msg="success",content=player,})
  136. else
  137. return cjson.encode({state = 400, msg = "未找到该玩家"})
  138. end
  139. end)
  140. end
  141. return player