forbit.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. -- GM管理对玩家封号和 禁言
  2. local skynet = require "skynet"
  3. require "skynet.manager"
  4. local redisdriver = require "skynet.db.redis"
  5. local logger = require "logger"
  6. local queue = require "skynet.queue"
  7. local cjson = require "cjson"
  8. local stringify = require "stringify"
  9. local synchronized = queue()
  10. local namecenter
  11. local usercenter
  12. local rankinglist
  13. local skynet_send = skynet.send
  14. local skynet_call = skynet.call
  15. local md5 = require "md5"
  16. local state = 0
  17. local db_character
  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. ["192.168.1.23"] = true,
  24. ["192.168.1.127"] = true,
  25. ["192.168.1.50"] = true,
  26. ["192.168.1.41"] = true,
  27. ["14.29.136.211"] = true,
  28. ["222.212.88.4"] = true,
  29. }
  30. -- 根据名字得到玩家uid
  31. local function get_id(name) return
  32. skynet.call(namecenter, "lua", "findby", name)
  33. end
  34. local function initialize()
  35. state = 1
  36. local conf = assert(option.redis)
  37. db_character = redisdriver.connect(conf)
  38. db_character:select(0)
  39. namecenter = skynet.localname(".namecenter")
  40. usercenter = skynet.localname(".usercenter")
  41. rankinglist = skynet.localname(".rankinglist")
  42. end
  43. local forbit = function(args, ipaddr, header)
  44. return synchronized(function()
  45. logger.trace("处理来自主机 %s 的GM管理封号禁言请求",
  46. ipaddr)
  47. if state == 0 then initialize() end
  48. if not whitelist[ipaddr] then
  49. -- return { code=403, msg="Forbidden" }
  50. -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
  51. end
  52. -- 验证gm账号
  53. -- local code = string.sub(args.code, 1, 16)
  54. -- if code ~= content.sign then
  55. -- return cjson.encode({state = 403, msg = "账号或密码错误"})
  56. -- end
  57. local ntype=tonumber(args.ntype)
  58. local entity=cjson.decode(args.json)
  59. local uid={}
  60. local succ1={}
  61. local failed1={}
  62. if entity.names then
  63. for k,v in pairs(entity.names) do
  64. local v1=get_id(v)
  65. table.insert(uid, v1)
  66. end
  67. elseif entity.uids then
  68. uid=entity.uids
  69. elseif (not entity.uids) and (not entity.names) then
  70. return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
  71. end
  72. local times = tonumber(entity.times) or 0
  73. if ntype==3 or ntype==1 then
  74. if not times or times < 0 then
  75. return cjson.encode({state = 400, msg = "wrong times"})
  76. end
  77. end
  78. if ntype==4 or ntype==2 then
  79. times=0
  80. end
  81. local now = os.time()
  82. local forbittime = now + times
  83. for key,value in pairs(uid) do
  84. local k = string.format("character:%s",value)
  85. if true == db_character:exists(k) then
  86. -- local forbitstr = "GM工具对玩家:" -- CDPK3-172
  87. local forbitstr_mode = "%s,%s,%s"
  88. local timeas = os.date("%Y.%m.%d %X", forbittime)
  89. if ntype == 6 then
  90. skynet_send(usercenter, "lua", "agent_command", value, "ban_rank", 0)
  91. db_character:hset(k, "ban_rank", 0)
  92. elseif ntype == 5 then
  93. skynet_send(usercenter, "lua", "agent_command", value, "ban_rank", 1)
  94. db_character:hset(k, "ban_rank", 1)
  95. skynet_send(rankinglist, "lua", "del", value)
  96. elseif ntype == 4 then
  97. -- forbitstr = forbitstr .. value .. " 解除禁言--" .. timeas -- CDPK3-172
  98. local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_4,value,timeas)
  99. skynet_send(usercenter, "lua", "agent_command", value, "setsilent",forbitstr, forbittime)
  100. db_character:hset(k, "silent", forbittime)
  101. elseif ntype==3 then
  102. -- forbitstr = forbitstr .. value .. " 禁言到" .. timeas -- CDPK3-172
  103. local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_3,value,timeas)
  104. skynet_send(usercenter, "lua", "agent_command", value, "setsilent",forbitstr, forbittime)
  105. db_character:hset(k, "silent", forbittime)
  106. elseif ntype==2 then
  107. -- forbitstr = forbitstr .. value .. " 解除封号--" .. timeas -- CDPK3-172
  108. local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_2,value,timeas)
  109. --logger.error(forbiddenstr)
  110. db_character:hset(k,"forbidden",forbittime)
  111. elseif ntype==1 then
  112. -- forbitstr = forbitstr .. value .. " 封号到" .. timeas -- CDPK3-172
  113. local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_1,value,timeas)
  114. skynet_call(usercenter,"lua","agent_command",value,"kick",forbitstr)
  115. db_character:hset(k,"forbidden",forbittime)
  116. end
  117. table.insert(succ1, value)
  118. else
  119. table.insert(failed1, value)
  120. --return cjson.encode({state = 400, msg = "without the player"})
  121. end
  122. end
  123. local pack={}
  124. pack.succ=succ1
  125. pack.failed=failed1
  126. if ntype ==6 then
  127. return cjson.encode({state = 0, msg = "排行解禁止success",content=pack})
  128. elseif ntype==5 then
  129. return cjson.encode({state = 0, msg = "排行封禁success",content=pack})
  130. elseif ntype==3 then
  131. return cjson.encode({state = 0, msg = "禁言success",content=pack})
  132. elseif ntype==4 then
  133. return cjson.encode({state = 0, msg = "解除禁言success",content=pack})
  134. elseif ntype==2 then
  135. return cjson.encode({state = 0, msg = "解除封号success",content=pack})
  136. elseif ntype==1 then
  137. return cjson.encode({state = 0, msg = "封号success",content=pack})
  138. end
  139. end)
  140. end
  141. return forbit