guild.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local logger = require "logger"
  4. local cjson = require "cjson"
  5. local queue = require "skynet.queue"
  6. local synchronized = queue()
  7. local redisdriver = require "skynet.db.redis"
  8. -- local namecenter = skynet.localname(".namecenter")
  9. -- local temp_config = mt
  10. local mysql = require "skynet.db.mysql"
  11. local util = require "util"
  12. local stringify = require "stringify"
  13. local s_guild = skynet.localname(".guild")
  14. local md5 = require "md5"
  15. -- local zlf_log = require "zlf_log"
  16. -- local z_trace = zlf_log.trace
  17. local db
  18. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  19. -- Generate request data
  20. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  21. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  22. local whitelist = {
  23. ["14.29.136.211"] = true,
  24. ["192.168.1.41"] = true,
  25. ["222.212.88.4"] = true,
  26. }
  27. -- 模板
  28. --[[
  29. 请求方式: http://服务器ip:端口号/ban?code=xxx&type=操作类型&content=xxxx&sid=xxxxx
  30. 参数:
  31. type:
  32. 1: 封禁公会 conten=1
  33. 2: 解封公会 conten=2
  34. 3: 重置公告 conten=公告内容
  35. 4: 重置名称 conten=公会行名称
  36. 5: 解锁公会 conten=5
  37. sid: 公会sid
  38. 反馈信息内容(json格式):
  39. {
  40. state: 反馈码(0表示成功)
  41. msg: 反馈描述(成功的时返回success)
  42. }
  43. ]]
  44. local guild = function(args, ipaddr,header)
  45. return synchronized(function()
  46. logger.trace("处理来自主机 %s 的guild请求", ipaddr)
  47. -- 验证主机id
  48. if not whitelist[ipaddr] then
  49. -- return cjson.encode({errno = 403, msg = "不信任ip"})
  50. end
  51. -- 验证gm账号2
  52. local code = string.sub(args.code, 1, 16)
  53. if code ~= content.sign then
  54. return cjson.encode({state = 403, msg = "账号或密码错误"})
  55. end
  56. local ftype = tonumber(args.type) -- 操作类型
  57. local fcont = args.content -- 操作参数
  58. local sid = args.sid -- 公会sid
  59. logger.trace(" %s:%s:%s",ftype,fcont,sid)
  60. -- 封 公会
  61. if ftype == 1 then
  62. local ret1,ret2 = skynet.call(s_guild, "lua", "set_seal", _,sid,1)
  63. if ret1 >= 0 then
  64. return cjson.encode({errno = 200, msg = "封禁公会 成功"})
  65. else
  66. return cjson.encode({errno = 400, msg = ret2})
  67. end
  68. elseif ftype == 2 then
  69. local ret1,ret2 = skynet.call(s_guild, "lua", "set_seal", _,sid,2)
  70. if ret1 >= 0 then
  71. return cjson.encode({errno = 200, msg = "解封公会 成功"})
  72. else
  73. return cjson.encode({errno = 400, msg = ret2})
  74. end
  75. elseif ftype == 3 then -- 设置公告
  76. local ret1,ret2 = skynet.call(s_guild, "lua", "web_set_notice", _,sid,fcont)
  77. if ret1 >= 0 then
  78. return cjson.encode({errno = 200, msg = "设置新的公告 成功"})
  79. else
  80. return cjson.encode({errno = 400, msg = ret2})
  81. end
  82. elseif ftype == 4 then -- 公会改名
  83. local ret1,ret2 = skynet.call(s_guild, "lua", "web_rename", _,sid,fcont)
  84. if ret1 >= 0 then
  85. return cjson.encode({errno = 200, msg = "重新命名字 成功"})
  86. else
  87. return cjson.encode({errno = 400, msg = ret2})
  88. end
  89. else
  90. -- return {code = 0, msg = "type 没有找到"}
  91. return cjson.encode({errno = 400, msg = "type 没有找到"})
  92. end
  93. end)
  94. end
  95. return guild