123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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"
- }
-
- 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,
- }
- 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)
- 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
- local player = function(args, ipaddr,header)
- return synchronized(function()
- logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
- if status == 0 then
- initialize()
- end
- if not whitelist[ipaddr] then
-
- end
-
- 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
- player.nickname = info.nickname
- player.uid = info.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
- player.sex = info.sex
- player.power=info.power
- player.bind_diamonds=info.bind_diamonds
- player.account = info.account
-
- player.recharge = recharge(uid)
- if info.guild_basic then
- player.guild_info = guild_basic(info.guild_basic)
- end
- player.forbidden = info.forbidden
- player.silent = info.silent
- 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
|