team.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local skynet = require "skynet"
  2. local codecache = require "skynet.codecache"
  3. require "skynet.manager"
  4. local logger = require "logger"
  5. local stringify = require "stringify"
  6. local cjson = require "cjson"
  7. local assetcenter
  8. local watchdog
  9. local authz = {
  10. yytx = "lee@YY-Games.520",
  11. lee = "yytx-Games-9527",
  12. }
  13. local span_team = skynet.localname(".span_team")
  14. -- example:
  15. --[[
  16. -- 重新加载指定玩家数据
  17. http://192.168.1.22:9002/team?user=lee&pwd=lee@123&func_local=player&uids=["uid","uid"]
  18. -- 重新加载指定队伍的数据
  19. http://192.168.1.22:9002/team?user=lee&pwd=lee@123&func_local=team&teamids=["tmid","tmid"]
  20. -- 关闭组队功能
  21. http://192.168.1.22:9002/team?user=lee&pwd=lee@123&func_local=switch&flag=0/1 -- 0 关闭 1 开启
  22. ]]
  23. local function team(args, ipaddr, header)
  24. logger.warn("处理来自主机team %s %s", ipaddr,args.func_local)
  25. -- 鉴权
  26. local user = args.user or ""
  27. local pwd = args.pwd or ""
  28. if authz[user] ~= pwd then
  29. return cjson.encode({errno = 403, host = header.host, info = "账号或密码错误"})
  30. end
  31. local func = args.func_local or ""
  32. logger.trace(" args = %s", stringify(args))
  33. if func == "player" and args.uids then
  34. local uids = cjson.decode(args.uids)
  35. local ok, ret = pcall(skynet.call,span_team, "lua", "web_load_player", uids)
  36. if not ok then
  37. logger.trace(" == 异常报错 %s", ret)
  38. return cjson.encode({errno = 400, host = header.host, info = "功能执行异常"})
  39. end
  40. elseif func == "team" and args.teamids then
  41. local teamids = cjson.decode(args.teamids)
  42. local ok, ret = pcall(skynet.call,span_team, "lua", "web_load_team", teamids)
  43. if not ok then
  44. logger.trace(" == 异常报错 %s", ret)
  45. return cjson.encode({errno = 400, host = header.host, info = "功能执行异常"})
  46. end
  47. elseif func == "switch" and args.flag then
  48. local ok, ret = pcall(skynet.call,span_team, "lua", "web_switch", args.flag)
  49. if not ok then
  50. logger.trace(" == 异常报错 %s", ret)
  51. return cjson.encode({errno = 400, host = header.host, info = "功能执行异常"})
  52. end
  53. if ret ~= 0 then
  54. return cjson.encode({errno = 400, host = header.host, info = "flag 参数异常"})
  55. end
  56. else
  57. return cjson.encode({errno = 400, host = header.host, info = "选择的功能不存在 或参数异常"})
  58. end
  59. return cjson.encode({errno = 200, host = header.host, info = "热更新 成功"})
  60. end
  61. return team