local skynet = require "skynet" require "skynet.manager" local logger = require "logger" local stringify = require "stringify" local watchdog = skynet.localname(".watchdog") local cjson = require "cjson" local md5 = require "md5" local redisdriver = require "skynet.db.redis" local s_public = skynet.localname(".public") -- PK3-1384 增加区服平均等级展示 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, ["14.29.136.211"] = true, ["192.168.1.41"] = true, ["222.212.88.4"] = true, } local redis local status = 0 local function initialize() status = 1 local conf = assert(option.redis) redis = redisdriver.connect(conf) redis:select(0) end -- http://192.168.1.57:9001/console?user=lee&pwd=lee@123&cmd=info#address=.watchdog --请求方式: http://服务器ip地址:端口号/online?code=xxx --示例: http://192.168.1.102:9002/online?code=xxx local function online(args, ipaddr, header) logger.warn("处理来自主机 %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 content content = skynet.call(args.address or ".watchdog", "debug", "INFO") logger.trace(" content = %s", content) if not content then return cjson.encode({state = 400, msg = "获取服务器失败"}) else if status == 0 then initialize() end local ret = redis:KEYS("character:*") content.offline_avg_number = #ret local average_lv = skynet.call(s_public, "lua", "compensate", "gm_average_lv") -- PK3-1384 增加区服平均等级展示 content.average_lv = average_lv return cjson.encode({state = 0, msg = "success",content=content}) end end return online