1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- local skynet = require "skynet"
- require "skynet.manager"
- local logger = require "logger"
- local usercenter = skynet.localname(".usercenter")
- local ws_watchdog = skynet.localname(".ws_watchdog")
- local cjson = require "cjson"
- local md5 = require "md5"
- local redisdriver = require "skynet.db.redis"
- local loader = require "model.loader"
- 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.41"] = true,
- ["14.29.136.211"] = true,
- ["222.212.88.4"] = true,
- }
- local function initialize()
- status = 1
- local conf = assert(option.redis)
- db_character = redisdriver.connect(conf)
- db_character:select(0)
- end
- --请求方式: http://服务器ip地址:端口号/notice?code=xxx&ntype=1&interval=10&content=想要发送的跑马灯内容
- --示例: http://192.168.1.102:8002/notice?code=xxx&ntype=1&interval=10&content=this%20is%20a%20test
- local function check_server(args, ipaddr, header)
- if not whitelist[ipaddr] then
- -- return { "403 - Forbidden" }
- -- return cjson.encode({errno = 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
- logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
- if status == 0 then
- initialize()
- end
- local sid = args.sid
- local account = args.account
- local channel = args.channel or ""
- -- 渠道唯一标识
- local k = string.format("account:%s:%s:%s", channel, sid, account)
- local uid = db_character:get(k)
- if uid then
- local character = loader(uid)
- local ret = cjson.encode({
- state = 0,
- create = true,
- name = character.nickname,
- level = character.level,
- uid = character.uid,
- createtime = os.date("%Y-%m-%d %H:%M:%S", character.createtime)
- })
- logger.trace(ret)
- return ret
- end
-
- local ret = cjson.encode({state = 0, create = false})
- logger.trace(ret)
- return ret
- end
- return check_server
|