123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- -- 映射账号(老帐号映射到新账号上)
- local skynet = require "skynet"
- require "skynet.manager"
- local redisdriver = require "skynet.db.redis"
- local logger = require "logger"
- local queue = require "skynet.queue"
- local cjson = require "cjson"
- local stringify = require "stringify"
- local synchronized = queue()
- local namecenter
- local usercenter
- local skynet_send = skynet.send
- local skynet_call = skynet.call
- local md5 = require "md5"
- local THIS = {}
- local state = 0
- local redis
- local whitelist = {
- }
- 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 function initialize()
- state = 1
- local conf = assert(option.redis)
- redis = redisdriver.connect(conf)
- redis:select(0)
- namecenter = skynet.localname(".namecenter")
- usercenter = skynet.localname(".usercenter")
- end
- -- http://192.168.108.10:9002/exchange_account?code=xxx&type=1&json={"attach":["00-6658977989381873664","00-6659002777164865536"]}
- local account = function(args, ipaddr, header)
- return synchronized(function()
- logger.trace("处理来自主机 %s 的GM管理账号映射请求",ipaddr)
- if state == 0 then initialize() end
- --验证gm账号
- local code = string.sub(args.code, 1, 16)
- if code ~= content.sign then
- return cjson.encode({state = 403, msg = "账号或密码错误"})
- end
- if not whitelist[ipaddr] then
- -- return { code=403, msg="Forbidden" }
- -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
- end
- local json = cjson.decode(args.json)
- local attach = json.attach or {}
- local type = args.type
- local new,old = attach[1],attach[2]
- local o_string = string.format("character:%s",old)
- local n_string = string.format("character:%s",new)
- logger.trace(" %s %s %s",type,new,old)
- function THIS.account_ys()
- local o_num = redis:HGET(o_string,'sid')
- local n_num = redis:HGET(n_string,'sid')
- logger.trace("#### ,account_ys %s %s",o_num,n_num)
- if o_num ~= n_num then
- logger.trace("#### 账号区服不一致,禁止映射")
- local context = "账号区服不一致,禁止映射"
- return -1,context
- end
- local o_acc = redis:HGET(o_string,'account')
- local n_acc = redis:HGET(n_string,'account')
- local migration_account_key = "migration_account:%s:%s" -- 区服+新账号
- local acco_string = string.format(migration_account_key,o_num,o_acc)
- local ret = redis:HGET(acco_string,'account')
- if ret then
- logger.trace("#### 新账号已有映射账号 不可再次映射")
- local context = "新账号已有映射账号 不可再次映射"
- return -1,context
- end
- local accn_string = string.format(migration_account_key,n_num,n_acc)
- ret = redis:HGET(accn_string,'account')
- if ret and ret ~= n_acc then
- logger.trace("#### 老账号已有映射账号 不可再次映射")
- local context = "老账号已有映射账号 不可再次映射"
- return -1,context
- end
- local err = redis:HSET(accn_string,'account',o_acc)
- return err
- end
- --取消绑定
- function THIS.account_qx()
- local n_num = redis:HGET(n_string,'sid')
- local n_acc = redis:HGET(n_string,'account')
- local migration_account_key = "migration_account:%s:%s" -- 区服+新账号
- logger.trace("#### ,account_qx server:%s account:%s ",n_num,n_acc )
- local accn_string = string.format(migration_account_key,n_num,n_acc)
- local ret = redis:HGET(accn_string,'account')
- if not ret then
- logger.trace("#### 账号没有映射账号 不可取消")
- local context = "账号没有映射账号 不可取消"
- return -1,context
- end
- local num = redis:HLEN(accn_string)
- num = (num or 0) + 1
- local add_string = 'account' ..num
- redis:HSET(accn_string,add_string,ret)
- redis:HSET(accn_string,'account',n_acc)
- return 0
- end
- if tonumber(type) == 1 then
- local erron,context = THIS.account_ys() --映射
- if erron == 1 then
- return cjson.encode({state=0,msg="success"})
- else
- return cjson.encode({state=-1,msg = context})
- end
- elseif tonumber(type) == 2 then
- local erron,context = THIS.account_qx() --取消
- if erron == 0 then
- return cjson.encode({state=0,msg="success"})
- else
- return cjson.encode({state=-1,msg=context})
- end
- end
- end)
- end
- return account
|