123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- -- --GM管理对得到玩家的基本信息
- local skynet = require "skynet"
- require "skynet.manager"
- local logger = require "logger"
- local queue = require "skynet.queue"
- local cjson = require "cjson"
- local stringify = require "stringify"
- local pipeline = require "pipeline"
- local loader = require "model.loader"
- local elf = require "model.elf"
- local equipment = require "model.equipment"
- local redisdriver = require "skynet.db.redis"
- local asset = require "model.asset"
- local md5 = require "md5"
- local ti=require "model.title"
- local s_public = skynet.localname(".public")
- local namecenter
- local usercenter
- local synchronized = queue()
- local skynet_send = skynet.send
- local skynet_call = skynet.call
- local status = 0
- local db_character
- 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.50"] = true,
- ["14.29.136.211"] = true,
- ["192.168.1.41"] = true,
- ["222.212.88.4"] = true,
- }
- --根据名字得到玩家uid
- local function get_id(name)
- return skynet.call(namecenter,"lua","findby", name)
- end
- local function initialize()
- status = 1
- namecenter = skynet.localname(".namecenter")
- usercenter = skynet.localname(".usercenter")
- local conf = assert(option.redis)
- db_character = redisdriver.connect(conf)
- db_character:select(0)
- end
- -- 获取玩家的充值信息
- local function recharge(uid)
- local suminfo = skynet.call(s_public, "lua","sum_money", "statistics_money",uid) -- PK3-1383 玩家金额统计
- return suminfo
- end
- -- 获取玩家公会信息
- local function guild_basic(data)
- data = skynet.unpack(data)
- local info = {}
- if data.guild then
- db_character:select(9)
- local ret = db_character:HMGET(string.format("guild:%s", data.guild), "g_name", "sid")
- if ret then
- info.guild_name = cjson.decode(ret[1])
- info.guild_sid = cjson.decode(ret[2])
- end
- db_character:select(0)
- end
- return info
- end
- --请求方式1: http://服务器ip地址:端口号/player?code=xxx&玩家uid
- --示例: http://192.168.1.102:8002/player?code=xxx&uid=00-6477912978149613568
- --http://192.168.108.4:9002/player?code=a7fd102b76268069hughskhfdksjhkaugjsdfdksjkjdfbuis1557041324&name==庞德的小煜
- local player = function(args, ipaddr,header)
- return synchronized(function()
- logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
- if status == 0 then
- initialize()
- end
- if not whitelist[ipaddr] then
- -- return cjson.encode({state = 403, host = header.host, info = "不信任ip"})
- end
- -- 验证gm账号
- local code=string.sub(args.code,1,16)
- if code ~= content.sign then
- return cjson.encode({state = 403,msg= "账号或密码错误"})
- end
- local uid
- if args.name then
- uid =get_id(args.name)
- elseif args.uid then
- uid=args.uid
- elseif (not args.uid) and (not args.name) then
- return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
- end
- local k = string.format("character:%s", uid)
- local info
- if true == db_character:exists(k) then
- info = loader(uid)
- else
- return cjson.encode({state = 400,msg = "加载玩家数据失败", content= uid})
- end
- if next(info) then
- local player = {}
- player.exp = info.exp --玩家的当前经验值
- player.coins = info.coins --玩家的金币数量
- player.lastlogin = info.lastlogin --玩家上次登陆的时间戳
- player.lv = info.level --玩家等级
- player.lastlogout = info.lastlogout --玩家上次下线的时间戳
- player.vip = info.vip --玩家的vip等级
- player.nickname = info.nickname --玩家名字
- player.uid = info.uid --玩家的uid
- player.platform=info.platform --玩家使用的操作系统
- player.createtime = info.createtime --玩家创建账号的时间戳
- player.channel = info.channel --玩家所属的渠道唯一标识
- player.diamonds = info.diamonds --玩家的钻石数量
- player.title=ti.gettitle(info) --玩家的称号编号
- player.appid = info.appid --玩家的App唯一标识
- player.sex = info.sex --玩家的性别
- player.power=info.power --玩家的当前战力
- player.bind_diamonds=info.bind_diamonds --玩家的神石数量
- player.account = info.account -- 玩家账号
- -- 6.27 增加
- player.recharge = recharge(uid) -- 玩家充值金额
- if info.guild_basic then
- player.guild_info = guild_basic(info.guild_basic) -- 公会数据
- end
- player.forbidden = info.forbidden-- 封号标志0是正常,非0解封号时间
- player.silent = info.silent -- 禁言标志0是正常,非0解禁言时间
- logger.trace(" player.recharge = %s", stringify(player))
- return cjson.encode({state=0,msg="success",content=player,})
- else
- return cjson.encode({state = 400, msg = "未找到该玩家"})
- end
- end)
- end
- return player
|