123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- -- GM管理对玩家封号和 禁言
- local skynet = require "skynet"
- require "skynet.manager"
- local redisdriver = require "skynet.db.redis"
- local logger = require "logger"
- local queue = require "skynet.queue"
- local cjson = require "cjson"
- local stringify = require "stringify"
- local synchronized = queue()
- local namecenter
- local usercenter
- local rankinglist
- local skynet_send = skynet.send
- local skynet_call = skynet.call
- local md5 = require "md5"
- local state = 0
- local db_character
- local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
- -- Generate request data
- local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
- content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
- local whitelist = {
- ["192.168.1.23"] = true,
- ["192.168.1.127"] = true,
- ["192.168.1.50"] = true,
- ["192.168.1.41"] = true,
- ["14.29.136.211"] = true,
- ["222.212.88.4"] = true,
- }
- -- 根据名字得到玩家uid
- local function get_id(name) return
- skynet.call(namecenter, "lua", "findby", name)
- end
- local function initialize()
- state = 1
- local conf = assert(option.redis)
- db_character = redisdriver.connect(conf)
- db_character:select(0)
- namecenter = skynet.localname(".namecenter")
- usercenter = skynet.localname(".usercenter")
- rankinglist = skynet.localname(".rankinglist")
- end
- local forbit = function(args, ipaddr, header)
- return synchronized(function()
- logger.trace("处理来自主机 %s 的GM管理封号禁言请求",
- ipaddr)
- if state == 0 then initialize() end
- if not whitelist[ipaddr] then
- -- return { code=403, msg="Forbidden" }
- -- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
- end
- -- 验证gm账号
- -- local code = string.sub(args.code, 1, 16)
- -- if code ~= content.sign then
- -- return cjson.encode({state = 403, msg = "账号或密码错误"})
- -- end
- local ntype=tonumber(args.ntype)
- local entity=cjson.decode(args.json)
- local uid={}
- local succ1={}
- local failed1={}
- if entity.names then
- for k,v in pairs(entity.names) do
- local v1=get_id(v)
- table.insert(uid, v1)
- end
- elseif entity.uids then
- uid=entity.uids
- elseif (not entity.uids) and (not entity.names) then
- return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
- end
- local times = tonumber(entity.times) or 0
- if ntype==3 or ntype==1 then
- if not times or times < 0 then
- return cjson.encode({state = 400, msg = "wrong times"})
- end
- end
- if ntype==4 or ntype==2 then
- times=0
- end
- local now = os.time()
- local forbittime = now + times
- for key,value in pairs(uid) do
- local k = string.format("character:%s",value)
- if true == db_character:exists(k) then
- -- local forbitstr = "GM工具对玩家:" -- CDPK3-172
- local forbitstr_mode = "%s,%s,%s"
- local timeas = os.date("%Y.%m.%d %X", forbittime)
- if ntype == 6 then
- skynet_send(usercenter, "lua", "agent_command", value, "ban_rank", 0)
- db_character:hset(k, "ban_rank", 0)
- elseif ntype == 5 then
- skynet_send(usercenter, "lua", "agent_command", value, "ban_rank", 1)
- db_character:hset(k, "ban_rank", 1)
- skynet_send(rankinglist, "lua", "del", value)
- elseif ntype == 4 then
- -- forbitstr = forbitstr .. value .. " 解除禁言--" .. timeas -- CDPK3-172
- local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_4,value,timeas)
- skynet_send(usercenter, "lua", "agent_command", value, "setsilent",forbitstr, forbittime)
- db_character:hset(k, "silent", forbittime)
- elseif ntype==3 then
- -- forbitstr = forbitstr .. value .. " 禁言到" .. timeas -- CDPK3-172
- local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_3,value,timeas)
- skynet_send(usercenter, "lua", "agent_command", value, "setsilent",forbitstr, forbittime)
- db_character:hset(k, "silent", forbittime)
- elseif ntype==2 then
- -- forbitstr = forbitstr .. value .. " 解除封号--" .. timeas -- CDPK3-172
- local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_2,value,timeas)
- --logger.error(forbiddenstr)
- db_character:hset(k,"forbidden",forbittime)
- elseif ntype==1 then
- -- forbitstr = forbitstr .. value .. " 封号到" .. timeas -- CDPK3-172
- local forbitstr = string.format(forbitstr_mode, STD_ERR.PLAYER_FORBIT_1,value,timeas)
- skynet_call(usercenter,"lua","agent_command",value,"kick",forbitstr)
- db_character:hset(k,"forbidden",forbittime)
- end
- table.insert(succ1, value)
- else
- table.insert(failed1, value)
- --return cjson.encode({state = 400, msg = "without the player"})
- end
- end
- local pack={}
- pack.succ=succ1
- pack.failed=failed1
- if ntype ==6 then
- return cjson.encode({state = 0, msg = "排行解禁止success",content=pack})
- elseif ntype==5 then
- return cjson.encode({state = 0, msg = "排行封禁success",content=pack})
- elseif ntype==3 then
- return cjson.encode({state = 0, msg = "禁言success",content=pack})
- elseif ntype==4 then
- return cjson.encode({state = 0, msg = "解除禁言success",content=pack})
- elseif ntype==2 then
- return cjson.encode({state = 0, msg = "解除封号success",content=pack})
- elseif ntype==1 then
- return cjson.encode({state = 0, msg = "封号success",content=pack})
- end
- end)
- end
- return forbit
|