check_role.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local logger = require "logger"
  4. local usercenter = skynet.localname(".usercenter")
  5. local ws_watchdog = skynet.localname(".ws_watchdog")
  6. local cjson = require "cjson"
  7. local md5 = require "md5"
  8. local redisdriver = require "skynet.db.redis"
  9. local loader = require "model.loader"
  10. local skynet_send = skynet.send
  11. local skynet_call = skynet.call
  12. local status = 0
  13. local db_character
  14. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  15. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  16. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  17. local whitelist = {
  18. ["192.168.1.23"] = true,
  19. ["192.168.1.127"] = true,
  20. ["192.168.1.41"] = true,
  21. ["14.29.136.211"] = true,
  22. ["222.212.88.4"] = true,
  23. }
  24. local function initialize()
  25. status = 1
  26. local conf = assert(option.redis)
  27. db_character = redisdriver.connect(conf)
  28. db_character:select(0)
  29. end
  30. --请求方式: http://服务器ip地址:端口号/notice?code=xxx&ntype=1&interval=10&content=想要发送的跑马灯内容
  31. --示例: http://192.168.1.102:8002/notice?code=xxx&ntype=1&interval=10&content=this%20is%20a%20test
  32. local function check_server(args, ipaddr, header)
  33. if not whitelist[ipaddr] then
  34. -- return { "403 - Forbidden" }
  35. -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
  36. end
  37. -- 验证gm账号
  38. -- local code = string.sub(args.code, 1, 16)
  39. -- if code ~= content.sign then
  40. -- return cjson.encode({state = 403, msg = "账号或密码错误"})
  41. -- end
  42. logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
  43. if status == 0 then
  44. initialize()
  45. end
  46. local sid = args.sid
  47. local account = args.account
  48. local channel = args.channel or ""
  49. -- 渠道唯一标识
  50. local k = string.format("account:%s:%s:%s", channel, sid, account)
  51. local uid = db_character:get(k)
  52. if uid then
  53. local character = loader(uid)
  54. local ret = cjson.encode({
  55. state = 0,
  56. create = true,
  57. name = character.nickname,
  58. level = character.level,
  59. uid = character.uid,
  60. createtime = os.date("%Y-%m-%d %H:%M:%S", character.createtime)
  61. })
  62. logger.trace(ret)
  63. return ret
  64. end
  65. local ret = cjson.encode({state = 0, create = false})
  66. logger.trace(ret)
  67. return ret
  68. end
  69. return check_server