check_server.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  9. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  10. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  11. local whitelist = {
  12. ["192.168.1.23"] = true,
  13. ["192.168.1.127"] = true,
  14. ["192.168.1.41"] = true,
  15. ["14.29.136.211"] = true,
  16. ["222.212.88.4"] = true,
  17. }
  18. --请求方式: http://服务器ip地址:端口号/notice?code=xxx&ntype=1&interval=10&content=想要发送的跑马灯内容
  19. --示例: http://192.168.1.102:8002/notice?code=xxx&ntype=1&interval=10&content=this%20is%20a%20test
  20. local function check_server(args, ipaddr, header)
  21. logger.trace("处理来自主机 %s 查询服务器状态", ipaddr)
  22. if not whitelist[ipaddr] then
  23. -- return { "403 - Forbidden" }
  24. -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
  25. end
  26. -- 验证gm账号
  27. -- local code = string.sub(args.code, 1, 16)
  28. -- if code ~= content.sign then
  29. -- return cjson.encode({state = 403, msg = "账号或密码错误"})
  30. -- end
  31. local sid = args.sid
  32. local account = args.account
  33. local channel = args.channel or ""
  34. local create = false
  35. if sid and account and channel then
  36. skynet.call(usercenter, "lua", "exsits", {
  37. sid = sid,
  38. account = account,
  39. channel = channel,
  40. })
  41. end
  42. local maintain = skynet.call(ws_watchdog, "lua", "getstatus")
  43. local ret = cjson.encode({state = 0, create = create, open = maintain and false or true})
  44. logger.trace(ret)
  45. return ret
  46. end
  47. return check_server