local skynet = require "skynet" require "skynet.manager" local logger = require "logger" local queue = require "skynet.queue" local md5 = require "md5" local synchronized = queue() local cjson = require "cjson" local asset = require "model.asset" local common_fun = require "model.common_fun" local mailbox local table_insert = table.insert 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 function create_html_page(text) return string.format( " %s ", string.gsub(text, "[\n]", "
")) end local whitelist = { -- ["192.168.1.23"] = true, } local function func(args, ipaddr, header) logger.trace("处理来自主机 %s 的发送邮件请求", ipaddr) -- 验证主机id -- if not whitelist[ipaddr] then -- 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 mtype = tonumber(args.ntype) local json = cjson.decode(args.json) local attach = json.attach or {} local detail = json.attach or {} local errno = 0 local info = "成功" ----------------------------- THIS ---------------------------------- -- if attach ~= nil then -- for i=1, #attach, 2 do -- local id = attach[i] -- local num = attach[i+1] -- if not id or not num or num <= 0 then -- errno = 1 -- info = "格式错误" -- break -- end -- errno = common_fun.goods_check(id) -- if errno == 0 then -- table_insert(detail, {id = id, num = num}) -- else -- info = "错误的道具id:"..id -- break -- end -- end -- else -- detail = {} -- end -- if errno ~= 0 then -- return cjson.encode({state = errno, msg = info}) -- end for _, v in ipairs(detail) do if not v.id or not v.num or v.num <= 0 then errno = 1 info = "格式错误" break end local goods_type = common_fun.goods_type(v.id) if goods_type== GOODS_NONE then errno = 1 info = "错误的道具id" end end if errno ~= 0 then return cjson.encode({state = errno, msg = info}) end local body = json.content local source = { module = "sendmail", brief = "GM发送的邮件", context = string.format("GM ip: %s tm = %s", ipaddr, os.time()) } local receiver mailbox = mailbox or skynet.localname(".mailbox") local subject = tonumber(json.title) if type(subject) ~= 'number' then return cjson.encode({state = 400, msg = "错误的title"}) end for k, v in pairs(detail) do logger.trace("=======k=%s--v=%s----", v.id, v.num) end if mtype == 2 then -- 全服邮件 skynet.call(mailbox, "lua", "broadcast", subject, body, detail, source) elseif mtype == 1 then -- 给特定玩家 receiver = json.roles skynet.call(mailbox, "lua", "off_line_mail", receiver, subject, body, detail, source) else return cjson.encode({state = 400, msg = "ntype不存在"}) end return cjson.encode({state = 0, msg = "success"}) end -- http://192.168.108.4:9002/mail?code=xxxx&ntype=3&json={"roles":["00-6527363693544497152","00-6527368552515657728"],"attach":[100041, 100, 100037, 100],"title":"这是标题","content":"这是正文"} local mail = function(args, ipaddr, header) return synchronized(function() -- return create_html_page(func(args, ipaddr, header)) return func(args, ipaddr, header) end) end return mail