local skynet = require "skynet" require "skynet.manager" local logger = require "logger" local stringify = require "stringify" local watchdog = skynet.localname(".ws_watchdog") local usercenter = skynet.localname(".usercenter") local skynet_sleep = skynet.sleep 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.50"] = true, ["14.29.136.211"] = true, ["192.168.1.41"] = true, ["222.212.88.4"] = true, } --请求方式: http://服务器ip地址:端口号/server?code=xxx&ntype=操作类型 --示例: http://192.168.106.25:9002/server?code=a7fd102b76268069&ntype=1&error=错误描述 local function server(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 logger.trace("args:"..stringify(args)) local ntype=tonumber(args.ntype) local error=args.error if ntype==1 then local status=skynet.call(watchdog,"lua","getstatus") if status then return cjson.encode({state = 0, msg= "维护状态"}) else return cjson.encode({state = 0, msg= "正常状态"}) end elseif ntype==2 then -- 通知 watchdog, 进入维护状态 skynet.call(watchdog, "lua", "maintain") -- 通知所有在线玩家下线(标准下线流程) skynet.call(usercenter, "lua", "maintain",15) logger.warn("maintain (%s, %s)", args.code, ipaddr) return cjson.encode({state = 0,msg = "维护 成功"}) elseif ntype==3 then skynet.call(watchdog,"lua","open") logger.warn("open (%s, %s)", args.code, ipaddr) -- return { "200 - OK" } return cjson.encode({state = 0, msg= "开放 成功"}) elseif ntype==4 then -- 通知 watchdog, 进入维护状态 skynet.call(watchdog, "lua", "maintain") -- 通知所有在线玩家下线(标准下线流程) skynet.call(usercenter, "lua", "maintain",15,error) logger.warn("maintain (%s, %s)", args.code, ipaddr) skynet_sleep(10) skynet.call(watchdog,"lua","open") return cjson.encode({state = 0, msg= "设置成功"}) end end return server