local skynet = require "skynet" require "skynet.manager" local logger = require "logger" local stringify = require "stringify" local usercenter = skynet.localname(".usercenter") local chat = skynet.localname(".chat") local cjson = require "cjson" local md5 = require "md5" 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.41"] = true, ["14.29.136.211"] = true, ["222.212.88.4"] = true, } --请求方式: http://服务器ip地址:端口号/notice?code=xxx&ntype=1&interval=10&content=想要发送的跑马灯内容 --示例: http://192.168.1.102:8002/notice?code=xxx&ntype=1&interval=10&content=this%20is%20a%20test local function notice(args, ipaddr, header) logger.trace("处理来自主机 %s 的公告请求", ipaddr) if not whitelist[ipaddr] then -- return { "403 - 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 = math.tointeger(args.ntype) or 1 if ntype < 1 then return cjson.encode({state = 400, msg = "ntype次数少于 1"}) end local details = args.content if not details or #details == 0 then return cjson.encode({state = 400, msg = "content内容异常"}) end logger.error("______GM请求发送公告:%s", details) local interval = math.tointeger(args.interval) or 0 if ntype > 1 then if interval < 1 then return cjson.encode({state = 400, msg = "间隔时间太短"}) end else interval = 0 end skynet.fork(function() for i = 1, ntype do logger.trace("notice: %s,times:%s,interval:%s", details, ntype,interval) local now = os.time() local message = { h_type = 2, -- 聊天的主类型 c_type = CHAT_SON_TYPE.GM_NOTICE, -- 子类型 content = details, -- 内容 tm = now, -- 时间 sid = option.sid -- 服务器 } skynet.call(chat, "lua", "reqChat", message) -- skynet.call(usercenter, "lua", "broadcast", "notice", content) skynet.sleep(interval * 100) end end) logger.warn("notice (%s, %s)", code, ipaddr) return cjson.encode({state = 0, msg = "success"}) end return notice